/** * The documentation site's client bundle. * * Small on purpose. Navigation, sidebar, outline, language menu and the mobile drawer * are all server-rendered HTML and CSS — a documentation site that needs script to show * its navigation shows nothing to a crawler, and nothing to a reader on a failed request. * What is here genuinely cannot be done without it. */ import '../styles/docs.css'; import '../styles/home.css'; import '../styles/demos.css'; import '../styles/design-illustrations.css'; import 'ranui/style'; // Header chrome is on every page: static imports so the upgrade rides the main // module graph instead of a post-paint dynamic import waterfall (refresh flash). import 'ranui/menubar'; import 'ranui/select'; import 'ranui/theme-switch'; import 'ranui/surface-switch'; import { mountPreviewDemo } from './preview.ts'; import { mountComponents } from './components.ts'; import { cacheVisitedAssets } from './visited-assets.ts'; import { mountIdlePrefetch } from './idle-prefetch.ts'; import { mountCodeGroups } from './code-groups.ts'; import { mountDesignIllustrations } from './design-illustrations.ts'; import { mountSearch } from './search.ts'; import { mountDemos } from './home.ts'; import { mountEntrance } from './entrance.ts'; import { mountNavigation, mountCodeCopy } from './interactions.ts'; import { mountPlaygrounds } from './playground.ts'; import { mountSidebar } from './sidebar.ts'; import { mountHeaderTools } from './header-tools.ts'; cacheVisitedAssets(); mountComponents(); mountPreviewDemo(); mountCodeGroups(); mountDesignIllustrations(); mountPlaygrounds(); /** * Mark the outline entry for whatever section is on screen. * * `IntersectionObserver` rather than a scroll handler: the callback only fires when a * heading actually crosses the line, instead of on every frame of every scroll. */ const headings = [...document.querySelectorAll('.prose h2[id], .prose h3[id]')]; const links = new Map(); for (const link of document.querySelectorAll('.toc__link')) { const hash = decodeURIComponent(link.hash.slice(1)); const copies = links.get(hash) ?? []; copies.push(link); links.set(hash, copies); } if (headings.length && links.size) { let current: HTMLAnchorElement[] | undefined; const observer = new IntersectionObserver( (entries) => { for (const entry of entries) { if (!entry.isIntersecting) continue; const link = links.get(entry.target.id); if (!link || link === current) continue; current?.forEach((copy) => copy.removeAttribute('data-active')); link.forEach((copy) => copy.setAttribute('data-active', '')); current = link; } }, // A band just under the sticky header: a heading counts as "current" once it reaches // the top of the reading area, not when it first appears at the bottom. { rootMargin: '-72px 0px -70% 0px' }, ); for (const heading of headings) observer.observe(heading); } mountSearch(); mountDemos(); mountEntrance(); mountNavigation(); mountSidebar(); mountHeaderTools(); mountCodeCopy(); mountIdlePrefetch();