Sidebar-and-main app shell. Provisions sidebar_state_context (creating
a fresh SidebarState if sidebar_state is not supplied) so descendants
can read sidebar visibility and toggle it. Optionally binds a global
keyboard shortcut and renders a built-in toggle button (or a custom one
via the toggle_button snippet) while the sidebar is enabled. Requires
the SvelteKit runtime — it closes the overlay from afterNavigate.
Two modes, split by the state's narrow_query. Outside it the sidebar
sits beside the content, padded by --sidebar_offset, following
show_sidebar_wide. Inside it the sidebar starts closed and opens as an
overlay over a scrim, following show_sidebar_narrow; the content is
inert while it's open, and navigation, Escape, a scrim click, or
widening out of narrow mode closes it. Escape never prevents the
default, so the browser's close requests stay intact; it does nothing
while a modal (:modal) is open, when a window keydown listener
registered before the overlay opened swallows it (a contextmenu, say),
or when a visible Popover's document listener already handled it.
The open overlay is a modal dialog: the sidebar takes role="dialog",
aria-modal, tabindex="-1", and sidebar_label as its name, and
focus moves into it, to its first control that takes focus, else to the
sidebar itself — the content went inert and dropped it. The attributes
key on the open overlay, which reads the viewport — that's what keeps
the wide sidebar from ever being a dialog — and the server render
matches hydration because the overlay always starts closed, as with the
content's inert. aria-modal lets assistive tech hide everything
outside the sidebar, the built-in toggle included, so a sidebar whose
screen-reader users need a close control beyond Escape and navigation
renders its own.
Closing with Escape, the keyboard shortcut, or a scrim click returns
focus to what opened the overlay, or else to the first element whose
aria-controls names the sidebar's id and that takes it — when focus
was inside the sidebar or had fallen to the body. The id is the state's
sidebar_id when set, so a toggle outside the shell can carry
aria-controls too; Safari doesn't focus a clicked button, so without
it a mouse-opened overlay has no opener to return to.
The shell's rules sit in two cascade layers nested under fuz_app.
fuz_app.app_shell_base, in the scoped style, holds the base and state
rules, which apply in both modes; fuz_app.app_shell_narrow overrides
some of them from a style element in svelte:head carrying
media={narrow_query}, so the server render paints the right mode
before hydration and the markup's classes never depend on the viewport.
The narrow layer is ordered after the base layer, so it wins whatever
the selectors' specificity or the sheets' order. Its rules are global —
they match every .app-shell on the page — so shells mounted at the
same time must share a narrow_query. Pages served under a strict CSP
need style-src-elem 'unsafe-inline' or the hash of that constant style.
Public class hooks: .app-shell (root, with state classes .wide-open /
.narrow-open), .app-shell-content, .app-shell-sidebar,
.app-shell-scrim, .app-shell-toggle, .app-shell-toggle-glyph. Any
unlayered rule beats both layers at any specificity, so overrides need
no specificity games; to layer them instead, order fuz_app first
(@layer fuz_app, overrides;) in a sheet that loads before the shell.
The same rule means an unlayered reset overrides the shell too — the
fuz_css reset zeroes padding, margin, and border on every element —
so the layers set none of those. The one they need, the content's
wide offset, goes through --sidebar_offset: the layers set it on
.app-shell-content (--sidebar_width while the wide sidebar is open,
else 0px), and one unlayered rule at (0,0,1) reads it into the
content's padding-left. Descendants of the content can read it too.
Override the offset by setting --sidebar_offset on
.app-shell-content or with a padding-left rule there; a padding
shorthand there overrides it as well. Like any unlayered override,
these apply in both modes, open or closed; to change only the wide open
offset, target .app-shell.wide-open > .app-shell-content inside the
narrow query's negation — the state classes don't track the viewport,
so .wide-open stays set in narrow mode too. CSS variables:
--sidebar_bg, --sidebar_z_index (default 200 in both modes; the toggle sits one
above), --sidebar_scrim_bg, --sidebar_width (set from the
sidebar_width prop; always the configured width, not the offset), and
--sidebar_offset.