@clarusjs/theme-docs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clarusjs/theme-docs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A docs theme for clarusjs: layout with header, sidebar, content and on-this-page, design tokens, dark mode, copy buttons and callouts.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "access": "public"
17
17
  },
18
18
  "peerDependencies": {
19
- "clarusjs": "^0.9.0"
19
+ "clarusjs": "^0.10.0"
20
20
  },
21
21
  "engines": {
22
22
  "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^26.6.6",
42
- "clarusjs": "^0.9.0",
42
+ "clarusjs": "^0.10.0",
43
43
  "typescript": "^7.0.2",
44
44
  "vitest": "^5.1.1",
45
45
  "vite": "^8.3.8"
package/src/callout.tscl CHANGED
@@ -1,7 +1,12 @@
1
1
  @type Kind = 'tip' | 'info' | 'warning' | 'danger'
2
2
  @input type: Kind = 'info'
3
3
 
4
- <aside role="note" class="callout {{ type }}"><p class="callout-title"><slot name="title">{{ type[0].toUpperCase() + type.slice(1) }}</slot></p><slot /></aside>
4
+ <aside role="note" class="callout {{ type }}">
5
+ <p class="callout-title">
6
+ <slot name="title">{{ type[0].toUpperCase() + type.slice(1) }}</slot>
7
+ </p>
8
+ <slot />
9
+ </aside>
5
10
 
6
11
  <style scoped>
7
12
  /* Scoped to this component: :scope is the <aside>; slot content inside it is styled too. */
@@ -12,9 +17,20 @@
12
17
  border-radius: 0 8px 8px 0;
13
18
  margin: 24px 0;
14
19
  }
15
- :scope.tip { border-left-color: #2f9e6e; }
16
- :scope.warning { border-left-color: #c98a12; }
17
- :scope.danger { border-left-color: #d0453b; }
18
- .callout-title { margin: 0 0 4px; font-weight: 650; }
19
- p:last-child { margin-bottom: 0; }
20
+ :scope.tip {
21
+ border-left-color: #2f9e6e;
22
+ }
23
+ :scope.warning {
24
+ border-left-color: #c98a12;
25
+ }
26
+ :scope.danger {
27
+ border-left-color: #d0453b;
28
+ }
29
+ .callout-title {
30
+ margin: 0 0 4px;
31
+ font-weight: 650;
32
+ }
33
+ p:last-child {
34
+ margin-bottom: 0;
35
+ }
20
36
  </style>
package/src/copy.tscl CHANGED
@@ -1,19 +1,23 @@
1
1
  {{-- A copy button for the code it sits next to: a .sample wrapper, or a highlighted .code-block from Markdown. --}}
2
+
2
3
  <script>
3
4
  let copied = state(false)
4
5
  async function copy(button) {
5
6
  const block = button.closest('.sample, .code-block')?.querySelector('code')
6
7
  // Removed diff lines aren't part of the code to copy.
7
8
  const clone = block?.cloneNode(true)
8
- if (clone instanceof Element) clone.querySelectorAll('.diff.remove').forEach((line) => {
9
- if (line.nextSibling?.nodeType === 3 && line.nextSibling.textContent === '\n') line.nextSibling.remove() // its newline too
10
- line.remove()
11
- })
9
+ if (clone instanceof Element)
10
+ clone.querySelectorAll('.diff.remove').forEach((line) => {
11
+ if (line.nextSibling?.nodeType === 3 && line.nextSibling.textContent === '\n') line.nextSibling.remove() // its newline too
12
+ line.remove()
13
+ })
12
14
  const code = clone?.textContent ?? ''
13
15
  try {
14
16
  await navigator.clipboard.writeText(code)
15
17
  copied = true
16
- setTimeout(() => { copied = false }, 1500)
18
+ setTimeout(() => {
19
+ copied = false
20
+ }, 1500)
17
21
  } catch {}
18
22
  }
19
23
  </script>
package/src/layout.tscl CHANGED
@@ -24,20 +24,33 @@
24
24
  @input headings: Heading[] = []
25
25
 
26
26
  <html lang="en">
27
- <head><pageHead [config]="config" [title]="title" [description]="description" [url]="url || path" /></head>
27
+ <head>
28
+ <pageHead [config]="config" [title]="title" [description]="description" [url]="url || path" />
29
+ </head>
28
30
  <body>
29
31
  {{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
30
32
  <a class="skip-link" href="#content">Skip to content</a>
31
33
  <header class="site-header">
32
34
  @if (sectionKey(config.sections, path)) {
33
35
  <button type="button" class="menu-button" popovertarget="sidebar" aria-label="Open menu">
34
- <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"></path></svg>
36
+ <svg
37
+ width="22"
38
+ height="22"
39
+ viewBox="0 0 24 24"
40
+ fill="none"
41
+ stroke="currentColor"
42
+ stroke-width="2.2"
43
+ stroke-linecap="round"
44
+ aria-hidden="true"
45
+ >
46
+ <path d="M4 7h16M4 12h16M4 17h16"></path>
47
+ </svg>
35
48
  </button>
36
49
  }
37
- <a class="brand" href="/">@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
- <nav class="top-nav" aria-label="Main">
39
- @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>}
40
- </nav>
50
+ <a class="brand" href="/"
51
+ >@if (config.brand.logo) {<img [src]="config.brand.logo" alt="" width="28" height="28">}<span>{{ config.brand.text }}@if (config.brand.accent) {<span class="js">{{ config.brand.accent }}</span>}</span></a
52
+ >
53
+ <nav class="top-nav" aria-label="Main">@for (s of config.sections; track s.key) {<a [href]="s.href" [aria-current]="sectionKey(config.sections, path) === s.key ? 'true' : false">{{ s.title }}</a>}</nav>
41
54
  <div class="header-end">
42
55
  {{-- On Learn pages: the XP chip, and the sidebar's lessons marked done, current or locked. --}}
43
56
  @if (config.learn && sectionKey(config.sections, path) === config.learn.section) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
@@ -46,18 +59,18 @@
46
59
  @if ((config.social ?? []).length) {
47
60
  <span class="social">
48
61
  @for (link of config.social ?? []; track link.href) {
49
- <a [href]="link.href" [aria-label]="link.label" [title]="link.label">
50
- @if (link.icon === 'github') {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 19c-4 1.5-4-2-6-2.5m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1.1-.3-3.5 1.3a12.3 12.3 0 0 0-6.2 0C6.5 2.8 5.4 3.1 5.4 3.1a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4 9.5c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V21"></path></svg>} @else if (link.icon === 'npm') {<span class="npm" aria-hidden="true">npm</span>} @else {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"></path></svg>}
51
- </a>
62
+ <a [href]="link.href" [aria-label]="link.label" [title]="link.label"> @if (link.icon === 'github') {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 19c-4 1.5-4-2-6-2.5m12 5v-3.5c0-1 .1-1.4-.5-2 2.8-.3 5.5-1.4 5.5-6a4.6 4.6 0 0 0-1.3-3.2 4.2 4.2 0 0 0-.1-3.2s-1.1-.3-3.5 1.3a12.3 12.3 0 0 0-6.2 0C6.5 2.8 5.4 3.1 5.4 3.1a4.2 4.2 0 0 0-.1 3.2A4.6 4.6 0 0 0 4 9.5c0 4.6 2.7 5.7 5.5 6-.6.6-.6 1.2-.5 2V21"></path></svg>} @else if (link.icon === 'npm') {<span class="npm" aria-hidden="true">npm</span>} @else {<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"></path></svg>} </a>
52
63
  }
53
64
  </span>
54
65
  {{-- When the header runs out of room, the social links fold into this menu (native popover). --}}
55
66
  <button type="button" class="more-button" popovertarget="more" aria-label="More links">
56
- <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="5" cy="12" r="2"></circle><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle></svg>
67
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
68
+ <circle cx="5" cy="12" r="2"></circle>
69
+ <circle cx="12" cy="12" r="2"></circle>
70
+ <circle cx="19" cy="12" r="2"></circle>
71
+ </svg>
57
72
  </button>
58
- <div id="more" class="more" popover>
59
- @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
60
- </div>
73
+ <div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
61
74
  }
62
75
  {{-- Kept across fragment navigations: the same element, with its state. --}}
63
76
  <span class="persist" data-cl-persist="theme"><themeToggle /></span>
@@ -71,22 +84,34 @@
71
84
  <div class="sidebar-head">
72
85
  <span>{{ config.brand.text }}{{ config.brand.accent ?? '' }}</span>
73
86
  <button type="button" popovertarget="sidebar" popovertargetaction="hide" aria-label="Close the menu">
74
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"></path></svg>
87
+ <svg
88
+ width="20"
89
+ height="20"
90
+ viewBox="0 0 24 24"
91
+ fill="none"
92
+ stroke="currentColor"
93
+ stroke-width="2.2"
94
+ stroke-linecap="round"
95
+ aria-hidden="true"
96
+ >
97
+ <path d="M6 6l12 12M18 6L6 18"></path>
98
+ </svg>
75
99
  </button>
76
100
  </div>
77
101
  <slot name="sidebar-top"></slot>
78
102
  @for (group of groupsOf(config.sections, path); track group.title) {
79
103
  <p class="group">{{ group.title }}</p>
80
104
  <ul>
81
- @for (item of group.items; track item.href) {<li><a [href]="item.href" [aria-current]="item.href === path ? 'page' : false">{{ item.title }}</a></li>}
105
+ @for (item of group.items; track item.href) {
106
+ <li>
107
+ <a [href]="item.href" [aria-current]="item.href === path ? 'page' : false">{{ item.title }}</a>
108
+ </li>
109
+ }
82
110
  </ul>
83
111
  }
84
112
  <slot name="sidebar-bottom"></slot>
85
113
  {{-- On phones, the header's links live here. --}}
86
- <div class="sidebar-links">
87
- @for (s of config.sections; track s.key) {<a [href]="s.href">{{ s.title }}</a>}
88
- @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}
89
- </div>
114
+ <div class="sidebar-links">@for (s of config.sections; track s.key) {<a [href]="s.href">{{ s.title }}</a>} @for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
90
115
  </nav>
91
116
  {{-- tabindex -1: the skip link (and navigation) can move focus here. --}}
92
117
  <main class="content" id="content" tabindex="-1">
@@ -94,7 +119,13 @@
94
119
  @if (headings.length) {
95
120
  <details class="toc-inline">
96
121
  <summary>On this page</summary>
97
- <ul>@for (h of headings; track h.id) {<li [class]="h.level === 3 ? 'sub' : false"><a [href]="'#' + h.id">{{ h.text }}</a></li>}</ul>
122
+ <ul>
123
+ @for (h of headings; track h.id) {
124
+ <li [class]="h.level === 3 ? 'sub' : false">
125
+ <a [href]="'#' + h.id">{{ h.text }}</a>
126
+ </li>
127
+ }
128
+ </ul>
98
129
  </details>
99
130
  }
100
131
  <slot name="content-top"></slot>
@@ -102,17 +133,27 @@
102
133
  <slot name="content-bottom"></slot>
103
134
  <footer class="page-footer">
104
135
  @if (editHref(config, source || path)) {<a class="edit" [href]="editHref(config, source || path)">Edit this page on GitHub</a>}
105
- @if (updatedOf(config, source || path)) {<p class="updated">Last updated <time [datetime]="updatedOf(config, source || path)?.iso">{{ updatedOf(config, source || path)?.text }}</time></p>}
106
- <nav class="pager" aria-label="Previous and next">
107
- @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>}
108
- @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>}
109
- </nav>
136
+ @if (updatedOf(config, source || path)) {
137
+ <p class="updated">
138
+ Last updated
139
+ <time [datetime]="updatedOf(config, source || path)?.iso">{{
140
+ updatedOf(config, source || path)?.text
141
+ }}</time>
142
+ </p>
143
+ }
144
+ <nav class="pager" aria-label="Previous and next">@if (pager(config.sections, path).prev.href) {<a class="prev" [href]="pager(config.sections, path).prev.href"><small>Previous</small>{{ pager(config.sections, path).prev.title }}</a>} @if (pager(config.sections, path).next.href) {<a class="next" [href]="pager(config.sections, path).next.href"><small>Next</small>{{ pager(config.sections, path).next.title }}</a>}</nav>
110
145
  </footer>
111
146
  </main>
112
147
  @if (headings.length) {
113
148
  <aside class="toc" aria-label="On this page">
114
149
  <p>On this page</p>
115
- <ul>@for (h of headings; track h.id) {<li [class]="h.level === 3 ? 'sub' : false"><a [href]="'#' + h.id">{{ h.text }}</a></li>}</ul>
150
+ <ul>
151
+ @for (h of headings; track h.id) {
152
+ <li [class]="h.level === 3 ? 'sub' : false">
153
+ <a [href]="'#' + h.id">{{ h.text }}</a>
154
+ </li>
155
+ }
156
+ </ul>
116
157
  </aside>
117
158
  }
118
159
  </div>
@@ -36,6 +36,8 @@
36
36
  </script>
37
37
 
38
38
  <a class="xp-chip" [href]="progress" [hidden]="!ready" [aria-label]="xp + ' XP: your progress'">
39
- <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M13 2L4 14h7l-1 8 9-12h-7z"></path></svg>
39
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
40
+ <path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
41
+ </svg>
40
42
  {{ xp }} XP
41
43
  </a>
@@ -37,7 +37,9 @@
37
37
  if (!all.length) return
38
38
  current = Math.max(0, Math.min(i, all.length - 1))
39
39
  total = all.length
40
- all.forEach((step, j) => { step.hidden = j !== current })
40
+ all.forEach((step, j) => {
41
+ step.hidden = j !== current
42
+ })
41
43
  checking = !!all[current].querySelector('[data-quiz]:not([data-answered])')
42
44
  verdict('', '', '')
43
45
  const id = all[current].getAttribute('aria-labelledby') ?? ''
@@ -57,7 +59,9 @@
57
59
  // The step a #hash points into: its own heading, or anything inside it.
58
60
  const indexOf = (hash) => {
59
61
  const id = decodeURIComponent(hash.slice(1))
60
- return id ? steps().findIndex((s) => s.getAttribute('aria-labelledby') === id || s.querySelector('#' + CSS.escape(id))) : -1
62
+ return id
63
+ ? steps().findIndex((s) => s.getAttribute('aria-labelledby') === id || s.querySelector('#' + CSS.escape(id)))
64
+ : -1
61
65
  }
62
66
  function back() {
63
67
  if (current > 0) show(current - 1, true)
@@ -65,7 +69,9 @@
65
69
  }
66
70
  function forward() {
67
71
  if (checking) {
68
- steps()[current]?.querySelector('[data-quiz]:not([data-answered])')?.dispatchEvent(new CustomEvent('quiz:check', { bubbles: true }))
72
+ steps()
73
+ [current]?.querySelector('[data-quiz]:not([data-answered])')
74
+ ?.dispatchEvent(new CustomEvent('quiz:check', { bubbles: true }))
69
75
  return
70
76
  }
71
77
  const id = steps()[current]?.getAttribute('aria-labelledby')
@@ -107,7 +113,12 @@
107
113
  }
108
114
  if (!reveal()) show(0, false)
109
115
  document.addEventListener('quiz:result', (event) => {
110
- if (!(event instanceof CustomEvent) || !(event.target instanceof HTMLElement) || !steps()[current]?.contains(event.target)) return
116
+ if (
117
+ !(event instanceof CustomEvent) ||
118
+ !(event.target instanceof HTMLElement) ||
119
+ !steps()[current]?.contains(event.target)
120
+ )
121
+ return
111
122
  const { ok, done, text: detail } = event.detail
112
123
  if (!done) return verdict('', 'Pick an answer', detail)
113
124
  const quiz = event.target.dataset.quiz
@@ -122,7 +133,12 @@
122
133
  <div class="lesson-actions">
123
134
  <button type="button" class="back" (click)="back()" [disabled]="current === 0 && !prev">Back</button>
124
135
  <div class="feedback" role="status">
125
- @if (title) {<p class="feedback-title">{{ title }}</p><p class="feedback-text">{{ text }}</p>} @else if (total) {<p class="feedback-title">Step {{ current + 1 }} of {{ total }}: {{ name }}</p>}
136
+ @if (title) {
137
+ <p class="feedback-title">{{ title }}</p>
138
+ <p class="feedback-text">{{ text }}</p>
139
+ } @else if (total) {
140
+ <p class="feedback-title">Step {{ current + 1 }} of {{ total }}: {{ name }}</p>
141
+ }
126
142
  </div>
127
143
  <button type="button" class="primary" (click)="forward()">@if (checking) {Check} @else if (total && current === total - 1) {@if (next) {Next lesson} @else {Finish}} @else {Continue}</button>
128
144
  </div>
package/src/lesson.tscl CHANGED
@@ -19,25 +19,51 @@
19
19
  @input headings: Heading[] = []
20
20
 
21
21
  <html lang="en">
22
- <head><pageHead [config]="config" [title]="title" [description]="description" [url]="path" /></head>
22
+ <head>
23
+ <pageHead [config]="config" [title]="title" [description]="description" [url]="path" />
24
+ </head>
23
25
  <body class="lesson-page">
24
26
  <a class="skip-link" href="#content">Skip to content</a>
25
27
  <header class="lesson-header">
26
28
  <a class="leave" [href]="lessonOf(config, path).leave" aria-label="Leave the lesson">
27
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"></path></svg>
29
+ <svg
30
+ width="20"
31
+ height="20"
32
+ viewBox="0 0 24 24"
33
+ fill="none"
34
+ stroke="currentColor"
35
+ stroke-width="2.2"
36
+ stroke-linecap="round"
37
+ aria-hidden="true"
38
+ >
39
+ <path d="M6 6l12 12M18 6L6 18"></path>
40
+ </svg>
28
41
  </a>
29
42
  <div class="lesson-name">
30
- @if (lessonOf(config, path).total) {<p class="eyebrow">{{ lessonOf(config, path).label }}</p>}
43
+ @if (lessonOf(config, path).total) {
44
+ <p class="eyebrow">{{ lessonOf(config, path).label }}</p>
45
+ }
31
46
  <p class="name">{{ title }}</p>
32
47
  </div>
33
48
  {{-- Links to each step: jumps without JavaScript, the progress bar with it. --}}
34
49
  <ol class="segments" aria-label="Steps">
35
- @for (h of headings.filter((h) => h.level === 2); track h.id) {<li><a [href]="'#' + h.id">{{ h.text }}</a></li>}
50
+ @for (h of headings.filter((h) => h.level === 2); track h.id) {
51
+ <li>
52
+ <a [href]="'#' + h.id">{{ h.text }}</a>
53
+ </li>
54
+ }
36
55
  </ol>
37
56
  @if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
38
57
  <slot name="header-end"></slot>
39
58
  </header>
40
59
  <main class="lesson" id="content" tabindex="-1"><slot /></main>
41
- <div class="lesson-bar" role="region" aria-label="Lesson actions" hidden><lessonBar [lesson]="path" [prev]="lessonOf(config, path).prev" [next]="lessonOf(config, path).next" [leave]="lessonOf(config, path).leave" /></div>
60
+ <div class="lesson-bar" role="region" aria-label="Lesson actions" hidden>
61
+ <lessonBar
62
+ [lesson]="path"
63
+ [prev]="lessonOf(config, path).prev"
64
+ [next]="lessonOf(config, path).next"
65
+ [leave]="lessonOf(config, path).leave"
66
+ />
67
+ </div>
42
68
  </body>
43
69
  </html>
@@ -4,11 +4,22 @@
4
4
  @input title: string
5
5
  @input description: string = ''
6
6
  @input url: string = '/'
7
-
8
7
  {{-- Runs before the first paint: the saved theme is on <html> before anything shows (no flash). --}}
9
- <script inline>try{var t=localStorage.getItem('clarusjs-theme');if(t==='light'||t==='dark')document.documentElement.setAttribute('data-theme',t)}catch(e){}</script>
10
- <meta charset="utf-8">
11
- <meta name="viewport" content="width=device-width, initial-scale=1">
12
- @if (description) {<meta name="description" content="{{ description }}">}
8
+
9
+ <script inline>
10
+ try {
11
+ var t = localStorage.getItem('clarusjs-theme')
12
+ if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t)
13
+ } catch (e) {}
14
+ </script>
15
+ <meta charset="utf-8" />
16
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
17
+ @if (description) {
18
+ <meta name="description" content="{{ description }}" />
19
+ }
13
20
  <title>{{ title }}</title>
14
- @if (config.siteUrl) {<script type="application/ld+json">{{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}</script>}
21
+ @if (config.siteUrl) {
22
+ <script type="application/ld+json">
23
+ {{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
24
+ </script>
25
+ }
@@ -15,15 +15,23 @@
15
15
  let mode = state('waiting')
16
16
  let confirming = state(false)
17
17
  function refresh() {
18
- const s = stats(load(), lessons.map((l) => l.href))
18
+ const s = stats(
19
+ load(),
20
+ lessons.map((l) => l.href),
21
+ )
19
22
  xp = s.xp
20
23
  done = s.done
21
- accuracy = s.answered ? Math.round((s.right / s.answered) * 100) + '% (' + s.right + ' of ' + s.answered + ')' : 'no quizzes answered yet'
24
+ accuracy = s.answered
25
+ ? Math.round((s.right / s.answered) * 100) + '% (' + s.right + ' of ' + s.answered + ')'
26
+ : 'no quizzes answered yet'
22
27
  badges = s.badges
23
28
  statuses = Object.fromEntries(lessons.map((l) => [l.href, s.status(l.href)]))
24
29
  }
25
30
  function wipe() {
26
- if (!confirming) { confirming = true; return }
31
+ if (!confirming) {
32
+ confirming = true
33
+ return
34
+ }
27
35
  reset()
28
36
  confirming = false
29
37
  refresh()
@@ -40,26 +48,47 @@
40
48
  @if (mode === 'waiting') {
41
49
  <p class="progress-note">Your progress is kept in this browser and shows here with JavaScript on.</p>
42
50
  } @else {
43
- @if (mode === 'blocked') {<p class="progress-note">This browser isn't keeping your progress (storage is blocked), so it lasts until you leave the page.</p>}
51
+ @if (mode === 'blocked') {
52
+ <p class="progress-note">
53
+ This browser isn't keeping your progress (storage is blocked), so it lasts until you leave the page.
54
+ </p>
55
+ }
44
56
  <dl class="progress-stats">
45
- <div><dt>XP</dt><dd>{{ xp }}</dd></div>
46
- <div><dt>Lessons</dt><dd>{{ done }} of {{ lessons.length }}</dd></div>
47
- <div><dt>Quizzes right</dt><dd>{{ accuracy }}</dd></div>
57
+ <div>
58
+ <dt>XP</dt>
59
+ <dd>{{ xp }}</dd>
60
+ </div>
61
+ <div>
62
+ <dt>Lessons</dt>
63
+ <dd>{{ done }} of {{ lessons.length }}</dd>
64
+ </div>
65
+ <div>
66
+ <dt>Quizzes right</dt>
67
+ <dd>{{ accuracy }}</dd>
68
+ </div>
48
69
  </dl>
49
70
  <h2>Badges</h2>
50
71
  <ul class="badges">
51
72
  @for (badge of badges; track badge.id) {
52
- <li [class]="badge.earned ? 'earned' : false"><strong>{{ badge.title }}</strong> <span>{{ badge.text }}</span> <em>{{ badge.earned ? 'Earned' : 'Not yet' }}</em></li>
73
+ <li [class]="badge.earned ? 'earned' : false">
74
+ <strong>{{ badge.title }}</strong> <span>{{ badge.text }}</span>
75
+ <em>{{ badge.earned ? 'Earned' : 'Not yet' }}</em>
76
+ </li>
53
77
  }
54
78
  </ul>
55
79
  }
56
80
  <h2>Lessons</h2>
57
81
  <ol class="progress-lessons">
58
82
  @for (lesson of lessons; track lesson.href) {
59
- <li [data-status]="statuses[lesson.href] ?? false"><a [href]="lesson.href">{{ lesson.title }}</a>@if (statuses[lesson.href]) { <span class="status-note">({{ statuses[lesson.href] === 'current' ? 'up next' : statuses[lesson.href] === 'done' ? 'done' : 'not started' }})</span>}</li>
83
+ <li [data-status]="statuses[lesson.href] ?? false">
84
+ <a [href]="lesson.href">{{ lesson.title }}</a
85
+ >@if (statuses[lesson.href]) { <span class="status-note">({{ statuses[lesson.href] === 'current' ? 'up next' : statuses[lesson.href] === 'done' ? 'done' : 'not started' }})</span>}
86
+ </li>
60
87
  }
61
88
  </ol>
62
89
  @if (mode !== 'waiting') {
63
- <button type="button" class="progress-reset" (click)="wipe()">{{ confirming ? 'Click again to erase your progress' : 'Reset progress' }}</button>
90
+ <button type="button" class="progress-reset" (click)="wipe()">
91
+ {{ confirming ? 'Click again to erase your progress' : 'Reset progress' }}
92
+ </button>
64
93
  }
65
94
  </div>
@@ -29,14 +29,19 @@
29
29
  quiz()?.dispatchEvent(new CustomEvent('quiz:result', { bubbles: true, detail }))
30
30
  }
31
31
  if (typeof document !== 'undefined') {
32
- document.addEventListener('quiz:check', (event) => { if (event.target === quiz() && !checked) check() })
32
+ document.addEventListener('quiz:check', (event) => {
33
+ if (event.target === quiz() && !checked) check()
34
+ })
33
35
  }
34
36
  </script>
35
37
 
36
38
  <div class="quiz-choices">
37
39
  <div class="quiz-options" role="radiogroup" [aria-labelledby]="name + '-q'">
38
40
  @for (option of options; track $index) {
39
- <label [class]="!checked ? false : $index === answer ? 'right' : $index === picked ? 'wrong' : false"><input type="radio" [name]="name" [value]="$index" [disabled]="checked" (change)="picked = $index"> {{ option }}@if (checked && $index === answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label>
41
+ <label [class]="!checked ? false : $index === answer ? 'right' : $index === picked ? 'wrong' : false"
42
+ ><input type="radio" [name]="name" [value]="$index" [disabled]="checked" (change)="picked = $index" />
43
+ {{ option }}@if (checked && $index === answer) {<span class="mark">✓ Right answer</span>} @else if (checked && $index === picked) {<span class="mark">✗ Your pick</span>}</label
44
+ >
40
45
  }
41
46
  </div>
42
47
  <button type="button" class="quiz-check" (click)="check()" [disabled]="checked">Check</button>
package/src/quiz.tscl CHANGED
@@ -12,5 +12,9 @@
12
12
  <div class="quiz" [data-quiz]="name">
13
13
  <p class="quiz-question" [id]="name + '-q'">{{ question }}</p>
14
14
  <quizChoices [name]="name" [options]="options" [answer]="answer" />
15
- <details class="quiz-answer"><summary>Show the answer</summary><p class="quiz-correct">Answer: {{ options[answer] }}</p><slot /></details>
15
+ <details class="quiz-answer">
16
+ <summary>Show the answer</summary>
17
+ <p class="quiz-correct">Answer: {{ options[answer] }}</p>
18
+ <slot />
19
+ </details>
16
20
  </div>
package/src/search.tscl CHANGED
@@ -3,6 +3,7 @@
3
3
  Escape closes it and focus goes back. Arrow keys move through the results, Enter opens one. The index is the one
4
4
  themeDocs() writes at build time; a query fetches only the files it needs.
5
5
  --}}
6
+
6
7
  <script>
7
8
  import { navigate } from 'clarusjs/navigation'
8
9
  import { base, search } from './search.js'
@@ -10,7 +11,15 @@
10
11
  let results = state([])
11
12
  let active = state(0)
12
13
  let searched = state(false)
13
- const status = derived(() => !searched ? '' : results.length === 0 ? 'No results for "' + query + '"' : results.length === 1 ? '1 result' : results.length + ' results')
14
+ const status = derived(() =>
15
+ !searched
16
+ ? ''
17
+ : results.length === 0
18
+ ? 'No results for "' + query + '"'
19
+ : results.length === 1
20
+ ? '1 result'
21
+ : results.length + ' results',
22
+ )
14
23
  const load = (file) => fetch(base + 'search/' + file).then((r) => (r.ok ? r.json() : {}))
15
24
  let latest = 0
16
25
  async function run(value) {
@@ -22,7 +31,10 @@
22
31
  active = 0
23
32
  searched = value.trim() !== ''
24
33
  }
25
- const dialog = () => { const d = document.querySelector('.search-dialog'); return d instanceof HTMLDialogElement ? d : null }
34
+ const dialog = () => {
35
+ const d = document.querySelector('.search-dialog')
36
+ return d instanceof HTMLDialogElement ? d : null
37
+ }
26
38
  function open() {
27
39
  const d = dialog()
28
40
  if (!d || d.open) return
@@ -35,15 +47,27 @@
35
47
  document.getElementById('search-result-' + active)?.scrollIntoView({ block: 'nearest' })
36
48
  }
37
49
  function key(event) {
38
- if (event.key === 'ArrowDown') { event.preventDefault(); move(1) }
39
- else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1) }
40
- else if (event.key === 'Enter' && results.length) { event.preventDefault(); dialog()?.close(); navigate(results[active].u) }
50
+ if (event.key === 'ArrowDown') {
51
+ event.preventDefault()
52
+ move(1)
53
+ } else if (event.key === 'ArrowUp') {
54
+ event.preventDefault()
55
+ move(-1)
56
+ } else if (event.key === 'Enter' && results.length) {
57
+ event.preventDefault()
58
+ dialog()?.close()
59
+ navigate(results[active].u)
60
+ }
41
61
  // One Escape closes (a search field would only clear itself first).
42
- else if (event.key === 'Escape') { event.preventDefault(); dialog()?.close() }
62
+ else if (event.key === 'Escape') {
63
+ event.preventDefault()
64
+ dialog()?.close()
65
+ }
43
66
  }
44
67
  if (typeof document !== 'undefined') {
45
68
  document.addEventListener('keydown', (event) => {
46
- const typing = event.target instanceof Element && event.target.closest('input, textarea, select, [contenteditable]')
69
+ const typing =
70
+ event.target instanceof Element && event.target.closest('input, textarea, select, [contenteditable]')
47
71
  if ((event.key === 'k' && (event.metaKey || event.ctrlKey)) || (event.key === '/' && !typing)) {
48
72
  event.preventDefault()
49
73
  open()
@@ -54,19 +78,51 @@
54
78
 
55
79
  <div class="search">
56
80
  <button type="button" class="search-button" aria-haspopup="dialog" (click)="open()">
57
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="7"></circle><path d="M20 20l-3.5-3.5"></path></svg>
81
+ <svg
82
+ width="16"
83
+ height="16"
84
+ viewBox="0 0 24 24"
85
+ fill="none"
86
+ stroke="currentColor"
87
+ stroke-width="2"
88
+ stroke-linecap="round"
89
+ aria-hidden="true"
90
+ >
91
+ <circle cx="11" cy="11" r="7"></circle>
92
+ <path d="M20 20l-3.5-3.5"></path>
93
+ </svg>
58
94
  <span class="search-label">Search</span>
59
95
  <kbd aria-hidden="true">⌘K</kbd>
60
96
  </button>
61
97
  {{-- A click on the backdrop (the dialog itself, outside its box) closes it; so does choosing a result. --}}
62
- <dialog class="search-dialog" aria-label="Search the docs" (click)="($event.target.matches('dialog') || $event.target.closest('a')) && dialog()?.close()">
98
+ <dialog
99
+ class="search-dialog"
100
+ aria-label="Search the docs"
101
+ (click)="($event.target.matches('dialog') || $event.target.closest('a')) && dialog()?.close()"
102
+ >
63
103
  <div class="search-box">
64
- <input type="search" role="combobox" aria-label="Search the docs" aria-controls="search-results" aria-autocomplete="list" [aria-expanded]="results.length ? 'true' : 'false'" [aria-activedescendant]="results.length ? 'search-result-' + active : false" placeholder="Search the docs" autocomplete="off" spellcheck="false" (input)="run($event.target.value)" (keydown)="key($event)">
104
+ <input
105
+ type="search"
106
+ role="combobox"
107
+ aria-label="Search the docs"
108
+ aria-controls="search-results"
109
+ aria-autocomplete="list"
110
+ [aria-expanded]="results.length ? 'true' : 'false'"
111
+ [aria-activedescendant]="results.length ? 'search-result-' + active : false"
112
+ placeholder="Search the docs"
113
+ autocomplete="off"
114
+ spellcheck="false"
115
+ (input)="run($event.target.value)"
116
+ (keydown)="key($event)"
117
+ />
65
118
  <p class="search-status" role="status">{{ status }}</p>
66
119
  <ul id="search-results" role="listbox" aria-label="Results">
67
120
  @for (r of results; track r.u) {
68
121
  <li [id]="'search-result-' + $index" role="option" [aria-selected]="$index === active ? 'true' : 'false'">
69
- <a [href]="r.u" tabindex="-1"><span class="search-heading">{{ r.h }}</span>@if (r.h !== r.p) {<span class="search-page">{{ r.p }}</span>}<span class="search-text">{{ r.t }}</span></a>
122
+ <a [href]="r.u" tabindex="-1"
123
+ ><span class="search-heading">{{ r.h }}</span
124
+ >@if (r.h !== r.p) {<span class="search-page">{{ r.p }}</span>}<span class="search-text">{{ r.t }}</span></a
125
+ >
70
126
  </li>
71
127
  }
72
128
  </ul>
@@ -1,4 +1,5 @@
1
1
  {{-- Light, dark or the system setting; remembered in localStorage and applied as data-theme on <html>. --}}
2
+
2
3
  <script>
3
4
  const order = ['system', 'light', 'dark']
4
5
  let mode = state('system')
@@ -8,16 +9,26 @@
8
9
  }
9
10
  function cycle() {
10
11
  mode = order[(order.indexOf(mode) + 1) % order.length]
11
- try { localStorage.setItem('clarusjs-theme', mode) } catch {}
12
+ try {
13
+ localStorage.setItem('clarusjs-theme', mode)
14
+ } catch {}
12
15
  apply()
13
16
  }
14
17
  // In the browser, start from the saved choice (the server always renders "system").
15
18
  if (typeof document !== 'undefined') {
16
- try { mode = localStorage.getItem('clarusjs-theme') || 'system' } catch {}
19
+ try {
20
+ mode = localStorage.getItem('clarusjs-theme') || 'system'
21
+ } catch {}
17
22
  apply()
18
23
  }
19
24
  </script>
20
25
 
21
- <button type="button" class="theme-toggle" (click)="cycle()" [aria-label]="'Theme: ' + mode + ' (change)'" [title]="'Theme: ' + mode">
26
+ <button
27
+ type="button"
28
+ class="theme-toggle"
29
+ (click)="cycle()"
30
+ [aria-label]="'Theme: ' + mode + ' (change)'"
31
+ [title]="'Theme: ' + mode"
32
+ >
22
33
  @if (mode === 'dark') {☾} @else if (mode === 'light') {☀} @else {◐}
23
34
  </button>
@@ -1,4 +1,5 @@
1
1
  {{-- Turns on view transitions for page changes (config.viewTransitions): no markup of its own, kept across swaps. --}}
2
+
2
3
  <script>
3
4
  import { viewTransitions } from 'clarusjs/navigation'
4
5
  viewTransitions()