@clarusjs/theme-docs 0.4.2 → 0.5.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.4.2",
3
+ "version": "0.5.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.15.0"
19
+ "clarusjs": "^0.16.0"
20
20
  },
21
21
  "engines": {
22
22
  "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@tailwindcss/cli": "4.3.5",
42
42
  "@types/node": "^26.6.6",
43
- "clarusjs": "^0.15.0",
43
+ "clarusjs": "^0.16.0",
44
44
  "tailwindcss": "4.3.5",
45
45
  "typescript": "^7.0.2",
46
46
  "vite": "^8.3.8",
package/src/layout.tscl CHANGED
@@ -33,7 +33,7 @@
33
33
  <body>
34
34
  {{-- First in the tab order: keyboard and screen reader users jump past the header and page list. --}}
35
35
  <a class="skip-link" href="#content">Skip to content</a>
36
- <siteHeader [config]="config" [path]="path" [app]="app" />
36
+ <siteHeader [config]="config" [path]="path" [app]="app">@slot('end') {<slot name="header-end"></slot>}</siteHeader>
37
37
  @if (app) {
38
38
  <main class="content app" id="content" tabindex="-1"><slot /></main>
39
39
  } @else if (sectionKey(config.sections, path)) {
package/src/nav.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export type Item = { title: string; href: string; order?: number; badge?: string; xp?: number; minutes?: number }
10
10
  /** The icons a sidebar group can show (#369). */
11
- export type GroupIcon = 'info' | 'code' | 'box' | 'shield' | 'download' | 'book' | 'terminal' | 'sparkles' | 'layers' | 'wrench' | 'rocket' | 'file'
11
+ export type GroupIcon = 'info' | 'code' | 'box' | 'shield' | 'download' | 'book' | 'terminal' | 'sparkles' | 'layers' | 'wrench' | 'rocket' | 'file' | 'form' | 'pointer' | 'table' | 'panel' | 'overlay' | 'menu' | 'chart' | 'message' | 'image' | 'grid'
12
12
  /**
13
13
  * A sidebar group. `icon`: shown beside its title. `collapsed`: closed until opened (the group of the current page is
14
14
  * always open).
@@ -12,14 +12,16 @@
12
12
  if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t)
13
13
  } catch (e) {}
14
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
- }
20
- <title>{{ title }}</title>
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
+ <fragment>
16
+ <meta charset="utf-8" />
17
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
18
+ @if (description) {
19
+ <meta name="description" content="{{ description }}" />
20
+ }
21
+ <title>{{ title }}</title>
22
+ @if (config.siteUrl) {
23
+ <script type="application/ld+json">
24
+ {{ { '@context': 'https://schema.org', '@type': 'TechArticle', headline: title, description, url: `${config.siteUrl}${url === '/' ? '' : url}` } }}
25
+ </script>
26
+ }
27
+ </fragment>
@@ -7,26 +7,28 @@
7
7
  @input headings: Heading[] = []
8
8
  @input inline: boolean = false
9
9
 
10
- @if (headings.length && inline) {
11
- <details class="toc-inline">
12
- <summary>On this page</summary>
13
- <ul>
14
- @for (h of headings; track h.id) {
15
- <li [class]="h.level === 3 ? 'sub' : false">
16
- <a [href]="'#' + h.id">{{ h.text }}</a>
17
- </li>
18
- }
19
- </ul>
20
- </details>
21
- } @else if (headings.length) {
22
- <aside class="toc" aria-label="On this page">
23
- <p>On this page</p>
24
- <ul>
25
- @for (h of headings; track h.id) {
26
- <li [class]="h.level === 3 ? 'sub' : false">
27
- <a [href]="'#' + h.id">{{ h.text }}</a>
28
- </li>
29
- }
30
- </ul>
31
- </aside>
32
- }
10
+ <fragment>
11
+ @if (headings.length && inline) {
12
+ <details class="toc-inline">
13
+ <summary>On this page</summary>
14
+ <ul>
15
+ @for (h of headings; track h.id) {
16
+ <li [class]="h.level === 3 ? 'sub' : false">
17
+ <a [href]="'#' + h.id">{{ h.text }}</a>
18
+ </li>
19
+ }
20
+ </ul>
21
+ </details>
22
+ } @else if (headings.length) {
23
+ <aside class="toc" aria-label="On this page">
24
+ <p>On this page</p>
25
+ <ul>
26
+ @for (h of headings; track h.id) {
27
+ <li [class]="h.level === 3 ? 'sub' : false">
28
+ <a [href]="'#' + h.id">{{ h.text }}</a>
29
+ </li>
30
+ }
31
+ </ul>
32
+ </aside>
33
+ }
34
+ </fragment>
@@ -1,6 +1,6 @@
1
1
  {{--
2
2
  The site header (a public part, #360): the menu button, brand, section links, Learn status, search, social links and
3
- the theme toggle. Replace it with themeDocs({ components: { header } }) (#361).
3
+ the theme toggle, and before it the site's own (slot "end"). Replace it with themeDocs({ components: { header } }) (#361).
4
4
  --}}
5
5
  @import themeToggle from '../theme-toggle.tscl'
6
6
  @import pageTransitions from '../view-transitions.tscl'
@@ -55,6 +55,8 @@
55
55
  </button>
56
56
  <div id="more" class="more" popover>@for (link of config.social ?? []; track link.href) {<a [href]="link.href">{{ link.label }}</a>}</div>
57
57
  }
58
+ {{-- What a site adds (slot "end"; the layout's "header-end"), kept across fragment navigations too. --}}
59
+ <span class="persist" data-cl-persist="header-end"><slot name="end"></slot></span>
58
60
  {{-- Kept across fragment navigations: the same element, with its state. --}}
59
61
  <span class="persist" data-cl-persist="theme"><themeToggle /></span>
60
62
  @if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
@@ -14,4 +14,14 @@ export const ICONS: Record<GroupIcon, string[]> = {
14
14
  wrench: ['M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z'],
15
15
  rocket: ['M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z', 'm12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z'],
16
16
  file: ['M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5Z', 'M14 2v6h6'],
17
+ form: ['M12 20h-1a2 2 0 0 1-2-2a2 2 0 0 1-2 2H6m7-12h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7m-8 0H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1m1-4h1a2 2 0 0 1 2 2a2 2 0 0 1 2-2h1M9 6v12'],
18
+ pointer: ['M14 4.1L12 6M5.1 8l-2.9-.8M6 12l-1.9 2M7.2 2.2L8 5.1m1.037 4.59a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z'],
19
+ table: ['M12 3v18','M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2z','M3 9h18M3 15h18'],
20
+ panel: ['M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2z','M3 9h18M9 21V9'],
21
+ overlay: ['M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z','M10 4v4M2 8h20M6 4v4'],
22
+ menu: ['M4 5h16M4 12h16M4 19h16'],
23
+ chart: ['M3 3v16a2 2 0 0 0 2 2h16m-3-4V9m-5 8V5M8 17v-3'],
24
+ message: ['M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z'],
25
+ image: ['M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2z','M7 9a2 2 0 1 0 4 0a2 2 0 1 0 -4 0','m21 15l-3.086-3.086a2 2 0 0 0-2.828 0L6 21'],
26
+ grid: ['M4 3h5a1 1 0 0 1 1 1v5a1 1 0 0 1 -1 1h-5a1 1 0 0 1 -1 -1v-5a1 1 0 0 1 1 -1z','M15 3h5a1 1 0 0 1 1 1v5a1 1 0 0 1 -1 1h-5a1 1 0 0 1 -1 -1v-5a1 1 0 0 1 1 -1z','M15 14h5a1 1 0 0 1 1 1v5a1 1 0 0 1 -1 1h-5a1 1 0 0 1 -1 -1v-5a1 1 0 0 1 1 -1z','M4 14h5a1 1 0 0 1 1 1v5a1 1 0 0 1 -1 1h-5a1 1 0 0 1 -1 -1v-5a1 1 0 0 1 1 -1z'],
17
27
  }
@@ -138,6 +138,10 @@ a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outlin
138
138
  h1, h2 { line-height: 1.2; text-wrap: balance; }
139
139
  h1 { font-size: clamp(30px, 5vw, 40px); margin: 0 0 16px; letter-spacing: -0.01em; }
140
140
  h2 { font-size: 22px; margin: 40px 0 12px; }
141
+ /* More room above a heading than below it: it belongs to what follows. Right under an h2, an h3 sits closer. */
142
+ h3 { font-size: 18px; line-height: 1.3; margin: 32px 0 8px; }
143
+ h4 { font-size: 16px; line-height: 1.3; margin: 24px 0 8px; }
144
+ h2 + h3 { margin-top: 16px; }
141
145
  p, ul, ol { margin: 0 0 16px; }
142
146
  li { margin-bottom: 6px; }
143
147
 
@@ -226,7 +230,8 @@ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rul
226
230
  .search-dialog::backdrop { background: rgba(15, 23, 25, 0.45); }
227
231
  .search-box { @apply flex flex-col; max-height: inherit; }
228
232
  .search-box input { @apply border-0 border-b border-rule bg-transparent text-inherit; height: 52px; padding: 0 16px; font: inherit; font-size: 17px; }
229
- .search-box input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
233
+ /* One indicator: the bottom line turns accent (a ring would square off inside the dialog's rounded border). */
234
+ .search-box input:focus { outline: none; box-shadow: inset 0 -2px 0 var(--accent); }
230
235
  .search-status { @apply m-0 text-muted; padding: 8px 16px 0; font-size: 13px; }
231
236
  .search-status:empty { display: none; }
232
237
  #search-results { @apply list-none m-0 overflow-y-auto; padding: 8px; }
@@ -295,6 +300,9 @@ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rul
295
300
  details.custom-block { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; margin: 20px 0; }
296
301
  details.custom-block > summary { cursor: pointer; font-weight: 600; }
297
302
  details.custom-block[open] > summary { margin-bottom: 8px; }
303
+ /* {since=…} / {deprecated=…} badges from @clarusjs/content: when a feature came, and when it goes. */
304
+ .version { display: inline-block; vertical-align: middle; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 1.6; white-space: nowrap; color: var(--accent); background: var(--accent-soft); }
305
+ .version[data-version='deprecated'], .version[data-version='removed'] { color: var(--muted); background: var(--surface); border: 1px solid var(--rule); }
298
306
 
299
307
  /* Highlighted code from Markdown (Shiki, build time). Tokens carry both themes as variables; the page picks one. */
300
308
  .code-block { position: relative; margin: 0 0 20px; }
@@ -1,6 +1,7 @@
1
1
  {{-- Light, dark or the system setting; remembered in localStorage and applied as data-theme on <html>. --}}
2
2
 
3
3
  <script>
4
+ import { browser, onDispose } from 'clarusjs/runtime'
4
5
  const order = ['system', 'light', 'dark']
5
6
  let mode = state('system')
6
7
  function apply() {
@@ -14,13 +15,22 @@
14
15
  } catch {}
15
16
  apply()
16
17
  }
17
- // In the browser, start from the saved choice (the server always renders "system").
18
- if (typeof document !== 'undefined') {
18
+ // In the browser, start from the saved choice (the server always renders "system"), and follow it when another
19
+ // tab (or a page around this one) changes it.
20
+ const saved = () => {
19
21
  try {
20
22
  mode = localStorage.getItem('clarusjs-theme') || 'system'
21
23
  } catch {}
22
24
  apply()
23
25
  }
26
+ if (browser) {
27
+ saved()
28
+ const changed = (e) => {
29
+ if (!e.key || e.key === 'clarusjs-theme') saved()
30
+ }
31
+ addEventListener('storage', changed)
32
+ onDispose(() => removeEventListener('storage', changed))
33
+ }
24
34
  </script>
25
35
 
26
36
  <button
package/src/theme.css CHANGED
@@ -574,6 +574,19 @@ h2 {
574
574
  font-size: 22px;
575
575
  margin: 40px 0 12px;
576
576
  }
577
+ h3 {
578
+ font-size: 18px;
579
+ line-height: 1.3;
580
+ margin: 32px 0 8px;
581
+ }
582
+ h4 {
583
+ font-size: 16px;
584
+ line-height: 1.3;
585
+ margin: 24px 0 8px;
586
+ }
587
+ h2 + h3 {
588
+ margin-top: 16px;
589
+ }
577
590
  p, ul, ol {
578
591
  margin: 0 0 16px;
579
592
  }
@@ -884,8 +897,8 @@ th, td {
884
897
  font-size: 17px;
885
898
  }
886
899
  .search-box input:focus {
887
- outline: 2px solid var(--accent);
888
- outline-offset: -2px;
900
+ outline: none;
901
+ box-shadow: inset 0 -2px 0 var(--accent);
889
902
  }
890
903
  .search-status {
891
904
  margin: 0px;
@@ -1125,6 +1138,24 @@ details.custom-block > summary {
1125
1138
  details.custom-block[open] > summary {
1126
1139
  margin-bottom: 8px;
1127
1140
  }
1141
+ .version {
1142
+ display: inline-block;
1143
+ vertical-align: middle;
1144
+ margin-left: 6px;
1145
+ padding: 1px 8px;
1146
+ border-radius: 999px;
1147
+ font-size: 12px;
1148
+ font-weight: 500;
1149
+ line-height: 1.6;
1150
+ white-space: nowrap;
1151
+ color: var(--accent);
1152
+ background: var(--accent-soft);
1153
+ }
1154
+ .version[data-version='deprecated'], .version[data-version='removed'] {
1155
+ color: var(--muted);
1156
+ background: var(--surface);
1157
+ border: 1px solid var(--rule);
1158
+ }
1128
1159
  .code-block {
1129
1160
  position: relative;
1130
1161
  margin: 0 0 20px;
package/src/vite.d.ts CHANGED
@@ -41,7 +41,8 @@ export declare function themeDocs(options?: Options): import('vite').Plugin;
41
41
  /**
42
42
  * Every page under `dir` with its source `file`, its last commit time (`updated`, from one `git log`) and its sidebar
43
43
  * entry: frontmatter `title` (else the first `# ` heading, or a .tscl page's `[title]="'…'"`, else the file name),
44
- * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false` and
44
+ * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false`, a .tscl page's
45
+ * `<meta name="robots" content="noindex">`, and
45
46
  * dynamic routes (`[step]`). Files or folders starting with `_` aren't pages.
46
47
  * @param {string} dir
47
48
  * @returns {import('./nav.ts').PageInfo[]}
package/src/vite.js CHANGED
@@ -181,7 +181,8 @@ export function themeDocs(options = {}) {
181
181
  /**
182
182
  * Every page under `dir` with its source `file`, its last commit time (`updated`, from one `git log`) and its sidebar
183
183
  * entry: frontmatter `title` (else the first `# ` heading, or a .tscl page's `[title]="'…'"`, else the file name),
184
- * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false` and
184
+ * `group` (else the subfolder inside its section), `order`. `hidden` (not in the sidebar): `sidebar: false`, a .tscl page's
185
+ * `<meta name="robots" content="noindex">`, and
185
186
  * dynamic routes (`[step]`). Files or folders starting with `_` aren't pages.
186
187
  * @param {string} dir
187
188
  * @returns {import('./nav.ts').PageInfo[]}
@@ -218,7 +219,9 @@ export function readPages(dir) {
218
219
  }
219
220
  const updated = dates.get(resolve(dir, file))
220
221
  if (updated !== undefined) page.updated = updated
221
- if (data.sidebar === 'false' || parts.some((part) => part.startsWith('['))) page.hidden = true
222
+ // Not in the sidebar: asked not to be, a dynamic route, or a .tscl page kept out of search engines (noindex; a Markdown page says sidebar: false).
223
+ const noindex = m[2] === 'tscl' && [...text.matchAll(/<meta\b[^>]*>/gi)].some(([tag]) => /\bname=["']robots["']/i.test(tag) && /\bcontent=["'][^"']*\bnoindex\b/i.test(tag))
224
+ if (data.sidebar === 'false' || noindex || parts.some((part) => part.startsWith('['))) page.hidden = true
222
225
  pages.push(page)
223
226
  }
224
227
  return pages