@opentf/afw-docs 0.0.0-stage → 0.31.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -2
  3. package/build/blog-posts-plugin.js +154 -0
  4. package/build/docs-nav-plugin.js +200 -0
  5. package/build/feed.js +176 -0
  6. package/build/frontmatter.js +45 -0
  7. package/build/host.js +54 -0
  8. package/build/index.js +13 -0
  9. package/build/last-updated-plugin.js +107 -0
  10. package/build/last-updated.js +40 -0
  11. package/build/llms.js +176 -0
  12. package/build/publish.js +29 -0
  13. package/build/reading-time.js +16 -0
  14. package/build/search.js +27 -0
  15. package/components/BlogLayout.jsx +104 -0
  16. package/components/Breadcrumbs.jsx +71 -0
  17. package/components/Callout.jsx +29 -0
  18. package/components/Card.jsx +21 -0
  19. package/components/Cards.jsx +11 -0
  20. package/components/CodeBlock.jsx +39 -0
  21. package/components/DocsLayout.jsx +106 -0
  22. package/components/FeedLinks.jsx +47 -0
  23. package/components/Footer.jsx +25 -0
  24. package/components/LastUpdated.jsx +20 -0
  25. package/components/NavIcon.jsx +34 -0
  26. package/components/Navbar.jsx +64 -0
  27. package/components/NavbarLink.jsx +40 -0
  28. package/components/Pagination.jsx +49 -0
  29. package/components/PostBanner.jsx +25 -0
  30. package/components/PostCard.jsx +24 -0
  31. package/components/PostList.jsx +25 -0
  32. package/components/PostMeta.jsx +37 -0
  33. package/components/ReadingTime.jsx +6 -0
  34. package/components/Search.jsx +191 -0
  35. package/components/SearchTrigger.jsx +32 -0
  36. package/components/Sidebar.jsx +199 -0
  37. package/components/SidebarNode.jsx +143 -0
  38. package/components/SidebarToggle.jsx +47 -0
  39. package/components/Steps.jsx +14 -0
  40. package/components/Table.jsx +10 -0
  41. package/components/Tabs.jsx +77 -0
  42. package/components/ThemeToggle.jsx +164 -0
  43. package/components/Toc.jsx +106 -0
  44. package/components/Tooltip.jsx +19 -0
  45. package/components/format.js +21 -0
  46. package/components/post-dates.js +21 -0
  47. package/components/sidebar-collapse.js +38 -0
  48. package/config.js +77 -0
  49. package/index.js +69 -0
  50. package/nav-virtual.js +18 -0
  51. package/package.json +79 -4
  52. package/posts-virtual.js +17 -0
  53. package/search.js +285 -0
  54. package/theme/index.css +1843 -0
  55. package/types/config.d.ts +39 -0
  56. package/types/index.d.ts +70 -0
  57. package/types/nav.d.ts +9 -0
  58. package/types/posts.d.ts +17 -0
  59. package/types/search.d.ts +28 -0
  60. package/types/updated.d.ts +4 -0
  61. package/updated-virtual.js +10 -0
@@ -0,0 +1,49 @@
1
+ // Prev / next page links, derived from a depth-first flatten of the nav tree.
2
+
3
+ import { Link, router } from "@opentf/afw";
4
+
5
+ export default function Pagination(props) {
6
+ const nav = props.nav || [];
7
+
8
+ const flat = [];
9
+ const walk = (items) => {
10
+ for (const it of items) {
11
+ if (it.path) flat.push(it);
12
+ if (it.items) walk(it.items);
13
+ }
14
+ };
15
+ walk(nav);
16
+
17
+ const adjacent = (path) => {
18
+ const i = flat.findIndex((x) => x.path === path);
19
+ return {
20
+ prev: i > 0 ? flat[i - 1] : null,
21
+ next: i >= 0 && i < flat.length - 1 ? flat[i + 1] : null,
22
+ };
23
+ };
24
+
25
+ // A single reactive signal (not a `{() => …}` thunk): `pos` is in scope for the
26
+ // hoisted branch builders, and recomputes on `router.pathname`.
27
+ const pos = $derived(adjacent(router.pathname));
28
+
29
+ return (
30
+ <nav class="afwd-pagination" aria-label="Pagination">
31
+ {pos.prev ? (
32
+ <Link href={pos.prev?.path} class="afwd-page-link afwd-page-prev">
33
+ <span class="afwd-page-dir">← Previous</span>
34
+ <span class="afwd-page-title">{pos.prev?.title}</span>
35
+ </Link>
36
+ ) : (
37
+ <span class="afwd-page-spacer" />
38
+ )}
39
+ {pos.next ? (
40
+ <Link href={pos.next?.path} class="afwd-page-link afwd-page-next">
41
+ <span class="afwd-page-dir">Next →</span>
42
+ <span class="afwd-page-title">{pos.next?.title}</span>
43
+ </Link>
44
+ ) : (
45
+ <span class="afwd-page-spacer" />
46
+ )}
47
+ </nav>
48
+ );
49
+ }
@@ -0,0 +1,25 @@
1
+ // A blog post's header: title, optional description, and the metadata row. Rendered
2
+ // by BlogLayout above the post's prose body, driven by the post record so the MDX
3
+ // file stays pure content (no hand-written title/date in the body).
4
+ import PostMeta from "./PostMeta.jsx";
5
+
6
+ export default function PostBanner(props) {
7
+ const post = props.post || props;
8
+ return (
9
+ <header class="afwd-post-banner">
10
+ {post.cover ? (
11
+ <img class="afwd-post-cover" src={post.cover} alt="" />
12
+ ) : null}
13
+ <h1 class="afwd-post-title">{post.title}</h1>
14
+ {post.description ? <p class="afwd-post-desc">{post.description}</p> : null}
15
+ <PostMeta post={post} showUpdated={props.showUpdated} />
16
+ {post.tags && post.tags.length ? (
17
+ <div class="afwd-post-tags">
18
+ {post.tags.map((tag) => (
19
+ <span class="afwd-post-tag">{tag}</span>
20
+ ))}
21
+ </div>
22
+ ) : null}
23
+ </header>
24
+ );
25
+ }
@@ -0,0 +1,24 @@
1
+ // One post in the blog index: a link to the post with its title, excerpt and meta row. `featured` renders it as the index hero.
2
+ import { Link } from "@opentf/afw";
3
+ import PostMeta from "./PostMeta.jsx";
4
+
5
+ export default function PostCard(props) {
6
+ const post = props.post;
7
+ return (
8
+ <Link
9
+ href={post.path}
10
+ class={"afwd-post-card" + (post.cover ? " afwd-has-cover" : "") + (props.featured ? " afwd-post-card-featured" : "")}
11
+ >
12
+ {post.cover ? (
13
+ // Decorative here: the title below already names the link, so a screen reader
14
+ // would otherwise read it twice.
15
+ <img class="afwd-post-card-cover" src={post.cover} alt="" loading={props.featured ? "eager" : "lazy"} />
16
+ ) : null}
17
+ <div class="afwd-post-card-body">
18
+ <h2 class="afwd-post-card-title">{post.title}</h2>
19
+ {post.description ? <p class="afwd-post-card-desc">{post.description}</p> : null}
20
+ <PostMeta post={post} />
21
+ </div>
22
+ </Link>
23
+ );
24
+ }
@@ -0,0 +1,25 @@
1
+ // The blog index listing: renders a PostCard per post. Pass the list from
2
+ // `@opentf/afw-docs/posts`:
3
+ //
4
+ // import { posts } from "@opentf/afw-docs/posts";
5
+ // <PostList posts={posts} />
6
+ import PostCard from "./PostCard.jsx";
7
+
8
+ // The newest post leads as a full-width hero card and the rest follow as compact rows.
9
+ // `featured={false}` lists every post the same way.
10
+ export default function PostList(props) {
11
+ const posts = props.posts || [];
12
+ const featured = props.featured !== false && posts.length > 0;
13
+ const rest = featured ? posts.slice(1) : posts;
14
+ return (
15
+ <div class="afwd-post-list">
16
+ {posts.length ? null : <p class="afwd-post-empty">No posts yet.</p>}
17
+ {featured ? <PostCard post={posts[0]} featured /> : null}
18
+ {rest.length ? (
19
+ <div class="afwd-post-rows">
20
+ {rest.map((post) => <PostCard post={post} />)}
21
+ </div>
22
+ ) : null}
23
+ </div>
24
+ );
25
+ }
@@ -0,0 +1,37 @@
1
+ // A post's metadata row: date · author · reading time. Pass a post record (from
2
+ // `@opentf/afw-docs/posts`) as `post`, or the fields directly. Missing fields are
3
+ // omitted. Used in both the post banner and the index cards. `showUpdated` (the banner)
4
+ // adds the frontmatter `updated` date when it is a later day than `date`. A draft or
5
+ // scheduled post, listed only by the dev server, is marked as such.
6
+ import ReadingTime from "./ReadingTime.jsx";
7
+ import { formatDate } from "./format.js";
8
+ import { editedAfterPublish } from "./post-dates.js";
9
+
10
+ export default function PostMeta(props) {
11
+ const post = props.post || props;
12
+ return (
13
+ <div class="afwd-post-meta">
14
+ {post.author ? (
15
+ <span class="afwd-post-author">
16
+ {post.authorAvatar ? (
17
+ <img class="afwd-post-avatar" src={post.authorAvatar} alt="" loading="lazy" />
18
+ ) : null}
19
+ <span class="afwd-post-author-name">{post.author}</span>
20
+ {post.authorRole ? <span class="afwd-post-author-role">{post.authorRole}</span> : null}
21
+ </span>
22
+ ) : null}
23
+ {post.date ? (
24
+ <time class="afwd-post-date" datetime={String(post.date)}>
25
+ {formatDate(post.date)}
26
+ </time>
27
+ ) : null}
28
+ {props.showUpdated && editedAfterPublish(post.updated, post.date) ? (
29
+ <span class="afwd-post-updated">
30
+ Updated <time datetime={String(post.updated)}>{formatDate(post.updated)}</time>
31
+ </span>
32
+ ) : null}
33
+ {post.readingTime ? <ReadingTime minutes={post.readingTime} /> : null}
34
+ {post.draft ? <span class="afwd-post-draft">Draft</span> : null}
35
+ </div>
36
+ );
37
+ }
@@ -0,0 +1,6 @@
1
+ // Reading-time label, e.g. "4 min read". `minutes` is precomputed at build time by
2
+ // the blog posts plugin (see build/reading-time.js).
3
+ export default function ReadingTime(props) {
4
+ const minutes = props.minutes ?? 1;
5
+ return <span class="afwd-reading-time">{minutes} min read</span>;
6
+ }
@@ -0,0 +1,191 @@
1
+ // AFW Search-backed modal. The navbar's `SearchTrigger` and the global
2
+ // ⌘K / Ctrl+K shortcut open it via `window.__afwOpenSearch`, which this component
3
+ // installs on mount. The static index is generated after a release build (the `siteOutputPlugin`
4
+ // output hook, with `docs.search.provider === "afw"`) lives at `/_search/`; the reader is lazy so
5
+ // pages without a search never fetch its index.
6
+ //
7
+ // Note: results only exist against a built site (`dist/`). In dev there is no index,
8
+ // so the modal opens but reports no results — expected.
9
+ import { onCleanup, onMount, router, Portal } from "@opentf/afw";
10
+ import { createSearch, excerptParts } from "../search.js";
11
+
12
+ const search = createSearch({ base: "/_search/" });
13
+
14
+ export default function Search() {
15
+ let open = $state(false);
16
+ let query = $state("");
17
+ let results = $state([]);
18
+ let active = $state(0);
19
+ let loading = $state(false);
20
+ let error = $state("");
21
+ let controller;
22
+ const inputRef = $ref();
23
+
24
+ let timer;
25
+ let token = 0;
26
+
27
+ async function runSearch(q) {
28
+ const mine = ++token;
29
+ controller?.abort();
30
+ controller = new AbortController();
31
+ error = "";
32
+ if (!q.trim()) {
33
+ results = [];
34
+ loading = false;
35
+ return;
36
+ }
37
+ loading = true;
38
+ try {
39
+ const found = await search.query(q, { limit: 10, signal: controller.signal });
40
+ if (mine !== token) return; // a newer query superseded this one
41
+ results = found.results;
42
+ active = 0;
43
+ } catch (e) {
44
+ if (mine === token && e?.name !== "AbortError") {
45
+ results = [];
46
+ error = "Search is unavailable. Please try again.";
47
+ }
48
+ } finally {
49
+ if (mine === token) loading = false;
50
+ }
51
+ }
52
+
53
+ $effect(() => {
54
+ const q = query;
55
+ clearTimeout(timer);
56
+ timer = setTimeout(() => runSearch(q), 150);
57
+ });
58
+
59
+ const focusInput = () => {
60
+ const el = inputRef;
61
+ if (el && typeof requestAnimationFrame !== "undefined") requestAnimationFrame(() => el.focus());
62
+ };
63
+ const openModal = () => {
64
+ open = true;
65
+ focusInput();
66
+ };
67
+ const close = () => {
68
+ ++token;
69
+ controller?.abort();
70
+ clearTimeout(timer);
71
+ loading = false;
72
+ error = "";
73
+ open = false;
74
+ query = "";
75
+ results = [];
76
+ active = 0;
77
+ };
78
+ const go = (url) => {
79
+ close();
80
+ router.push(url);
81
+ };
82
+
83
+ onMount(() => {
84
+ if (typeof window === "undefined") return;
85
+ window.__afwOpenSearch = openModal;
86
+ const onKey = (e) => {
87
+ const k = e.key;
88
+ if ((e.metaKey || e.ctrlKey) && k.toLowerCase() === "k") {
89
+ e.preventDefault();
90
+ openModal();
91
+ return;
92
+ }
93
+ if (!open) return;
94
+ if (k === "Escape") close();
95
+ else if (k === "ArrowDown") {
96
+ e.preventDefault();
97
+ active = results.length ? (active + 1) % results.length : 0;
98
+ } else if (k === "ArrowUp") {
99
+ e.preventDefault();
100
+ active = results.length ? (active - 1 + results.length) % results.length : 0;
101
+ } else if (k === "Enter" && results[active]) {
102
+ e.preventDefault();
103
+ go(results[active].url);
104
+ }
105
+ };
106
+ window.addEventListener("keydown", onKey);
107
+ return () => {
108
+ window.removeEventListener("keydown", onKey);
109
+ if (window.__afwOpenSearch === openModal) delete window.__afwOpenSearch;
110
+ };
111
+ });
112
+
113
+ onCleanup(() => {
114
+ ++token;
115
+ clearTimeout(timer);
116
+ controller?.abort();
117
+ });
118
+
119
+ // Portal to <body>: the navbar (our render parent) sets `backdrop-filter`, which
120
+ // establishes a containing block for fixed-position descendants — so without this the
121
+ // `position: fixed` overlay would collapse to the navbar's box instead of the viewport.
122
+ return (
123
+ <Portal>
124
+ <div
125
+ class={open ? "afwd-search-modal is-open" : "afwd-search-modal"}
126
+ onclick={(e) => {
127
+ if (e.target === e.currentTarget) close();
128
+ }}
129
+ >
130
+ <div class="afwd-search-panel" role="dialog" aria-label="Search docs">
131
+ <div class="afwd-search-field">
132
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
133
+ <circle cx="11" cy="11" r="7" />
134
+ <line x1="21" y1="21" x2="16.65" y2="16.65" stroke-linecap="round" />
135
+ </svg>
136
+ <input
137
+ ref={inputRef}
138
+ class="afwd-search-input-field"
139
+ type="search"
140
+ placeholder="Search docs…"
141
+ aria-label="Search docs"
142
+ value={query}
143
+ oninput={(e) => (query = e.target.value)}
144
+ />
145
+ </div>
146
+ <ul class="afwd-search-results">
147
+ {results.map((r, i) => (
148
+ <li>
149
+ <a
150
+ href={r.url}
151
+ class={i === active ? "afwd-search-result is-active" : "afwd-search-result"}
152
+ onclick={(e) => {
153
+ e.preventDefault();
154
+ go(r.url);
155
+ }}
156
+ onmouseenter={() => (active = i)}
157
+ >
158
+ {r.meta?.breadcrumb ? <span class="afwd-search-result-crumb">{r.meta.breadcrumb}</span> : null}
159
+ <span class="afwd-search-result-title">{r.title}</span>
160
+ {r.section ? <span class="afwd-search-result-section">{r.section}</span> : null}
161
+ <span class="afwd-search-result-excerpt">
162
+ {excerptParts(r.excerpt, r.highlights).map((part) => <span>{part.match ? <mark>{part.text}</mark> : part.text}</span>)}
163
+ </span>
164
+ </a>
165
+ </li>
166
+ ))}
167
+ </ul>
168
+ {error ? <div class="afwd-search-empty" role="status">{error}</div> : null}
169
+ {query.trim() && !loading && !error && results.length === 0 ? (
170
+ <div class="afwd-search-empty">No results for “{query}”.</div>
171
+ ) : null}
172
+ <div class="afwd-search-hint">
173
+ <span class="afwd-search-hint-item">
174
+ <kbd>↑</kbd>
175
+ <kbd>↓</kbd>
176
+ navigate
177
+ </span>
178
+ <span class="afwd-search-hint-item">
179
+ <kbd>↵</kbd>
180
+ select
181
+ </span>
182
+ <span class="afwd-search-hint-item">
183
+ <kbd>esc</kbd>
184
+ close
185
+ </span>
186
+ </div>
187
+ </div>
188
+ </div>
189
+ </Portal>
190
+ );
191
+ }
@@ -0,0 +1,32 @@
1
+ // Search box trigger in the navbar. Calls the global opener that the AFW Search-backed
2
+ // <Search> modal installs on `window` (the ⌘K / Ctrl+K shortcut opens it too). Shows
3
+ // the shortcut as a hint; the modifier resolves to ⌘ on Apple platforms, Ctrl
4
+ // elsewhere, on mount.
5
+
6
+ import { onMount } from "@opentf/afw";
7
+
8
+ export default function SearchTrigger() {
9
+ let mod = $state("Ctrl");
10
+
11
+ onMount(() => {
12
+ const ua = navigator.platform || navigator.userAgent || "";
13
+ if (/Mac|iPhone|iPad|iPod/.test(ua)) mod = "⌘";
14
+ });
15
+
16
+ const open = () => {
17
+ if (typeof window !== "undefined" && typeof window.__afwOpenSearch === "function") {
18
+ window.__afwOpenSearch();
19
+ }
20
+ };
21
+
22
+ return (
23
+ <button class="afwd-search-trigger" onclick={open} aria-label="Search docs">
24
+ <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
25
+ <circle cx="11" cy="11" r="7" />
26
+ <line x1="21" y1="21" x2="16.65" y2="16.65" stroke-linecap="round" />
27
+ </svg>
28
+ <span class="afwd-search-label">Search</span>
29
+ <kbd class="afwd-search-kbd">{() => `${mod} K`}</kbd>
30
+ </button>
31
+ );
32
+ }
@@ -0,0 +1,199 @@
1
+ // Documentation sidebar — renders the build-time nav tree (from
2
+ // `@opentf/afw-docs/nav`). Static content (crawlable with JS off); the active link
3
+ // updates reactively in SidebarNode.
4
+ //
5
+ // On desktop it is the sticky left column of the docs grid. On mobile (< 768px) the
6
+ // same element becomes an off-canvas drawer: hidden off-screen, slid in over a
7
+ // backdrop. The drawer is opened by the navbar hamburger, which lives in a different
8
+ // component (and, on the website, a different layout), so the two are coupled the same
9
+ // way Search/SearchTrigger are — through a global toggle installed here:
10
+ //
11
+ // • `window.__afwToggleSidebar()` / `__afwCloseSidebar()` — called by the burger.
12
+ // • `document.documentElement[data-afw-has-sidebar]` — set while a Sidebar is
13
+ // mounted, so the burger shows only on pages that actually have one.
14
+ // • a `afw:sidebar` CustomEvent (`{ open }`) — lets the burger mirror `aria-expanded`.
15
+ //
16
+ // The drawer closes on navigation, Escape, backdrop click, or a viewport resize up to
17
+ // the desktop breakpoint, and locks body scroll while open.
18
+ //
19
+ // Above the tree sits a single icon button that collapses (or re-expands) every group at
20
+ // once — it drives the nodes through the shared `collapseAll` signal, since they are
21
+ // rendered recursively by SidebarNode.
22
+
23
+ import { onMount, router } from "@opentf/afw";
24
+
25
+ import SidebarNode from "./SidebarNode.jsx";
26
+ import NavbarLink from "./NavbarLink.jsx";
27
+ import { collapseAll } from "./sidebar-collapse.js";
28
+
29
+ const DESKTOP_QUERY = "(min-width: 768px)";
30
+
31
+ // How many Sidebars are mounted right now. On SPA navigation a new section's Sidebar can
32
+ // mount *before* the old one unmounts, so the burger's `data-afw-has-sidebar` flag must
33
+ // be reference-counted — otherwise the departing instance's cleanup would clear the flag
34
+ // the arriving instance just set, and the burger would vanish after navigating.
35
+ let liveSidebars = 0;
36
+
37
+ export default function Sidebar(props) {
38
+ const nav = props.nav || [];
39
+ // Top-level site links (config.nav). On desktop they live in the navbar; on mobile the
40
+ // navbar hides them and the drawer surfaces them above the section tree, so the whole
41
+ // nav is reachable from one place.
42
+ const navLinks = (props.config && props.config.nav) || [];
43
+ // The collapse-all button is only meaningful when the tree actually has groups.
44
+ const hasGroups = nav.some((item) => item.items && item.items.length > 0);
45
+ let open = $state(false);
46
+ const asideRef = $ref();
47
+
48
+ const close = () => (open = false);
49
+ // Stable per-instance toggle so cleanup can tell whether the global still points at us.
50
+ const toggle = () => (open = !open);
51
+
52
+ onMount(() => {
53
+ const root = document.documentElement;
54
+ liveSidebars += 1;
55
+ root.setAttribute("data-afw-has-sidebar", "");
56
+
57
+ // The burger (navbar) drives the drawer through these globals — same decoupling as
58
+ // the Search modal's `__afwOpenSearch`. The latest-mounted Sidebar owns them.
59
+ window.__afwToggleSidebar = toggle;
60
+ window.__afwCloseSidebar = close;
61
+
62
+ const onKey = (e) => e.key === "Escape" && close();
63
+ window.addEventListener("keydown", onKey);
64
+
65
+ // If the viewport grows to desktop while the drawer is open, drop the drawer state
66
+ // (CSS turns the element back into the sticky column; this releases the scroll lock
67
+ // and resyncs the burger).
68
+ const mql = window.matchMedia(DESKTOP_QUERY);
69
+ const onDesktop = (e) => e.matches && close();
70
+ mql.addEventListener?.("change", onDesktop);
71
+
72
+ return () => {
73
+ window.removeEventListener("keydown", onKey);
74
+ mql.removeEventListener?.("change", onDesktop);
75
+ document.body.style.removeProperty("overflow");
76
+ root.removeAttribute("data-afw-sidebar-open");
77
+ // Only drop the flag/globals if we're the last Sidebar and still the owner — an
78
+ // arriving instance may already have taken over during navigation.
79
+ liveSidebars -= 1;
80
+ if (liveSidebars <= 0) {
81
+ liveSidebars = 0;
82
+ root.removeAttribute("data-afw-has-sidebar");
83
+ }
84
+ if (window.__afwToggleSidebar === toggle) delete window.__afwToggleSidebar;
85
+ if (window.__afwCloseSidebar === close) delete window.__afwCloseSidebar;
86
+ };
87
+ });
88
+
89
+ // Reflect open state: lock body scroll, mark the root (for styling), and notify the
90
+ // burger so it can mirror `aria-expanded`. Reading `open` (not writing it) keeps this
91
+ // effect free of the route/resize effects.
92
+ $effect(() => {
93
+ const isOpen = open;
94
+ if (typeof document === "undefined") return;
95
+ document.documentElement.toggleAttribute("data-afw-sidebar-open", isOpen);
96
+ document.body.style.overflow = isOpen ? "hidden" : "";
97
+ window.dispatchEvent(new CustomEvent("afw:sidebar", { detail: { open: isOpen } }));
98
+ });
99
+
100
+ // Close on navigation — clicking a drawer link should dismiss it.
101
+ $effect(() => {
102
+ router.pathname; // subscribe
103
+ close();
104
+ });
105
+
106
+ // Keep the active item in view. On navigation a fresh Sidebar mounts (see the
107
+ // reference-count note above) scrolled to the top, so a deep-in-a-long-tree active link
108
+ // would sit off-screen. When it's outside the sidebar's own scroll viewport, bring it
109
+ // into view — adjusting only the sidebar's scrollTop, never the page's scroll.
110
+ $effect(() => {
111
+ router.pathname; // re-run on navigation
112
+ if (typeof requestAnimationFrame === "undefined") return;
113
+ // Defer a frame so the newly-active class (and any auto-expanded branch) is in the DOM.
114
+ const raf = requestAnimationFrame(() => {
115
+ const aside = asideRef;
116
+ const active = aside && aside.querySelector(".afwd-sidebar-nav .afwd-active");
117
+ if (!active) return;
118
+ const a = active.getBoundingClientRect();
119
+ const c = aside.getBoundingClientRect();
120
+ if (a.top < c.top || a.bottom > c.bottom) {
121
+ aside.scrollTop += a.top - c.top - (aside.clientHeight - a.height) / 2;
122
+ }
123
+ });
124
+ return () => cancelAnimationFrame(raf);
125
+ });
126
+
127
+ return (
128
+ <div class="afwd-sidebar-shell">
129
+ <div
130
+ class={open ? "afwd-sidebar-backdrop is-open" : "afwd-sidebar-backdrop"}
131
+ onclick={close}
132
+ aria-hidden="true"
133
+ ></div>
134
+ <aside id="afw-sidebar" ref={asideRef} class={open ? "afwd-sidebar is-open" : "afwd-sidebar"}>
135
+ {navLinks.length ? (
136
+ <nav class="afwd-drawer-links" aria-label="Site">
137
+ {navLinks.map((link) => (
138
+ <NavbarLink link={link} />
139
+ ))}
140
+ </nav>
141
+ ) : null}
142
+ {hasGroups ? (
143
+ <div class="afwd-sidebar-tools">
144
+ <button
145
+ type="button"
146
+ class="afwd-sidebar-collapse-all"
147
+ onclick={() => collapseAll.set(collapseAll.collapsed)}
148
+ aria-label={collapseAll.collapsed ? "Expand all sections" : "Collapse all sections"}
149
+ title={collapseAll.collapsed ? "Expand all sections" : "Collapse all sections"}
150
+ >
151
+ {() =>
152
+ collapseAll.collapsed ? (
153
+ // chevrons pointing apart — press to expand everything
154
+ <svg
155
+ width="15"
156
+ height="15"
157
+ viewBox="0 0 24 24"
158
+ fill="none"
159
+ stroke="currentColor"
160
+ stroke-width="2"
161
+ stroke-linecap="round"
162
+ stroke-linejoin="round"
163
+ aria-hidden="true"
164
+ >
165
+ <path d="m7 9 5-5 5 5" />
166
+ <path d="m7 15 5 5 5-5" />
167
+ </svg>
168
+ ) : (
169
+ // chevrons pointing together — press to collapse everything
170
+ <svg
171
+ width="15"
172
+ height="15"
173
+ viewBox="0 0 24 24"
174
+ fill="none"
175
+ stroke="currentColor"
176
+ stroke-width="2"
177
+ stroke-linecap="round"
178
+ stroke-linejoin="round"
179
+ aria-hidden="true"
180
+ >
181
+ <path d="m7 4 5 5 5-5" />
182
+ <path d="m7 20 5-5 5 5" />
183
+ </svg>
184
+ )
185
+ }
186
+ </button>
187
+ </div>
188
+ ) : null}
189
+ <nav class="afwd-sidebar-nav" aria-label="Documentation">
190
+ <ul class="afwd-sidebar-list">
191
+ {nav.map((item, i) => (
192
+ <SidebarNode item={item} nodeId={String(i)} />
193
+ ))}
194
+ </ul>
195
+ </nav>
196
+ </aside>
197
+ </div>
198
+ );
199
+ }