@clarusjs/theme-docs 0.1.0 → 0.1.1

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.0",
3
+ "version": "0.1.1",
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.8.0"
19
+ "clarusjs": "^0.8.1"
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.8.0",
42
+ "clarusjs": "^0.8.1",
43
43
  "typescript": "^7.0.2",
44
44
  "vitest": "^5.1.1",
45
45
  "vite": "^8.3.8"
package/src/layout.tscl CHANGED
@@ -5,6 +5,7 @@
5
5
  Slots: sidebar-top, sidebar-bottom, content-top, content-bottom, footer.
6
6
  --}}
7
7
  @import themeToggle from './theme-toggle.tscl'
8
+ @import pageTransitions from './view-transitions.tscl'
8
9
  @import siteSearch from './search.tscl'
9
10
  @import pageHead from './page-head.tscl'
10
11
  @import learnStatus from './learn-status.tscl'
@@ -60,6 +61,7 @@
60
61
  }
61
62
  {{-- Kept across fragment navigations: the same element, with its state. --}}
62
63
  <span class="persist" data-cl-persist="theme"><themeToggle /></span>
64
+ @if (config.viewTransitions) {<span class="persist" data-cl-persist="view-transitions"><pageTransitions /></span>}
63
65
  </div>
64
66
  </header>
65
67
  @if (sectionKey(config.sections, path)) {
package/src/nav.ts CHANGED
@@ -31,6 +31,11 @@ export type ThemeConfig = {
31
31
  learn?: { section: string; progress: string }
32
32
  /** A search button (and Ctrl/⌘K, /) in the header; the index comes from the themeDocs() Vite plugin. */
33
33
  search?: boolean
34
+ /**
35
+ * Page changes animate as view transitions where the browser has them (a cross-fade; `::view-transition-*` rules in
36
+ * the site's CSS change it). Needs fragment navigation or client routes; no animation with reduced motion.
37
+ */
38
+ viewTransitions?: boolean
34
39
  /** The site footer's text. */
35
40
  footer?: string
36
41
  }
package/src/search.tscl CHANGED
@@ -4,6 +4,7 @@
4
4
  themeDocs() writes at build time; a query fetches only the files it needs.
5
5
  --}}
6
6
  <script>
7
+ import { navigate } from 'clarusjs/navigation'
7
8
  import { search } from './search.js'
8
9
  let query = state('')
9
10
  let results = state([])
@@ -37,7 +38,7 @@
37
38
  function key(event) {
38
39
  if (event.key === 'ArrowDown') { event.preventDefault(); move(1) }
39
40
  else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1) }
40
- else if (event.key === 'Enter' && results.length) { event.preventDefault(); document.querySelector('#search-result-' + active + ' a')?.click() }
41
+ else if (event.key === 'Enter' && results.length) { event.preventDefault(); dialog().close(); navigate(results[active].u) }
41
42
  // One Escape closes (a search field would only clear itself first).
42
43
  else if (event.key === 'Escape') { event.preventDefault(); dialog().close() }
43
44
  }
package/src/theme.css CHANGED
@@ -1,6 +1,7 @@
1
1
  /* @clarusjs/theme-docs: a quiet reading layout. Every colour, font and size is a custom property on :root (tokens). */
2
2
  :root {
3
3
  --header-height: 64px;
4
+ --page-width: 1440px; /* the header, sidebar, content and contents columns together */
4
5
  --sidebar-width: 260px;
5
6
  --toc-width: 220px;
6
7
  --bg: #fbfcfc;
@@ -80,7 +81,10 @@ a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outlin
80
81
  align-items: center;
81
82
  gap: 12px 24px;
82
83
  background: var(--bg);
83
- padding: 14px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
84
+ /* Its content lines up with the page below (.docs, at most --page-width wide), not the window's edges. */
85
+ box-sizing: border-box;
86
+ min-height: var(--header-height); /* what the sticky sidebar and contents sit under */
87
+ padding: 0 max(16px, env(safe-area-inset-right, 0px), calc((100% - var(--page-width)) / 2 + 16px)) 0 max(16px, env(safe-area-inset-left, 0px), calc((100% - var(--page-width)) / 2 + 16px));
84
88
  border-bottom: 1px solid var(--rule);
85
89
  }
86
90
  .brand { display: inline-flex; align-items: center; gap: 10px; color: var(--fg); text-decoration: none; font-weight: 650; font-size: 18px; }
@@ -137,7 +141,7 @@ pre code { background: none; padding: 0; font-size: 14px; line-height: 1.55; }
137
141
  .site-header nav { align-items: center; }
138
142
 
139
143
  /* Docs pages: sidebar, content and "On this page" (from 1280px a column, below that a box above the content). */
140
- .docs { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width); max-width: 1440px; margin: 0 auto; }
144
+ .docs { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width); max-width: var(--page-width); margin: 0 auto; }
141
145
  .docs .content { margin: 0; max-width: 760px; min-width: 0; }
142
146
  .sidebar { position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto; padding: 28px 16px 40px max(16px, env(safe-area-inset-left, 0px)); border-right: 1px solid var(--rule); }
143
147
  .sidebar .group { margin: 20px 0 6px; font-size: 13px; font-weight: 650; color: var(--fg); }
@@ -195,7 +199,8 @@ th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rul
195
199
  .search-text { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
196
200
 
197
201
  /* The sidebar is a popover (so it can be a drawer on small screens): shown in place from 1024px. */
198
- .sidebar[popover] { display: block; position: sticky; top: var(--header-height); inset: auto; width: auto; height: auto; max-height: calc(100vh - var(--header-height)); margin: 0; border: 0; border-right: 1px solid var(--rule); background: transparent; color: inherit; overflow-y: auto; }
202
+ /* inset first: it would reset top. */
203
+ .sidebar[popover] { display: block; position: sticky; inset: auto; top: var(--header-height); width: auto; height: auto; max-height: calc(100vh - var(--header-height)); margin: 0; border: 0; border-right: 1px solid var(--rule); background: transparent; color: inherit; overflow-y: auto; }
199
204
  .sidebar-head, .sidebar-links { display: none; }
200
205
 
201
206
  /* On this page */
@@ -338,3 +343,17 @@ details.custom-block[open] > summary { margin-bottom: 8px; }
338
343
  .badges em { margin-left: auto; font-style: normal; font-size: 13px; font-weight: 700; }
339
344
  .progress-lessons li[data-status="done"] a::after { content: ' ✓'; color: var(--ok); }
340
345
  .progress-reset { margin-top: 16px; min-height: 44px; padding: 0 16px; border: 1px solid var(--bad); border-radius: 10px; background: transparent; color: var(--bad); font: inherit; font-weight: 600; cursor: pointer; }
346
+
347
+ /* While a page change runs (fragments or the client router set data-cl-navigating on <html>): a thin bar at the top.
348
+ Shown after a short delay, so fast swaps don't flash it. */
349
+ html[data-cl-navigating]::before {
350
+ content: ''; position: fixed; inset: 0 auto auto 0; z-index: 20; height: 3px; width: 100%; background: var(--accent);
351
+ transform-origin: left; animation: cl-navigating 8s cubic-bezier(0.1, 0.7, 0.2, 1) 150ms both;
352
+ }
353
+ @keyframes cl-navigating { from { transform: scaleX(0); } to { transform: scaleX(0.9); } }
354
+ @media (prefers-reduced-motion: reduce) { html[data-cl-navigating]::before { animation: none; transform: scaleX(1); opacity: 0.6; } }
355
+
356
+ /* View transitions (config.viewTransitions): the default cross-fade, none with reduced motion. */
357
+ @media (prefers-reduced-motion: reduce) {
358
+ ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none; }
359
+ }
@@ -0,0 +1,7 @@
1
+ {{-- Turns on view transitions for page changes (config.viewTransitions): no markup of its own, kept across swaps. --}}
2
+ <script>
3
+ import { viewTransitions } from 'clarusjs/navigation'
4
+ viewTransitions()
5
+ </script>
6
+
7
+ <span hidden></span>