@clarusjs/theme-docs 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clarusjs/theme-docs",
3
- "version": "0.6.0",
3
+ "version": "0.7.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.19.0",
19
+ "clarusjs": "^0.20.0",
20
20
  "mermaid": ">=11"
21
21
  },
22
22
  "engines": {
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@tailwindcss/cli": "4.3.5",
43
- "@types/node": "^26.6.6",
44
- "clarusjs": "^0.19.0",
45
- "mermaid": "12.3.0",
43
+ "@types/node": "^26.6.11",
44
+ "clarusjs": "^0.20.0",
45
+ "mermaid": "12.4.0",
46
46
  "tailwindcss": "4.3.5",
47
47
  "typescript": "^7.0.2",
48
- "vite": "^8.3.8",
49
- "vitest": "^5.1.1"
48
+ "vite": "^8.4.0",
49
+ "vitest": "^5.1.2"
50
50
  },
51
51
  "peerDependenciesMeta": {
52
52
  "mermaid": {
package/src/callout.tscl CHANGED
@@ -1,9 +1,13 @@
1
- @type Kind = 'tip' | 'info' | 'warning' | 'danger'
2
- @input type: Kind = 'info'
1
+ <script lang="ts">
2
+ type Kind = 'tip' | 'info' | 'warning' | 'danger'
3
+ const props = props<{
4
+ type?: Kind
5
+ }>(() => ({ type: 'info' }))
6
+ </script>
3
7
 
4
- <aside role="note" class="callout {{ type }}">
8
+ <aside role="note" class="callout {{ props.type }}">
5
9
  <p class="callout-title">
6
- <slot name="title">{{ type[0].toUpperCase() + type.slice(1) }}</slot>
10
+ <slot name="title">{{ props.type[0].toUpperCase() + props.type.slice(1) }}</slot>
7
11
  </p>
8
12
  <slot />
9
13
  </aside>
package/src/layout.tscl CHANGED
@@ -10,52 +10,57 @@
10
10
  @import pageContents from './parts/contents.tscl'
11
11
  @import pageFooter from './parts/page-footer.tscl'
12
12
  @import siteFooter from './parts/footer.tscl'
13
- @import type { ThemeConfig, Heading } from './nav.ts'
14
- @import { sectionKey, crumb } from './nav.ts'
13
+ <script lang="ts">
14
+ import { sectionKey, crumb } from './nav.ts'
15
+ import type { ThemeConfig, Heading } from './nav.ts'
16
+ const props = props<{
17
+ config: ThemeConfig
18
+ title: string
19
+ description?: string
20
+ path?: string
21
+ /** The page's own route, when it differs from the sidebar entry it belongs to (e.g. /releases/[version]). */
22
+ source?: string
23
+ /** The page's own address, when path names its sidebar entry instead (e.g. /releases/0.7.0 under /releases). */
24
+ url?: string
25
+ /** The page's h2/h3 for "On this page" (Markdown pages pass them; none: the region is left out). */
26
+ headings?: Heading[]
27
+ /** A tool (a playground) rather than a page: the header and a full-height main, without sidebar, crumb or footers. */
28
+ app?: boolean
29
+ }>(() => ({ description: '', path: '/', source: '', url: '', headings: [], app: false }))
30
+ </script>
31
+
15
32
  @import './theme.css'
16
- @input config: ThemeConfig
17
- @input title: string
18
- @input description: string = ''
19
- @input path: string = '/'
20
- {{-- The page's own route, when it differs from the sidebar entry it belongs to (e.g. /releases/[version]). --}}
21
- @input source: string = ''
22
- {{-- The page's own address, when path names its sidebar entry instead (e.g. /releases/0.7.0 under /releases). --}}
23
- @input url: string = ''
24
- {{-- The page's h2/h3 for "On this page" (Markdown pages pass them; none: the region is left out). --}}
25
- @input headings: Heading[] = []
26
- {{-- A tool (a playground) rather than a page: the header and a full-height main, without sidebar, crumb or footers. --}}
27
- @input app: boolean = false
28
33
 
29
34
  <html lang="en">
30
35
  <head>
31
- <pageHead [config]="config" [title]="title" [description]="description" [url]="url || path" />
36
+ <pageHead [config]="props.config" [title]="props.title" [description]="props.description" [url]="props.url || props.path" />
32
37
  </head>
33
- <body>
38
+ <body [data-code-groups]="props.config.codeGroups">
34
39
  {{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
35
40
  <a class="skip-link" href="#content">Skip to content</a>
36
- <siteHeader [config]="config" [path]="path" [app]="app">@slot('end') {<slot name="header-end"></slot>}</siteHeader>
37
- @if (app) {
41
+ <siteHeader [config]="props.config" [path]="props.path" [app]="props.app">@slot('end') {<slot name="header-end"></slot>}</siteHeader>
42
+ @if (props.app) {
38
43
  <main class="content app" id="content" tabindex="-1"><slot /></main>
39
- } @else if (sectionKey(config.sections, path)) {
44
+ } @else if (sectionKey(props.config.sections, props.path)) {
40
45
  <div class="docs">
41
46
  {{-- A drawer below 1024px (popover: Escape and a click outside close it), always visible from 1024px. --}}
42
- <docsSidebar [config]="config" [path]="path">@slot('top') {<slot name="sidebar-top"></slot>}@slot('bottom') {<slot name="sidebar-bottom"></slot>}</docsSidebar>
47
+ <docsSidebar [config]="props.config" [path]="props.path">@slot('top') {<slot name="sidebar-top"></slot>}@slot('bottom') {<slot name="sidebar-bottom"></slot>}</docsSidebar>
43
48
  {{-- tabindex -1: the skip link (and navigation) can move focus here. --}}
44
49
  <main class="content" id="content" tabindex="-1">
45
- <p class="crumb">{{ crumb(config.sections, path) }}</p>
46
- <pageContents [headings]="headings" [inline]="true" />
50
+ <p class="crumb">{{ crumb(props.config.sections, props.path) }}</p>
51
+ <pageContents [headings]="props.headings" [inline]="true" />
47
52
  <slot name="content-top"></slot>
48
53
  <slot />
49
54
  <slot name="content-bottom"></slot>
50
- <pageFooter [config]="config" [path]="path" [source]="source" />
55
+ <pageFooter [config]="props.config" [path]="props.path" [source]="props.source" />
51
56
  </main>
52
- <pageContents [headings]="headings" />
57
+ <pageContents [headings]="props.headings" />
53
58
  </div>
54
59
  } @else {
55
60
  <main class="content home" id="content" tabindex="-1"><slot /></main>
56
61
  }
57
- @if (!app) {
58
- <siteFooter [config]="config"><slot name="footer">@if (config.footer) {<p>{{ config.footer }}</p>}</slot></siteFooter>
62
+ @if (!props.app) {
63
+ <siteFooter [config]="props.config"><slot name="footer">@if (props.config.footer) {<p>{{ props.config.footer }}</p>}</slot></siteFooter>
59
64
  }
60
65
  </body>
61
66
  </html>
@@ -4,17 +4,20 @@
4
4
  XP and badges. Progress is read from this browser, so without JavaScript only the lessons and steps show.
5
5
  The steps follow the lesson bar (learn:step); everything else follows saved progress (learn:progress).
6
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
7
 
16
- <script>
8
+ <script lang="ts">
17
9
  import { load, stats } from './progress.ts'
10
+ import type { Heading } from './nav.ts'
11
+ import { browser } from 'clarusjs/runtime'
12
+ interface Lesson { title: string; href: string; xp?: number; minutes?: number }
13
+ const props = props<{
14
+ lessons: Lesson[]
15
+ path: string
16
+ eyebrow?: string
17
+ course?: string
18
+ steps?: Heading[]
19
+ progress?: string
20
+ }>(() => ({ eyebrow: 'Learn', course: '', steps: [], progress: '' }))
18
21
  let ready = state(false)
19
22
  let statuses = state(Object.create(null)) // lesson href → done, current, next or locked
20
23
  let done = state(0)
@@ -24,18 +27,18 @@
24
27
  function refresh() {
25
28
  const s = stats(
26
29
  load(),
27
- lessons.map((l) => l.href),
30
+ props.lessons.map((l) => l.href),
28
31
  )
29
- const current = lessons.findIndex((l) => s.status(l.href) === 'current')
32
+ const current = props.lessons.findIndex((l) => s.status(l.href) === 'current')
30
33
  statuses = Object.fromEntries(
31
- lessons.map((l, i) => [l.href, s.status(l.href) === 'locked' && i === current + 1 ? 'next' : s.status(l.href)]),
34
+ props.lessons.map((l, i) => [l.href, s.status(l.href) === 'locked' && i === current + 1 ? 'next' : s.status(l.href)]),
32
35
  )
33
36
  done = s.done
34
37
  xp = s.xp
35
38
  earned = s.badges.filter((b) => b.earned).length
36
39
  ready = true
37
40
  }
38
- const note = (lesson, i) =>
41
+ const note = (lesson: Lesson, i: number) =>
39
42
  ready && statuses[lesson.href] === 'done'
40
43
  ? 'Done'
41
44
  : ready && statuses[lesson.href] === 'locked'
@@ -43,7 +46,7 @@
43
46
  : lesson.minutes
44
47
  ? lesson.minutes + ' min'
45
48
  : ''
46
- if (typeof document !== 'undefined') {
49
+ if (browser) {
47
50
  refresh()
48
51
  window.addEventListener('learn:progress', refresh)
49
52
  window.addEventListener('learn:step', (event) => {
@@ -54,25 +57,25 @@
54
57
 
55
58
  <nav class="learn-path flex flex-col" aria-label="Lessons">
56
59
  <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>
60
+ <p class="m-0 text-[11px] font-bold tracking-wider text-accent uppercase">{{ props.eyebrow }}</p>
61
+ <p class="m-0 mt-0.5 text-[17px] font-bold text-fg">{{ props.course }}</p>
59
62
  <div class="mt-3 flex items-center gap-2.5">
60
63
  <progress
61
64
  class="path-progress h-1.5 flex-1"
62
65
  [value]="done"
63
- [max]="lessons.length"
66
+ [max]="props.lessons.length"
64
67
  aria-label="Lessons done"
65
68
  ></progress>
66
- <span class="text-[13px] font-semibold text-fg">{{ done }} of {{ lessons.length }}</span>
69
+ <span class="text-[13px] font-semibold text-fg">{{ done }} of {{ props.lessons.length }}</span>
67
70
  </div>
68
71
  </div>
69
72
  <ol class="m-0 flex-1 list-none overflow-y-auto p-3">
70
- @for (lesson of lessons; track lesson.href) {
73
+ @for (lesson of props.lessons; track lesson.href) {
71
74
  <li class="m-0 mb-1" [data-status]="ready ? statuses[lesson.href] : false">
72
75
  <a
73
76
  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
77
  [href]="lesson.href"
75
- [aria-current]="lesson.href === path ? 'page' : false"
78
+ [aria-current]="lesson.href === props.path ? 'page' : false"
76
79
  >
77
80
  <span
78
81
  class="path-dot grid size-7 flex-none place-items-center rounded-full text-xs font-bold"
@@ -103,9 +106,9 @@
103
106
  <span class="path-xp text-xs font-bold">+{{ lesson.xp }}</span>
104
107
  }
105
108
  </a>
106
- @if (lesson.href === path && steps.length) {
109
+ @if (lesson.href === props.path && props.steps.length) {
107
110
  <ol class="path-steps my-1.5 ml-[46px] list-none p-0" aria-label="Steps">
108
- @for (s of steps; track s.id) {
111
+ @for (s of props.steps; track s.id) {
109
112
  <li class="m-0" [data-step]="$index < step ? 'done' : $index === step ? 'current' : 'next'">
110
113
  <a
111
114
  class="flex items-center gap-2.5 py-1 text-[13px] text-muted no-underline"
@@ -122,7 +125,7 @@
122
125
  </ol>
123
126
  <a
124
127
  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"
128
+ [href]="props.progress"
126
129
  >
127
130
  <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
128
131
  <path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
@@ -1,7 +1,11 @@
1
1
  {{-- The progress page's board (put it on the page at config.learn.progress): XP, lessons, quiz accuracy, badges, Reset. --}}
2
2
  @import progressBoard from './progress-board.tscl'
3
- @import type { ThemeConfig } from './nav.ts'
4
- @import { lessonsOf } from './nav.ts'
5
- @input config: ThemeConfig
3
+ <script lang="ts">
4
+ import { lessonsOf } from './nav.ts'
5
+ import type { ThemeConfig } from './nav.ts'
6
+ const props = props<{
7
+ config: ThemeConfig
8
+ }>()
9
+ </script>
6
10
 
7
- <progressBoard [lessons]="lessonsOf(config)" />
11
+ <progressBoard [lessons]="lessonsOf(props.config)" />
@@ -3,23 +3,26 @@
3
3
  the Learn sidebar each lesson marked done, current or locked (a hint: every lesson stays open). Hidden until it has
4
4
  read the progress, so pages without JavaScript show no "0 XP". Updates when the lesson bar saves (learn:progress).
5
5
  --}}
6
- @input lessons: string[]
7
- @input progress: string
8
6
 
9
- <script>
7
+ <script lang="ts">
10
8
  import { withoutBase } from 'clarusjs/navigation'
11
9
  import { load, stats } from './progress.ts'
10
+ import { browser } from 'clarusjs/runtime'
11
+ const props = props<{
12
+ lessons: string[]
13
+ progress: string
14
+ }>()
12
15
  let xp = state(0)
13
16
  let ready = state(false)
14
17
  const words = { done: 'done', current: 'up next', locked: 'not started' }
15
18
  function refresh() {
16
- const s = stats(load(), lessons)
19
+ const s = stats(load(), props.lessons)
17
20
  xp = s.xp
18
21
  ready = true
19
22
  for (const link of document.querySelectorAll('.sidebar ul a[href]')) {
20
23
  // the link has the site's base; lessons are routes, without it
21
24
  const href = withoutBase(link.getAttribute('href') ?? '')
22
- if (!(link instanceof HTMLElement) || !lessons.includes(href)) continue
25
+ if (!(link instanceof HTMLElement) || !props.lessons.includes(href)) continue
23
26
  const status = s.status(href)
24
27
  link.dataset.status = status
25
28
  let note = link.querySelector('.status-note')
@@ -31,13 +34,13 @@
31
34
  note.textContent = ' (' + words[status] + ')'
32
35
  }
33
36
  }
34
- if (typeof document !== 'undefined') {
37
+ if (browser) {
35
38
  refresh()
36
39
  window.addEventListener('learn:progress', refresh)
37
40
  }
38
41
  </script>
39
42
 
40
- <a class="xp-chip" [href]="progress" [hidden]="!ready" [aria-label]="xp + ' XP: your progress'">
43
+ <a class="xp-chip" [href]="props.progress" [hidden]="!ready" [aria-label]="xp + ' XP: your progress'">
41
44
  <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
42
45
  <path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
43
46
  </svg>
@@ -3,16 +3,21 @@
3
3
  follows the URL's #step (the header's segments link there), and after the last step goes to the next lesson.
4
4
  It reveals itself (and the one-step view) when it attaches: without JavaScript the lesson is a plain page.
5
5
  --}}
6
- @input lesson: string = ''
7
- @input prev: string = ''
8
- @input next: string = ''
9
- @input leave: string = '/'
10
- @input layout: 'split' | 'stacked' = 'split'
11
6
 
12
- <script>
13
- import { answer, finish, load, save, step } from './progress.ts'
7
+ <script lang="ts">
8
+ import { answer, finish, load, save, step, type Progress } from './progress.ts'
9
+ import { browser } from 'clarusjs/runtime'
10
+ import { withBase } from 'clarusjs/navigation'
11
+ import type { LessonLayout } from './nav.ts'
12
+ const props = props<{
13
+ lesson?: string
14
+ prev?: string
15
+ next?: string
16
+ leave?: string
17
+ layout?: LessonLayout
18
+ }>(() => ({ lesson: '', prev: '', next: '', leave: '/', layout: 'split' }))
14
19
  // Progress lives in this browser; the XP chip and the progress page listen for learn:progress.
15
- function record(update) {
20
+ function record(update: (p: Progress) => Progress): void {
16
21
  save(update(load()))
17
22
  window.dispatchEvent(new Event('learn:progress'))
18
23
  }
@@ -25,7 +30,7 @@
25
30
  let title = state('')
26
31
  let text = state('')
27
32
  const bar = () => document.querySelector('.lesson-bar')
28
- function verdict(kind, heading, detail) {
33
+ function verdict(kind: string, heading: string, detail: string): void {
29
34
  result = kind
30
35
  title = heading
31
36
  text = detail
@@ -33,7 +38,7 @@
33
38
  bar()?.classList.toggle('bad', kind === 'bad')
34
39
  }
35
40
  const steps = () => [...document.querySelectorAll('main .step')].filter((el) => el instanceof HTMLElement)
36
- function show(i, focus) {
41
+ function show(i: number, focus: boolean): void {
37
42
  const all = steps()
38
43
  if (!all.length) return
39
44
  current = Math.max(0, Math.min(i, all.length - 1))
@@ -60,7 +65,7 @@
60
65
  }
61
66
  }
62
67
  // The step a #hash points into: its own heading, or anything inside it.
63
- const indexOf = (hash) => {
68
+ const indexOf = (hash: string): number => {
64
69
  const id = decodeURIComponent(hash.slice(1))
65
70
  return id
66
71
  ? steps().findIndex((s) => s.getAttribute('aria-labelledby') === id || s.querySelector('#' + CSS.escape(id)))
@@ -68,7 +73,7 @@
68
73
  }
69
74
  function back() {
70
75
  if (current > 0) show(current - 1, true)
71
- else if (prev) location.href = prev
76
+ else if (props.prev) location.href = withBase(props.prev)
72
77
  }
73
78
  function forward() {
74
79
  if (checking) {
@@ -79,16 +84,17 @@
79
84
  }
80
85
  const id = steps()[current]?.getAttribute('aria-labelledby')
81
86
  if (current < total - 1) {
82
- if (id) record((p) => step(p, lesson, id))
87
+ if (id) record((p) => step(p, props.lesson, id))
83
88
  show(current + 1, true)
84
89
  } else {
85
- record((p) => finish(id ? step(p, lesson, id) : p, lesson))
86
- location.href = next || leave
90
+ record((p) => finish(id ? step(p, props.lesson, id) : p, props.lesson))
91
+ location.href = withBase(props.next || props.leave)
87
92
  }
88
93
  }
89
- // Each step's code and results (code blocks, .result) go in a side column, its text in the main one ('split').
90
- function split(step) {
91
- const side = [...step.children].filter((el) => el.matches('.code-block, .sample, pre, .result'))
94
+ // Each step's code and results (code blocks, whole code groups, .result) go in a side column, its text in the main one (every layout
95
+ // but 'stacked'); CSS places the two by the step's classes.
96
+ function split(step: Element): void {
97
+ const side = [...step.children].filter((el) => el.matches('.code-block, .code-group, .sample, pre, .result'))
92
98
  if (!side.length || step.classList.contains('split')) return
93
99
  const text = document.createElement('div')
94
100
  text.className = 'step-text'
@@ -97,9 +103,16 @@
97
103
  for (const el of [...step.children]) (side.includes(el) ? aside : text).append(el)
98
104
  step.append(text, aside)
99
105
  step.classList.add('split')
106
+ if (props.layout === 'split-reverse') step.classList.add('reverse') // code column on the left (CSS only)
107
+ // stacked-reverse: the heading, then the code, then the text, in the document too (reading order = what you see)
108
+ if (props.layout === 'stacked-reverse') {
109
+ step.classList.add('stacked')
110
+ const h2 = text.firstElementChild?.matches('h2') ? text.firstElementChild : null
111
+ step.prepend(...(h2 ? [h2] : []), aside)
112
+ }
100
113
  }
101
- if (typeof document !== 'undefined' && steps().length) {
102
- if (layout === 'split') steps().forEach(split)
114
+ if (browser && steps().length) {
115
+ if (props.layout !== 'stacked') steps().forEach(split)
103
116
  document.body.classList.add('one-step')
104
117
  const lessonBar = document.querySelector('.lesson-bar')
105
118
  if (lessonBar instanceof HTMLElement) lessonBar.hidden = false
@@ -125,7 +138,7 @@
125
138
  const { ok, done, text: detail } = event.detail
126
139
  if (!done) return verdict('', 'Pick an answer', detail)
127
140
  const quiz = event.target.dataset.quiz
128
- record((p) => answer(p, lesson + '#' + quiz, ok))
141
+ record((p) => answer(p, props.lesson + '#' + quiz, ok))
129
142
  checking = !!steps()[current].querySelector('[data-quiz]:not([data-answered])')
130
143
  verdict(ok ? 'ok' : 'bad', ok ? 'Correct!' : 'Not quite', detail)
131
144
  })
@@ -134,7 +147,7 @@
134
147
  </script>
135
148
 
136
149
  <div class="lesson-actions">
137
- <button type="button" class="back" (click)="back()" [disabled]="current === 0 && !prev">Back</button>
150
+ <button type="button" class="back" (click)="back()" [disabled]="current === 0 && !props.prev">Back</button>
138
151
  <div class="feedback" role="status">
139
152
  @if (title) {
140
153
  <p class="feedback-title">{{ title }}</p>
@@ -143,5 +156,5 @@
143
156
  <p class="feedback-title">Step {{ current + 1 }} of {{ total }}: {{ name }}</p>
144
157
  }
145
158
  </div>
146
- <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>
159
+ <button type="button" class="primary" (click)="forward()">@if (checking) {Check} @else if (total && current === total - 1) {@if (props.next) {Next lesson} @else {Finish}} @else {Continue}</button>
147
160
  </div>
package/src/lesson.css CHANGED
@@ -37,8 +37,11 @@
37
37
  /* Wide screens: what the step says on the left, its code and results on the right (the bar island groups them into
38
38
  .step-text and .step-side; without JavaScript a step is one column). */
39
39
  @media (min-width: 1024px) {
40
- .lesson .step.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 40px; align-items: start; }
41
- .step-side { position: sticky; top: calc(var(--header-height) + 16px); padding-top: 24px; }
40
+ .lesson .step.split:not(.stacked) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 40px; align-items: start; }
41
+ .step.split:not(.stacked) > .step-side { position: sticky; top: calc(var(--header-height) + 16px); padding-top: 24px; }
42
+ /* split-reverse: code on the left, text on the right; the document keeps the text first. */
43
+ .lesson .step.split.reverse > .step-side { grid-column: 1; grid-row: 1; }
44
+ .lesson .step.split.reverse > .step-text { grid-column: 2; grid-row: 1; }
42
45
  }
43
46
 
44
47
  @media (prefers-reduced-motion: no-preference) {
package/src/lesson.tscl CHANGED
@@ -9,24 +9,31 @@
9
9
  @import learnStatus from './learn-status.tscl'
10
10
  @import learnPath from './learn-path.tscl'
11
11
  @import pageHead from './page-head.tscl'
12
- @import type { ThemeConfig, Heading } from './nav.ts'
13
- @import { lessonOf, lessonsOf } from './nav.ts'
12
+ <script lang="ts">
13
+ import { lessonOf, lessonsOf, lessonLayoutOf } from './nav.ts'
14
+ import type { ThemeConfig, Heading } from './nav.ts'
15
+ const props = props<{
16
+ config: ThemeConfig
17
+ title: string
18
+ description?: string
19
+ path?: string
20
+ headings?: Heading[]
21
+ /** The page's frontmatter (from @clarusjs/content): `lessonLayout` picks this lesson's layout. */
22
+ frontmatter?: Record<string, unknown>
23
+ }>(() => ({ description: '', path: '/', headings: [], frontmatter: {} }))
24
+ </script>
25
+
14
26
  @import './theme.css'
15
27
  @import './lesson.css'
16
- @input config: ThemeConfig
17
- @input title: string
18
- @input description: string = ''
19
- @input path: string = '/'
20
- @input headings: Heading[] = []
21
28
 
22
29
  <html lang="en">
23
30
  <head>
24
- <pageHead [config]="config" [title]="title" [description]="description" [url]="path" />
31
+ <pageHead [config]="props.config" [title]="props.title" [description]="props.description" [url]="props.path" />
25
32
  </head>
26
- <body class="lesson-page">
33
+ <body class="lesson-page" [data-code-groups]="props.config.codeGroups">
27
34
  <a class="skip-link" href="#content">Skip to content</a>
28
35
  <header class="lesson-header">
29
- <a class="leave" [href]="lessonOf(config, path).leave" aria-label="Leave the lesson">
36
+ <a class="leave" [href]="lessonOf(props.config, props.path).leave" aria-label="Leave the lesson">
30
37
  <svg
31
38
  width="20"
32
39
  height="20"
@@ -41,37 +48,37 @@
41
48
  </svg>
42
49
  </a>
43
50
  <div class="lesson-name">
44
- @if (lessonOf(config, path).total) {
45
- <p class="eyebrow">{{ lessonOf(config, path).label }}</p>
51
+ @if (lessonOf(props.config, props.path).total) {
52
+ <p class="eyebrow">{{ lessonOf(props.config, props.path).label }}</p>
46
53
  }
47
- <p class="name">{{ title }}</p>
54
+ <p class="name">{{ props.title }}</p>
48
55
  </div>
49
56
  {{-- Links to each step: jumps without JavaScript, the progress bar with it. --}}
50
57
  <ol class="segments" aria-label="Steps">
51
- @for (h of headings.filter((h) => h.level === 2); track h.id) {
58
+ @for (h of props.headings.filter((h) => h.level === 2); track h.id) {
52
59
  <li>
53
60
  <a [href]="'#' + h.id">{{ h.text }}</a>
54
61
  </li>
55
62
  }
56
63
  </ol>
57
- @if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
64
+ @if (props.config.learn) {<learnStatus [lessons]="lessonsOf(props.config).map((l) => l.href)" [progress]="props.config.learn.progress" />}
58
65
  <slot name="header-end"></slot>
59
66
  </header>
60
67
  <div class="lesson-body">
61
68
  {{-- The path (#371): a lesson of config.learn's section, from 1024px. --}}
62
- @if (config.learn && lessonsOf(config).some((l) => l.href === path)) {
69
+ @if (props.config.learn && lessonsOf(props.config).some((l) => l.href === props.path)) {
63
70
  <aside class="lesson-path">
64
71
  <learnPath
65
- [lessons]="lessonsOf(config)"
66
- [path]="path"
67
- [eyebrow]="config.sections.find((s) => s.key === config.learn?.section)?.title ?? 'Learn'"
72
+ [lessons]="lessonsOf(props.config)"
73
+ [path]="props.path"
74
+ [eyebrow]="props.config.sections.find((s) => s.key === props.config.learn?.section)?.title ?? 'Learn'"
68
75
  [course]="
69
- config.sections
70
- .find((s) => s.key === config.learn?.section)
71
- ?.groups.find((g) => g.items.some((i) => i.href === path))?.title ?? ''
76
+ props.config.sections
77
+ .find((s) => s.key === props.config.learn?.section)
78
+ ?.groups.find((g) => g.items.some((i) => i.href === props.path))?.title ?? ''
72
79
  "
73
- [steps]="headings.filter((h) => h.level === 2)"
74
- [progress]="config.learn.progress"
80
+ [steps]="props.headings.filter((h) => h.level === 2)"
81
+ [progress]="props.config.learn.progress"
75
82
  />
76
83
  </aside>
77
84
  }
@@ -79,11 +86,11 @@
79
86
  </div>
80
87
  <div class="lesson-bar" role="region" aria-label="Lesson actions" hidden>
81
88
  <lessonBar
82
- [lesson]="path"
83
- [prev]="lessonOf(config, path).prev"
84
- [next]="lessonOf(config, path).next"
85
- [leave]="lessonOf(config, path).leave"
86
- [layout]="config.learn?.layout ?? 'split'"
89
+ [lesson]="props.path"
90
+ [prev]="lessonOf(props.config, props.path).prev"
91
+ [next]="lessonOf(props.config, props.path).next"
92
+ [leave]="lessonOf(props.config, props.path).leave"
93
+ [layout]="lessonLayoutOf(props.config, props.frontmatter)"
87
94
  />
88
95
  </div>
89
96
  </body>
package/src/nav.ts CHANGED
@@ -63,11 +63,18 @@ export type ThemeConfig = {
63
63
  /**
64
64
  * Learn: the section whose pages are lessons, and its progress page (not a lesson). Progress, XP and badges are
65
65
  * kept in the browser (localStorage); an XP chip shows in lesson headers and on the section's pages. `layout`: from
66
- * 1024px a step's code goes in a side column beside its text (`'split'`, the default); `'stacked'` keeps it inline.
66
+ * 1024px a step's code goes in a side column beside its text (`'split'`, the default; `'split-reverse'` puts it on
67
+ * the left); `'stacked'` keeps it inline; `'stacked-reverse'` puts it under the step's heading, above the text. A
68
+ * lesson can pick its own with frontmatter `lessonLayout:`.
67
69
  */
68
- learn?: { section: string; progress: string; layout?: 'split' | 'stacked' }
70
+ learn?: { section: string; progress: string; layout?: LessonLayout }
69
71
  /** A search button (and Ctrl/⌘K, /) in the header; the index comes from the themeDocs() Vite plugin. */
70
72
  search?: boolean
73
+ /**
74
+ * How a `::: code-group`'s tabs lay out when they don't fit: `'wrap'` onto more rows (the default), or `'scroll'`, one
75
+ * row that scrolls sideways with the code staying in place. A group's own `:scroll` or `:wrap` wins.
76
+ */
77
+ codeGroups?: 'wrap' | 'scroll'
71
78
  /**
72
79
  * Page changes animate as view transitions where the browser has them (a cross-fade; `::view-transition-*` rules in
73
80
  * the site's CSS change it). Needs fragment navigation or client routes; no animation with reduced motion.
@@ -182,3 +189,13 @@ export function lessonOf(config: ThemeConfig, path: string): { leave: string; pr
182
189
  total: items.length,
183
190
  }
184
191
  }
192
+
193
+ /** How a lesson places each step's code: beside the text (split) or in line with it (stacked), either way round. */
194
+ export type LessonLayout = 'split' | 'split-reverse' | 'stacked' | 'stacked-reverse'
195
+ const LESSON_LAYOUTS: readonly string[] = ['split', 'split-reverse', 'stacked', 'stacked-reverse']
196
+
197
+ /** A lesson's layout: its frontmatter's `lessonLayout` when valid, else the site's `learn.layout`, else 'split'. */
198
+ export function lessonLayoutOf(config: ThemeConfig, frontmatter?: Record<string, unknown>): LessonLayout {
199
+ const own = frontmatter?.lessonLayout
200
+ return typeof own === 'string' && LESSON_LAYOUTS.includes(own) ? (own as LessonLayout) : config.learn?.layout ?? 'split'
201
+ }
@@ -1,9 +1,14 @@
1
1
  {{-- The <head> of every theme page: the saved theme before the first paint, the title and description, JSON-LD. --}}
2
- @import type { ThemeConfig } from './nav.ts'
3
- @input config: ThemeConfig
4
- @input title: string
5
- @input description: string = ''
6
- @input url: string = '/'
2
+ <script lang="ts">
3
+ import type { ThemeConfig } from './nav.ts'
4
+ const props = props<{
5
+ config: ThemeConfig
6
+ title: string
7
+ description?: string
8
+ url?: string
9
+ }>(() => ({ description: '', url: '/' }))
10
+ </script>
11
+
7
12
  {{-- Runs before the first paint: the saved theme is on <html> before anything shows (no flash). --}}
8
13
 
9
14
  <script inline>
@@ -15,13 +20,13 @@
15
20
  <fragment>
16
21
  <meta charset="utf-8" />
17
22
  <meta name="viewport" content="width=device-width, initial-scale=1" />
18
- @if (description) {
19
- <meta name="description" content="{{ description }}" />
23
+ @if (props.description) {
24
+ <meta name="description" content="{{ props.description }}" />
20
25
  }
21
- <title>{{ title }}</title>
22
- @if (config.siteUrl) {
26
+ <title>{{ props.title }}</title>
27
+ @if (props.config.siteUrl) {
23
28
  <script type="application/ld+json">
24
- {{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
29
+ {{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: props.title, description: props.description, url: `${props.config.siteUrl}${props.url === '/' ? '' : props.url}` } }}
25
30
  </script>
26
31
  }
27
32
  </fragment>
@@ -3,27 +3,31 @@
3
3
  collapsible box above the content (below 1280px). Nothing without headings. Replace it with
4
4
  themeDocs({ components: { contents } }) (#361).
5
5
  --}}
6
- @import type { Heading } from '../nav.ts'
7
- @input headings: Heading[] = []
8
- @input inline: boolean = false
6
+ <script lang="ts">
7
+ import type { Heading } from '../nav.ts'
8
+ const props = props<{
9
+ headings?: Heading[]
10
+ inline?: boolean
11
+ }>(() => ({ headings: [], inline: false }))
12
+ </script>
9
13
 
10
14
  <fragment>
11
- @if (headings.length && inline) {
15
+ @if (props.headings.length && props.inline) {
12
16
  <details class="toc-inline">
13
17
  <summary>On this page</summary>
14
18
  <ul>
15
- @for (h of headings; track h.id) {
19
+ @for (h of props.headings; track h.id) {
16
20
  <li [class]="h.level === 3 ? 'sub' : false">
17
21
  <a [href]="'#' + h.id">{{ h.text }}</a>
18
22
  </li>
19
23
  }
20
24
  </ul>
21
25
  </details>
22
- } @else if (headings.length) {
26
+ } @else if (props.headings.length) {
23
27
  <aside class="toc" aria-label="On this page">
24
28
  <p>On this page</p>
25
29
  <ul>
26
- @for (h of headings; track h.id) {
30
+ @for (h of props.headings; track h.id) {
27
31
  <li [class]="h.level === 3 ? 'sub' : false">
28
32
  <a [href]="'#' + h.id">{{ h.text }}</a>
29
33
  </li>
@@ -2,7 +2,11 @@
2
2
  The site footer (a public part, #360): its default content is config.footer. Replace it with
3
3
  themeDocs({ components: { footer } }) (#361).
4
4
  --}}
5
- @import type { ThemeConfig } from '../nav.ts'
6
- @input config: ThemeConfig
5
+ <script lang="ts">
6
+ import type { ThemeConfig } from '../nav.ts'
7
+ const props = props<{
8
+ config: ThemeConfig
9
+ }>()
10
+ </script>
7
11
 
8
- <footer class="site-footer"><slot>@if (config.footer) {<p>{{ config.footer }}</p>}</slot></footer>
12
+ <footer class="site-footer"><slot>@if (props.config.footer) {<p>{{ props.config.footer }}</p>}</slot></footer>
@@ -6,15 +6,19 @@
6
6
  @import pageTransitions from '../view-transitions.tscl'
7
7
  @import siteSearch from '../search.tscl'
8
8
  @import learnStatus from '../learn-status.tscl'
9
- @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
9
+ <script lang="ts">
10
+ import { sectionKey, lessonsOf } from '../nav.ts'
11
+ import type { ThemeConfig } from '../nav.ts'
12
+ const props = props<{
13
+ config: ThemeConfig
14
+ path?: string
15
+ /** An app page (a tool) has no sidebar, so no menu button. */
16
+ app?: boolean
17
+ }>(() => ({ path: '/', app: false }))
18
+ </script>
15
19
 
16
20
  <header class="site-header">
17
- @if (!app && sectionKey(config.sections, path)) {
21
+ @if (!props.app && sectionKey(props.config.sections, props.path)) {
18
22
  <button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
19
23
  <svg
20
24
  width="22"
@@ -31,17 +35,17 @@
31
35
  </button>
32
36
  }
33
37
  <a class="brand" href="/"
34
- >@if (config.brand.logo) {<img [src]="config.brand.logo" alt="" width="28" height="28">}<span>{{ config.brand.text }}@if (config.brand.accent) {<span class="js">{{ config.brand.accent }}</span>}</span></a
38
+ >@if (props.config.brand.logo) {<img [src]="props.config.brand.logo" alt="" width="28" height="28">}<span>{{ props.config.brand.text }}@if (props.config.brand.accent) {<span class="js">{{ props.config.brand.accent }}</span>}</span></a
35
39
  >
36
- <nav class="top-nav" aria-label="Main">@for (s of config.sections; track s.key) {<a [href]="s.href" [aria-current]="sectionKey(config.sections, path) === s.key ? 'true' : false">{{ s.title }}</a>}</nav>
40
+ <nav class="top-nav" aria-label="Main">@for (s of props.config.sections; track s.key) {<a [href]="s.href" [aria-current]="sectionKey(props.config.sections, props.path) === s.key ? 'true' : false">{{ s.title }}</a>}</nav>
37
41
  <div class="header-end">
38
42
  {{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
39
- @if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
43
+ @if (props.config.learn && sectionKey(props.config.sections, props.path) === props.config.learn.section) {<learnStatus [lessons]="lessonsOf(props.config).map((l) => l.href)" [progress]="props.config.learn.progress" />}
40
44
  {{-- Kept across fragment navigations, like the theme toggle: its shortcut listener is added once. --}}
41
- @if (config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
42
- @if ((config.social ?? []).length) {
45
+ @if (props.config.search) {<span class="persist" data-cl-persist="search"><siteSearch /></span>}
46
+ @if ((props.config.social ?? []).length) {
43
47
  <span class="social">
44
- @for (link of config.social ?? []; track link.href) {
48
+ @for (link of props.config.social ?? []; track link.href) {
45
49
  <a [href]="link.href" [aria-label]="link.label" [title]="link.label"> @if (link.icon === 'github') {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 19c-4 1.5-4-2-6-2.5m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1.1-.3-3.5 1.3a12.3 12.3 0 0 0-6.2 0C6.5 2.8 5.4 3.1 5.4 3.1a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4 9.5c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V21"></path></svg>} @else if (link.icon === 'npm') {<span class="npm" aria-hidden="true">npm</span>} @else {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"></path></svg>} </a>
46
50
  }
47
51
  </span>
@@ -53,12 +57,12 @@
53
57
  <circle cx="19" cy="12" r="2"></circle>
54
58
  </svg>
55
59
  </button>
56
- <div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
60
+ <div id="more" class="more" popover>@for (link of props.config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
57
61
  }
58
62
  {{-- What a site adds (slot "end"; the layout's "header-end"), kept across fragment navigations too. --}}
59
63
  <span class="persist" data-cl-persist="header-end"><slot name="end"></slot></span>
60
64
  {{-- Kept across fragment navigations: the same element, with its state. --}}
61
65
  <span class="persist" data-cl-persist="theme"><themeToggle /></span>
62
- @if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
66
+ @if (props.config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
63
67
  </div>
64
68
  </header>
@@ -1,10 +1,14 @@
1
1
  {{-- A sidebar group's icon (#369), by name: see parts/icons.ts. Decorative: the group's title says what it is. --}}
2
- @import type { GroupIcon } from '../nav.ts'
3
- @import { ICONS } from './icons.ts'
4
- @input name: GroupIcon
2
+ <script lang="ts">
3
+ import { ICONS } from './icons.ts'
4
+ import type { GroupIcon } from '../nav.ts'
5
+ const props = props<{
6
+ name: GroupIcon
7
+ }>()
8
+ </script>
5
9
 
6
10
  <svg
7
- [data-icon]="name"
11
+ [data-icon]="props.name"
8
12
  width="14"
9
13
  height="14"
10
14
  viewBox="0 0 24 24"
@@ -15,7 +19,7 @@
15
19
  stroke-linejoin="round"
16
20
  aria-hidden="true"
17
21
  >
18
- @for (d of ICONS[name] ?? []; track d) {
22
+ @for (d of ICONS[props.name] ?? []; track d) {
19
23
  <path [d]="d"></path>
20
24
  }
21
25
  </svg>
@@ -2,20 +2,24 @@
2
2
  Under the content (a public part, #360): the edit link, when the page was last updated, and the previous and next
3
3
  pages. Replace it with themeDocs({ components: { pageFooter } }) (#361).
4
4
  --}}
5
- @import type { ThemeConfig } from '../nav.ts'
6
- @import { editHref, updatedOf, pager } from '../nav.ts'
7
- @input config: ThemeConfig
8
- @input path: string = '/'
9
- {{-- The page's own route, when it differs from its sidebar entry (see the layout's source input). --}}
10
- @input source: string = ''
5
+ <script lang="ts">
6
+ import { editHref, updatedOf, pager } from '../nav.ts'
7
+ import type { ThemeConfig } from '../nav.ts'
8
+ const props = props<{
9
+ config: ThemeConfig
10
+ path?: string
11
+ /** The page's own route, when it differs from its sidebar entry (see the layout's source input). */
12
+ source?: string
13
+ }>(() => ({ path: '/', source: '' }))
14
+ </script>
11
15
 
12
16
  <footer class="page-footer">
13
- @if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
14
- @if (updatedOf(config, source || path)) {
17
+ @if (editHref(props.config, props.source || props.path)) {<a class="edit" [href]="editHref(props.config, props.source || props.path)">Edit this page on GitHub</a>}
18
+ @if (updatedOf(props.config, props.source || props.path)) {
15
19
  <p class="updated">
16
20
  Last updated
17
- <time [datetime]="updatedOf(config, source || path)?.iso">{{ updatedOf(config, source || path)?.text }}</time>
21
+ <time [datetime]="updatedOf(props.config, props.source || props.path)?.iso">{{ updatedOf(props.config, props.source || props.path)?.text }}</time>
18
22
  </p>
19
23
  }
20
- <nav class="pager" aria-label="Previous and next">@if (pager(config.sections, path).prev.href) {<a class="prev" [href]="pager(config.sections, path).prev.href"><small>Previous</small>{{ pager(config.sections, path).prev.title }}</a>} @if (pager(config.sections, path).next.href) {<a class="next" [href]="pager(config.sections, path).next.href"><small>Next</small>{{ pager(config.sections, path).next.title }}</a>}</nav>
24
+ <nav class="pager" aria-label="Previous and next">@if (pager(props.config.sections, props.path).prev.href) {<a class="prev" [href]="pager(props.config.sections, props.path).prev.href"><small>Previous</small>{{ pager(props.config.sections, props.path).prev.title }}</a>} @if (pager(props.config.sections, props.path).next.href) {<a class="next" [href]="pager(props.config.sections, props.path).next.href"><small>Next</small>{{ pager(props.config.sections, props.path).next.title }}</a>}</nav>
21
25
  </footer>
@@ -9,10 +9,14 @@
9
9
  or the search box: the header has one on phones), and a row of links at the bottom.
10
10
  --}}
11
11
  @import groupIcon from './icon.tscl'
12
- @import type { ThemeConfig } from '../nav.ts'
13
- @import { groupsOf, sectionKey } from '../nav.ts'
14
- @input config: ThemeConfig
15
- @input path: string = '/'
12
+ <script lang="ts">
13
+ import { groupsOf, sectionKey } from '../nav.ts'
14
+ import type { ThemeConfig } from '../nav.ts'
15
+ const props = props<{
16
+ config: ThemeConfig
17
+ path?: string
18
+ }>(() => ({ path: '/' }))
19
+ </script>
16
20
 
17
21
  <nav id="sidebar" class="sidebar" aria-label="Pages" popover>
18
22
  <div class="sidebar-head">
@@ -33,16 +37,16 @@
33
37
  </button>
34
38
  </div>
35
39
  <div class="sidebar-switch mb-3 auto-cols-fr grid-flow-col gap-1 rounded-xl bg-surface p-1">
36
- @for (s of config.sections.filter((s) => s.switch !== false); track s.key) {
40
+ @for (s of props.config.sections.filter((s) => s.switch !== false); track s.key) {
37
41
  <a
38
42
  [href]="s.href"
39
- [aria-current]="s.key === sectionKey(config.sections, path) ? 'true' : false"
43
+ [aria-current]="s.key === sectionKey(props.config.sections, props.path) ? 'true' : false"
40
44
  class="rounded-lg py-2 text-center text-sm font-semibold text-muted no-underline aria-[current=true]:bg-bg aria-[current=true]:text-accent aria-[current=true]:shadow-sm"
41
45
  >{{ s.title }}</a
42
46
  >
43
47
  }
44
48
  </div>
45
- @if (config.search) {
49
+ @if (props.config.search) {
46
50
  {{-- Opens the search dialog, as the header's button and Ctrl/⌘K do (search.tscl listens for data-search-open). --}}
47
51
  <button
48
52
  type="button"
@@ -70,11 +74,11 @@
70
74
  </button>
71
75
  }
72
76
  <slot name="top"></slot>
73
- @for (group of groupsOf(config.sections, path); track group.title) {
77
+ @for (group of groupsOf(props.config.sections, props.path); track group.title) {
74
78
  <details
75
79
  class="group mb-1.5"
76
80
  [data-group]="group.title"
77
- [open]="!group.collapsed || group.items.some((i) => i.href === path)"
81
+ [open]="!group.collapsed || group.items.some((i) => i.href === props.path)"
78
82
  >
79
83
  <summary
80
84
  class="flex cursor-pointer list-none items-center gap-2.5 rounded-md py-1.5 pr-1 text-[13px] font-semibold text-fg select-none [&::-webkit-details-marker]:hidden"
@@ -103,7 +107,7 @@
103
107
  <li class="m-0">
104
108
  <a
105
109
  [href]="item.href"
106
- [aria-current]="item.href === path ? 'page' : false"
110
+ [aria-current]="item.href === props.path ? 'page' : false"
107
111
  class="-ml-px flex items-center gap-2 rounded-r-md border-l-2 border-transparent py-[5px] pr-2 pl-3 text-[13px] text-fg/80 no-underline transition-colors hover:text-fg aria-[current=page]:border-accent aria-[current=page]:bg-accent-soft aria-[current=page]:font-semibold aria-[current=page]:text-accent"
108
112
  >
109
113
  <span class="flex-1">{{ item.title }}</span>
@@ -123,7 +127,7 @@
123
127
  <div
124
128
  class="sidebar-links mt-auto justify-between gap-x-3 gap-y-1 border-t border-rule pt-3 text-[13px] font-medium [&_a]:text-accent [&_a]:no-underline"
125
129
  >
126
- @for (link of [...(config.menuLinks ?? []), ...(config.social ?? [])]; track link.href) {
130
+ @for (link of [...(props.config.menuLinks ?? []), ...(props.config.social ?? [])]; track link.href) {
127
131
  <a [href]="link.href">{{ link.label }}</a>
128
132
  }
129
133
  </div>
@@ -2,11 +2,14 @@
2
2
  Your progress, read from this browser: XP, lessons done, quiz accuracy, badges and each lesson's state, with Reset.
3
3
  Without JavaScript (or with storage blocked) it says so; the lessons are still links.
4
4
  --}}
5
- @interface Lesson { title: string; href: string }
6
- @input lessons: Lesson[]
7
5
 
8
- <script>
6
+ <script lang="ts">
9
7
  import { load, reset, save, stats } from './progress.ts'
8
+ import { browser } from 'clarusjs/runtime'
9
+ interface Lesson { title: string; href: string }
10
+ const props = props<{
11
+ lessons: Lesson[]
12
+ }>()
10
13
  let xp = state(0)
11
14
  let done = state(0)
12
15
  let accuracy = state('')
@@ -17,7 +20,7 @@
17
20
  function refresh() {
18
21
  const s = stats(
19
22
  load(),
20
- lessons.map((l) => l.href),
23
+ props.lessons.map((l) => l.href),
21
24
  )
22
25
  xp = s.xp
23
26
  done = s.done
@@ -25,7 +28,7 @@
25
28
  ? Math.round((s.right / s.answered) * 100) + '% (' + s.right + ' of ' + s.answered + ')'
26
29
  : 'no quizzes answered yet'
27
30
  badges = s.badges
28
- statuses = Object.fromEntries(lessons.map((l) => [l.href, s.status(l.href)]))
31
+ statuses = Object.fromEntries(props.lessons.map((l) => [l.href, s.status(l.href)]))
29
32
  }
30
33
  function wipe() {
31
34
  if (!confirming) {
@@ -37,7 +40,7 @@
37
40
  refresh()
38
41
  window.dispatchEvent(new Event('learn:progress'))
39
42
  }
40
- if (typeof document !== 'undefined') {
43
+ if (browser) {
41
44
  // Saving what is there tells us whether this browser keeps it.
42
45
  mode = save(load()) ? 'saved' : 'blocked'
43
46
  refresh()
@@ -60,7 +63,7 @@
60
63
  </div>
61
64
  <div>
62
65
  <dt>Lessons</dt>
63
- <dd>{{ done }} of {{ lessons.length }}</dd>
66
+ <dd>{{ done }} of {{ props.lessons.length }}</dd>
64
67
  </div>
65
68
  <div>
66
69
  <dt>Quizzes right</dt>
@@ -79,7 +82,7 @@
79
82
  }
80
83
  <h2>Lessons</h2>
81
84
  <ol class="progress-lessons">
82
- @for (lesson of lessons; track lesson.href) {
85
+ @for (lesson of props.lessons; track lesson.href) {
83
86
  <li [data-status]="statuses[lesson.href] ?? false">
84
87
  <a [href]="lesson.href">{{ lesson.title }}</a
85
88
  >@if (statuses[lesson.href]) { <span class="status-note">({{ statuses[lesson.href] === 'current' ? 'up next' : statuses[lesson.href] === 'done' ? 'done' : 'not started' }})</span>}
@@ -3,15 +3,19 @@
3
3
  the quiz's answer and marks the options. In a lesson, the action bar's Check sends a quiz:check event to the quiz;
4
4
  the result goes back as a bubbling quiz:result event ({ ok, done, text }), so the bar can turn green or red.
5
5
  --}}
6
- @input name: string
7
- @input options: string[]
8
- @input answer: number
9
6
 
10
- <script>
7
+ <script lang="ts">
8
+ import { browser } from 'clarusjs/runtime'
9
+ const props = props<{
10
+ name: string
11
+ options: string[]
12
+ answer: number
13
+ }>()
14
+
11
15
  let picked = state(-1)
12
16
  let checked = state(false)
13
17
  let status = state('')
14
- const quiz = () => document.querySelector('[data-quiz="' + name + '"]')
18
+ const quiz = () => document.querySelector('[data-quiz="' + props.name + '"]')
15
19
  function check() {
16
20
  let detail
17
21
  if (picked < 0) {
@@ -19,16 +23,16 @@
19
23
  detail = { ok: false, done: false, text: status }
20
24
  } else {
21
25
  checked = true
22
- const ok = picked === answer
23
- status = ok ? 'Correct.' : 'Not quite. The answer is: ' + options[answer] + '.'
24
- detail = { ok, done: true, text: ok ? 'Correct.' : 'The answer is: ' + options[answer] + '.' }
26
+ const ok = picked === props.answer
27
+ status = ok ? 'Correct.' : 'Not quite. The answer is: ' + props.options[props.answer] + '.'
28
+ detail = { ok, done: true, text: ok ? 'Correct.' : 'The answer is: ' + props.options[props.answer] + '.' }
25
29
  quiz()?.setAttribute('data-answered', ok ? 'right' : 'wrong')
26
30
  const details = quiz()?.querySelector('.quiz-answer')
27
31
  if (details instanceof HTMLDetailsElement) details.open = true
28
32
  }
29
33
  quiz()?.dispatchEvent(new CustomEvent('quiz:result', { bubbles: true, detail }))
30
34
  }
31
- if (typeof document !== 'undefined') {
35
+ if (browser) {
32
36
  document.addEventListener('quiz:check', (event) => {
33
37
  if (event.target === quiz() && !checked) check()
34
38
  })
@@ -36,11 +40,11 @@
36
40
  </script>
37
41
 
38
42
  <div class="quiz-choices">
39
- <div class="quiz-options" role="radiogroup" [aria-labelledby]="name + '-q'">
40
- @for (option of options; track $index) {
41
- <label [class]="!checked ? false : $index === answer ? 'right' : $index === picked ? 'wrong' : false"
42
- ><input type="radio" [name]="name" [value]="$index" [disabled]="checked" (change)="picked = $index" />
43
- {{ option }}@if (checked && $index === answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label
43
+ <div class="quiz-options" role="radiogroup" [aria-labelledby]="props.name + '-q'">
44
+ @for (option of props.options; track $index) {
45
+ <label [class]="!checked ? false : $index === props.answer ? 'right' : $index === picked ? 'wrong' : false"
46
+ ><input type="radio" [name]="props.name" [value]="$index" [disabled]="checked" (change)="picked = $index" />
47
+ {{ option }}@if (checked && $index === props.answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label
44
48
  >
45
49
  }
46
50
  </div>
package/src/quiz.tscl CHANGED
@@ -4,17 +4,21 @@
4
4
  <details> shows the answer.
5
5
  --}}
6
6
  @import quizChoices from './quiz-choices.tscl'
7
- @input name: string
8
- @input question: string
9
- @input options: string[]
10
- @input answer: number
7
+ <script lang="ts">
8
+ const props = props<{
9
+ name: string
10
+ question: string
11
+ options: string[]
12
+ answer: number
13
+ }>()
14
+ </script>
11
15
 
12
- <div class="quiz" [data-quiz]="name">
13
- <p class="quiz-question" [id]="name + '-q'">{{ question }}</p>
14
- <quizChoices [name]="name" [options]="options" [answer]="answer" />
16
+ <div class="quiz" [data-quiz]="props.name">
17
+ <p class="quiz-question" [id]="props.name + '-q'">{{ props.question }}</p>
18
+ <quizChoices [name]="props.name" [options]="props.options" [answer]="props.answer" />
15
19
  <details class="quiz-answer">
16
20
  <summary>Show the answer</summary>
17
- <p class="quiz-correct">Answer: {{ options[answer] }}</p>
21
+ <p class="quiz-correct">Answer: {{ props.options[props.answer] }}</p>
18
22
  <slot />
19
23
  </details>
20
24
  </div>
package/src/search.tscl CHANGED
@@ -7,6 +7,7 @@
7
7
  <script>
8
8
  import { navigate } from 'clarusjs/navigation'
9
9
  import { base, search } from './search.js'
10
+ import { browser } from 'clarusjs/runtime'
10
11
  let query = state('')
11
12
  let results = state([])
12
13
  let active = state(0)
@@ -64,7 +65,7 @@
64
65
  dialog()?.close()
65
66
  }
66
67
  }
67
- if (typeof document !== 'undefined') {
68
+ if (browser) {
68
69
  document.addEventListener('keydown', (event) => {
69
70
  const typing =
70
71
  event.target instanceof Element && event.target.closest('input, textarea, select, [contenteditable]')
@@ -341,6 +341,18 @@ details.custom-block[open] > summary { margin-bottom: 8px; }
341
341
  .code-group > .code-block { order: 1; width: 100%; display: none; margin: 0; }
342
342
  .code-group > input:checked + label + .code-block { display: block; }
343
343
  .code-group > .code-block pre { border-top-left-radius: 0; }
344
+ /* ::: code-group :scroll (or codeGroups: 'scroll' in the theme config, unless the group says :wrap): the tabs on one row
345
+ that scrolls sideways, the code staying in place. A grid of --tabs pairs: each radio in a zero-width column before its
346
+ label, so focusing it (arrow keys) scrolls its tab into view; the code spans the row below at the group's own width
347
+ (100cqi), sticky at its left edge. */
348
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) {
349
+ display: grid; grid-template-columns: repeat(var(--tabs, 1), 0 max-content); position: relative;
350
+ overflow-x: auto; scrollbar-width: thin; container-type: inline-size;
351
+ }
352
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > input { position: static; grid-row: 1; width: 0; height: 0; margin: 0; scroll-margin-inline-end: 16rem; }
353
+ /* A label is at most as wide as its radio's scroll margin, so focusing the radio brings the whole tab into view. */
354
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > label { grid-row: 1; white-space: nowrap; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
355
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > .code-block { grid-row: 2; grid-column: 1 / -1; width: 100cqi; position: sticky; left: 0; }
344
356
 
345
357
  /* Visitors who ask for less motion get none: transitions and animations end at once, scrolling jumps. */
346
358
  @media (prefers-reduced-motion: reduce) {
package/src/theme.css CHANGED
@@ -1298,6 +1298,36 @@ details.custom-block[open] > summary {
1298
1298
  .code-group > .code-block pre {
1299
1299
  border-top-left-radius: 0;
1300
1300
  }
1301
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) {
1302
+ display: grid;
1303
+ grid-template-columns: repeat(var(--tabs, 1), 0 max-content);
1304
+ position: relative;
1305
+ overflow-x: auto;
1306
+ scrollbar-width: thin;
1307
+ container-type: inline-size;
1308
+ }
1309
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > input {
1310
+ position: static;
1311
+ grid-row: 1;
1312
+ width: 0;
1313
+ height: 0;
1314
+ margin: 0;
1315
+ scroll-margin-inline-end: 16rem;
1316
+ }
1317
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > label {
1318
+ grid-row: 1;
1319
+ white-space: nowrap;
1320
+ max-width: 16rem;
1321
+ overflow: hidden;
1322
+ text-overflow: ellipsis;
1323
+ }
1324
+ :is(.code-group.scroll, [data-code-groups="scroll"] .code-group:not(.wrap)) > .code-block {
1325
+ grid-row: 2;
1326
+ grid-column: 1 / -1;
1327
+ width: 100cqi;
1328
+ position: sticky;
1329
+ left: 0;
1330
+ }
1301
1331
  @media (prefers-reduced-motion: reduce) {
1302
1332
  *, *::before, *::after {
1303
1333
  animation-duration: 0.01ms !important;
package/src/vite.js CHANGED
@@ -293,7 +293,8 @@ export function buildIndex(sections) {
293
293
  for (const [word, n] of uses) weights.set(word, Math.min(n, 3))
294
294
  for (const word of tokens(section.h)) weights.set(word, (weights.get(word) ?? 0) + 10)
295
295
  for (const [word, weight] of weights) {
296
- const shard = shards.get(termFile(word)) ?? shards.set(termFile(word), {}).get(termFile(word))
296
+ // No prototype: words like constructor and __proto__ are terms like any other.
297
+ const shard = shards.get(termFile(word)) ?? shards.set(termFile(word), Object.create(null)).get(termFile(word))
297
298
  ;(/** @type {Record<string, number[]>} */ (shard)[word] ??= []).push(id, weight)
298
299
  }
299
300
  }