@clarusjs/theme-docs 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clarusjs/theme-docs",
3
- "version": "0.6.0",
3
+ "version": "0.8.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",
@@ -12,11 +12,14 @@
12
12
  "exports": {
13
13
  "./*": "./src/*"
14
14
  },
15
+ "bin": {
16
+ "clarusjs-docs-versions": "./src/versions-cli.js"
17
+ },
15
18
  "publishConfig": {
16
19
  "access": "public"
17
20
  },
18
21
  "peerDependencies": {
19
- "clarusjs": "^0.19.0",
22
+ "clarusjs": "^0.21.0",
20
23
  "mermaid": ">=11"
21
24
  },
22
25
  "engines": {
@@ -40,13 +43,13 @@
40
43
  },
41
44
  "devDependencies": {
42
45
  "@tailwindcss/cli": "4.3.5",
43
- "@types/node": "^26.6.6",
44
- "clarusjs": "^0.19.0",
45
- "mermaid": "12.3.0",
46
+ "@types/node": "^26.6.11",
47
+ "clarusjs": "^0.21.0",
48
+ "mermaid": "12.4.0",
46
49
  "tailwindcss": "4.3.5",
47
50
  "typescript": "^7.0.2",
48
- "vite": "^8.3.8",
49
- "vitest": "^5.1.1"
51
+ "vite": "^8.4.0",
52
+ "vitest": "^5.1.2"
50
53
  },
51
54
  "peerDependenciesMeta": {
52
55
  "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/mermaid.tscl CHANGED
@@ -20,8 +20,11 @@
20
20
  async function draw() {
21
21
  const run = ++latest
22
22
  try {
23
- const { default: mermaid } = await import('mermaid')
24
- mermaid.initialize({ startOnLoad: false, securityLevel: 'strict', theme: dark() ? 'dark' : 'default' })
23
+ // Once more if it fails: in dev, an import can fail while Vite re-optimizes dependencies
24
+ const { default: mermaid } = await import('mermaid').catch(() => new Promise((r) => setTimeout(r, 500)).then(() => import('mermaid')))
25
+ mermaid.initialize({ startOnLoad: false, securityLevel: 'strict', theme: dark() ? 'dark' : 'default',
26
+ // Dark edge labels: Mermaid's #ccc on #585858 is 4.4:1, under WCAG AA's 4.5; on #333 it's 7.9:1
27
+ ...(dark() && { themeVariables: { edgeLabelBackground: '#333333' } }) })
25
28
  const { svg } = await mermaid.render('cl-mermaid-' + Math.random().toString(36).slice(2), source)
26
29
  if (gone || run !== latest) return
27
30
  let out = box.querySelector('.mermaid-svg')