@writedocs/generator 0.11.1 → 0.12.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 +1 -1
- package/src/cli/build.js +203 -177
- package/src/cli/og-image-worker.js +20 -0
- package/src/cli/og-images.js +70 -0
- package/src/cli/run-astro.js +97 -93
- package/src/components/ApiReferencePanel.astro +1792 -1792
- package/src/layout/BaseLayout.astro +1 -3
- package/src/layout/components/MobileMenu.astro +9 -13
- package/src/layout/components/NavTree.astro +21 -6
- package/src/layout/components/Sidebar.astro +4 -4
- package/src/layout/styles/base.css +326 -327
- package/src/layout/styles/mobile-menu.css +285 -285
- package/src/lib/og-cards.js +33 -0
- package/src/lib/og-image.js +235 -168
- package/src/pages/og/[...slug].png.ts +63 -64
- package/src/scripts/mobile-menu.ts +80 -55
- package/src/scripts/sidebar-scroll.ts +61 -65
|
@@ -1,55 +1,80 @@
|
|
|
1
|
-
// The <= 860px hamburger menu (MobileMenu.astro's own toggle button +
|
|
2
|
-
// overlay panel). The accordion rows inside the panel need no JS of their
|
|
3
|
-
// own - they're plain <details name="wd-mobile-accordion"> elements, which
|
|
4
|
-
// get native click/keyboard toggling and (in browsers supporting the
|
|
5
|
-
// `name` attribute's exclusive-accordion behavior) mutual exclusion for
|
|
6
|
-
// free, same as NavTree.astro's own collapsible groups already rely on
|
|
7
|
-
// <details> for. This function only owns the panel itself: open/close, the
|
|
8
|
-
// backdrop, Escape, and body scroll locking while it's open - same pattern
|
|
9
|
-
// initSearch() uses for its own modal.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
// The <= 860px hamburger menu (MobileMenu.astro's own toggle button +
|
|
2
|
+
// overlay panel). The accordion rows inside the panel need no JS of their
|
|
3
|
+
// own - they're plain <details name="wd-mobile-accordion"> elements, which
|
|
4
|
+
// get native click/keyboard toggling and (in browsers supporting the
|
|
5
|
+
// `name` attribute's exclusive-accordion behavior) mutual exclusion for
|
|
6
|
+
// free, same as NavTree.astro's own collapsible groups already rely on
|
|
7
|
+
// <details> for. This function only owns the panel itself: open/close, the
|
|
8
|
+
// backdrop, Escape, and body scroll locking while it's open - same pattern
|
|
9
|
+
// initSearch() uses for its own modal.
|
|
10
|
+
//
|
|
11
|
+
// And the sidebar inside it: the page has one, in BaseLayout's
|
|
12
|
+
// `.wd-sidebar-col` (hidden at this width). Opening the menu moves it into
|
|
13
|
+
// the panel's `.wd-mobile-menu-sidebar`, where it stays while the menu
|
|
14
|
+
// closes (the panel slides out with it) and opens again; widening the window
|
|
15
|
+
// past 860px moves it back. Moved rather than drawn there by CSS: the panel
|
|
16
|
+
// scrolls its switchers and the sidebar as one list, under its own header,
|
|
17
|
+
// and a second box laid over it couldn't. Moving is also what keeps the
|
|
18
|
+
// styles exactly those of the copy the panel used to get (MobileMenu.astro):
|
|
19
|
+
// the same nodes under the same containers. Without JavaScript the menu
|
|
20
|
+
// doesn't open, so nothing is lost there. ClientRouter replaces the whole
|
|
21
|
+
// <body> on every navigation, so each page starts with the sidebar in its
|
|
22
|
+
// column again.
|
|
23
|
+
export function initMobileMenu(root: ParentNode) {
|
|
24
|
+
const trigger = root.querySelector<HTMLButtonElement>('[data-mobile-menu-trigger]');
|
|
25
|
+
const menu = root.querySelector<HTMLElement>('#wd-mobile-menu');
|
|
26
|
+
const backdrop = menu?.querySelector<HTMLElement>('[data-mobile-menu-backdrop]');
|
|
27
|
+
// The panel's own close button (.wd-mobile-menu-header, next to its
|
|
28
|
+
// replica of the topbar brand) - the real hamburger-turned-X trigger up
|
|
29
|
+
// in the topbar is covered by the panel itself once open, so this is the
|
|
30
|
+
// only reachable way to close via click besides the backdrop.
|
|
31
|
+
const closeBtn = menu?.querySelector<HTMLButtonElement>('[data-mobile-menu-close]');
|
|
32
|
+
if (!trigger || !menu || !backdrop || trigger.dataset.wdInit) return;
|
|
33
|
+
trigger.dataset.wdInit = 'true';
|
|
34
|
+
const column = root.querySelector<HTMLElement>('.wd-sidebar-col');
|
|
35
|
+
const drawerSidebar = menu.querySelector<HTMLElement>('.wd-mobile-menu-sidebar');
|
|
36
|
+
const narrow = window.matchMedia('(max-width: 860px)');
|
|
37
|
+
// Every child, not just .wd-sidebar: whatever the page put in the sidebar slot.
|
|
38
|
+
const moveSidebar = (from: HTMLElement | null, to: HTMLElement | null) => {
|
|
39
|
+
if (from && to) to.append(...from.childNodes);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function open() {
|
|
43
|
+
// Only at the width where the column is hidden.
|
|
44
|
+
if (narrow.matches) moveSidebar(column, drawerSidebar);
|
|
45
|
+
menu!.classList.add('open');
|
|
46
|
+
// `inert` (not just visibility/pointer-events, which only affect
|
|
47
|
+
// vision/mouse) is what keeps the closed panel's links out of Tab
|
|
48
|
+
// order and off a screen reader's radar - removed while open so its
|
|
49
|
+
// content becomes reachable again.
|
|
50
|
+
menu!.removeAttribute('inert');
|
|
51
|
+
trigger!.classList.add('open');
|
|
52
|
+
trigger!.setAttribute('aria-expanded', 'true');
|
|
53
|
+
document.body.style.overflow = 'hidden';
|
|
54
|
+
}
|
|
55
|
+
function close() {
|
|
56
|
+
menu!.classList.remove('open');
|
|
57
|
+
menu!.setAttribute('inert', '');
|
|
58
|
+
trigger!.classList.remove('open');
|
|
59
|
+
trigger!.setAttribute('aria-expanded', 'false');
|
|
60
|
+
document.body.style.overflow = '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
trigger.addEventListener('click', () => (menu.classList.contains('open') ? close() : open()));
|
|
64
|
+
backdrop.addEventListener('click', close);
|
|
65
|
+
closeBtn?.addEventListener('click', close);
|
|
66
|
+
document.addEventListener('keydown', (e) => {
|
|
67
|
+
if (e.key === 'Escape' && menu.classList.contains('open')) close();
|
|
68
|
+
});
|
|
69
|
+
// Resizing past the breakpoint while open (rotating a tablet, or
|
|
70
|
+
// widening a desktop browser window) - the panel/backdrop are already
|
|
71
|
+
// hard-hidden above 860px via CSS regardless, but without this the body
|
|
72
|
+
// scroll lock and the trigger's own "open" state would stick around with
|
|
73
|
+
// no visible panel left to close them.
|
|
74
|
+
// Wide again, the sidebar goes back to its column whether or not the menu
|
|
75
|
+
// was still open.
|
|
76
|
+
window.matchMedia('(min-width: 861px)').addEventListener('change', (e) => {
|
|
77
|
+
if (e.matches && menu.classList.contains('open')) close();
|
|
78
|
+
if (e.matches) moveSidebar(drawerSidebar, column);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -1,65 +1,61 @@
|
|
|
1
|
-
// ClientRouter swaps <body> (and everything in it) on every navigation -
|
|
2
|
-
// [...slug].astro re-renders Sidebar.astro/NavTree.astro fresh per page,
|
|
3
|
-
// since the active-link highlight and each collapsible group's open/closed
|
|
4
|
-
// state are computed server-side from the *new* URL (see NavTree.astro's
|
|
5
|
-
// own comment on `open = isActive || navTreeContainsSlug(...)`). That's
|
|
6
|
-
// exactly the behavior a reader wants for highlighting/auto-expanding the
|
|
7
|
-
// right branch - but it also means .wd-sidebar is a brand-new DOM node on
|
|
8
|
-
// every navigation, with its own independent scroll position (it's
|
|
9
|
-
// `overflow-y: auto`, not the window) starting back at 0, same as a full
|
|
10
|
-
// page reload would. For a page nested deep in a long nav tree, that reads
|
|
11
|
-
// as the sidebar "jumping back to the top" on every click - disorienting,
|
|
12
|
-
// since the reader loses their place in the tree they were navigating.
|
|
13
|
-
// This module carries the old sidebar's scroll offset across the swap and
|
|
14
|
-
// re-applies it to the new one, without touching anything about how the
|
|
15
|
-
// highlight/expand state itself is computed (that server-rendered-per-page
|
|
16
|
-
// behavior stays exactly as it is - only the scroll position is preserved).
|
|
17
|
-
//
|
|
18
|
-
// A module-scoped variable (not sessionStorage) is enough: this script's
|
|
19
|
-
// own module graph is loaded once and never re-evaluated by a ClientRouter
|
|
20
|
-
// swap (only <body>'s content is replaced), so the value naturally
|
|
21
|
-
// survives from one navigation to the next without needing to serialize it
|
|
22
|
-
// anywhere. It deliberately does NOT survive a real full-page reload
|
|
23
|
-
// (Cmd+R/F5) - resetting to the top on an actual reload is ordinary,
|
|
24
|
-
// expected browser behavior, not something this needs to fight.
|
|
25
|
-
let savedScrollTop: number | null = null;
|
|
26
|
-
|
|
27
|
-
/** The sidebar
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const sidebar = visibleSidebar();
|
|
63
|
-
if (sidebar) sidebar.scrollTop = savedScrollTop;
|
|
64
|
-
savedScrollTop = null;
|
|
65
|
-
}
|
|
1
|
+
// ClientRouter swaps <body> (and everything in it) on every navigation -
|
|
2
|
+
// [...slug].astro re-renders Sidebar.astro/NavTree.astro fresh per page,
|
|
3
|
+
// since the active-link highlight and each collapsible group's open/closed
|
|
4
|
+
// state are computed server-side from the *new* URL (see NavTree.astro's
|
|
5
|
+
// own comment on `open = isActive || navTreeContainsSlug(...)`). That's
|
|
6
|
+
// exactly the behavior a reader wants for highlighting/auto-expanding the
|
|
7
|
+
// right branch - but it also means .wd-sidebar is a brand-new DOM node on
|
|
8
|
+
// every navigation, with its own independent scroll position (it's
|
|
9
|
+
// `overflow-y: auto`, not the window) starting back at 0, same as a full
|
|
10
|
+
// page reload would. For a page nested deep in a long nav tree, that reads
|
|
11
|
+
// as the sidebar "jumping back to the top" on every click - disorienting,
|
|
12
|
+
// since the reader loses their place in the tree they were navigating.
|
|
13
|
+
// This module carries the old sidebar's scroll offset across the swap and
|
|
14
|
+
// re-applies it to the new one, without touching anything about how the
|
|
15
|
+
// highlight/expand state itself is computed (that server-rendered-per-page
|
|
16
|
+
// behavior stays exactly as it is - only the scroll position is preserved).
|
|
17
|
+
//
|
|
18
|
+
// A module-scoped variable (not sessionStorage) is enough: this script's
|
|
19
|
+
// own module graph is loaded once and never re-evaluated by a ClientRouter
|
|
20
|
+
// swap (only <body>'s content is replaced), so the value naturally
|
|
21
|
+
// survives from one navigation to the next without needing to serialize it
|
|
22
|
+
// anywhere. It deliberately does NOT survive a real full-page reload
|
|
23
|
+
// (Cmd+R/F5) - resetting to the top on an actual reload is ordinary,
|
|
24
|
+
// expected browser behavior, not something this needs to fight.
|
|
25
|
+
let savedScrollTop: number | null = null;
|
|
26
|
+
|
|
27
|
+
/** The page's one `.wd-sidebar` - in `.wd-sidebar-col` on desktop, or
|
|
28
|
+
* moved into MobileMenu.astro's drawer once that has been opened at phone
|
|
29
|
+
* width (src/scripts/mobile-menu.ts) - when it has a real layout box: in
|
|
30
|
+
* the column at phone width it's hidden, and there's no scroll position to
|
|
31
|
+
* carry. Returns null then, and on a page with no sidebar at all (`mode:
|
|
32
|
+
* custom`/`blank`, see BaseLayout.astro). */
|
|
33
|
+
function visibleSidebar(): HTMLElement | null {
|
|
34
|
+
const candidates = document.querySelectorAll<HTMLElement>('.wd-sidebar');
|
|
35
|
+
for (const el of candidates) {
|
|
36
|
+
if (el.offsetWidth > 0 || el.offsetHeight > 0) return el;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Reads the current scroll offset right before ClientRouter tears down
|
|
42
|
+
* the old page's DOM - `astro:before-swap` is the last moment the old
|
|
43
|
+
* `.wd-sidebar` is still attached and its `scrollTop` still means
|
|
44
|
+
* anything. */
|
|
45
|
+
export function saveSidebarScroll() {
|
|
46
|
+
const sidebar = visibleSidebar();
|
|
47
|
+
savedScrollTop = sidebar ? sidebar.scrollTop : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Re-applies the saved offset onto the new page's own `.wd-sidebar`.
|
|
51
|
+
* Bound to `astro:after-swap` (fires synchronously right after the swap,
|
|
52
|
+
* before the browser's next paint - see BaseLayout.astro's own
|
|
53
|
+
* `wdApplyStoredPreferences` for the identical timing rationale) rather
|
|
54
|
+
* than the later `astro:page-load`, so the sidebar never visibly flashes
|
|
55
|
+
* at the top before jumping to the preserved position. */
|
|
56
|
+
export function restoreSidebarScroll() {
|
|
57
|
+
if (savedScrollTop === null) return;
|
|
58
|
+
const sidebar = visibleSidebar();
|
|
59
|
+
if (sidebar) sidebar.scrollTop = savedScrollTop;
|
|
60
|
+
savedScrollTop = null;
|
|
61
|
+
}
|