@sypnia/ui 0.1.0 → 0.2.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.
@@ -0,0 +1,10 @@
1
+ ---
2
+ // The mark of another company, for a «Continue with …» button: Google or GitHub, exactly as its owner publishes it
3
+ // (src/icons/brands.ts). Decoration beside the button's words; with `label` it is an image named after the company.
4
+ import { brandMarks, type BrandName } from '../src/icons/brands';
5
+ interface Props { name: BrandName; size?: number; label?: boolean; class?: string }
6
+ const { name, size, label, class: className } = Astro.props;
7
+ const m = brandMarks[name];
8
+ ---
9
+ <svg class:list={['sy-brandmark', `sy-brandmark--${name}`, className]} viewBox={m.viewBox} width={size} height={size}
10
+ role={label ? 'img' : undefined} aria-label={label ? m.name : undefined} aria-hidden={label ? undefined : 'true'} set:html={m.svg} />
@@ -1,33 +1,78 @@
1
1
  ---
2
- // Goes in <head> of every page that uses DocsShell. Before the first paint it applies what the person chose last time
3
- // (surface, density, folded navigation), so nothing flashes.
4
- // `router` (default true): moving between pages happens in place (Astro's ClientRouter): the header, the navigation
5
- // and its scroll stay, the next page is fetched when the pointer rests on its link, and back and forward restore the
6
- // scroll. Without JavaScript every link is a plain link. With `router={false}`, Chromium prepares the page under the
7
- // pointer instead (speculation rules) and the browser loads it as usual.
8
- import { ClientRouter } from 'astro:transitions';
9
- interface Props { router?: boolean }
10
- const { router = true } = Astro.props;
2
+ // Goes in <head> of every page that uses DocsShell. Every Sypnia docs site (and the gallery) moves between pages the
3
+ // same way, and this is where that way is set:
4
+ //
5
+ // - Links are plain links and every page is a whole page load. The browser does what people expect of it: focus
6
+ // starts at the top (the skip link is the first stop), the new title is announced, back and forward restore the
7
+ // scroll and the page (back-forward cache), and a middle click or a copied link works. No script is needed.
8
+ // - It is still instant: Chromium prerenders the page a link points to when the pointer rests on it or a finger
9
+ // presses it (speculation rules); other browsers fetch it on hover or focus.
10
+ // - What the person chose last time (surface, density, folded navigation, language) is applied here, before the first
11
+ // paint, so nothing flashes; the side navigation takes back its scroll and its open sections before it is painted
12
+ // (DocsShell, SideNav), so moving from page to page does not move it.
13
+ //
14
+ // There is no in-place page swap (no ClientRouter): it kept the navigation in the DOM, but needed focus, scroll,
15
+ // announcement and scripts redone by hand, and its View Transition overlay swallowed quick second clicks.
16
+ interface Props {
17
+ /** Colours of the browser bar on each surface. Defaults to the background of night and paper. */
18
+ themeColor?: { night: string; paper: string };
19
+ }
20
+ const { themeColor = { night: '#08282a', paper: '#f2f4e6' } } = Astro.props;
21
+ // Same-origin pages only: never files (Markdown twins, llms.txt, indexes, downloads) or links that open elsewhere.
22
+ const files = ['md', 'txt', 'json', 'xml', 'pdf', 'zip', 'svg', 'png', 'jpg', 'webp', 'mp4'].map((x) => `/*.${x}`);
11
23
  const rules = JSON.stringify({
12
- prerender: [{ where: { and: [{ href_matches: '/*' }, { not: { selector_matches: '[data-no-prerender], [download], [target=_blank]' } }] }, eagerness: 'moderate' }],
24
+ prerender: [{
25
+ where: { and: [{ href_matches: '/*' }, { not: { href_matches: files } }, { not: { selector_matches: '[data-no-prerender], [download], [target=_blank], [rel~=external]' } }] },
26
+ eagerness: 'moderate',
27
+ }],
13
28
  });
14
29
  ---
30
+ <meta name="color-scheme" content="dark light" />
31
+ <meta name="theme-color" content={themeColor.night} data-sy-theme-color data-night={themeColor.night} data-paper={themeColor.paper} />
15
32
  <script is:inline>
16
33
  (() => {
17
- // The person's choices live on <html>. A page change in place replaces <html>'s attributes with the new page's,
18
- // so they are applied again after every swap, before it is painted.
19
- const apply = (d) => { try {
20
- const s = localStorage.getItem('sy-surface'), n = localStorage.getItem('sy-density'), f = localStorage.getItem('sy-nav');
21
- if (s) d.dataset.surface = s; if (n) d.dataset.density = n; else delete d.dataset.density;
34
+ const d = document.documentElement;
35
+ const get = (k, old) => { try { const v = localStorage.getItem(k); return v === null && old ? localStorage.getItem(old) : v; } catch { return null; } };
36
+ // The language the person chose is kept: arriving from outside the site (a search engine, another site) at a page
37
+ // in the other language takes them to the same page in theirs. Moving inside the site never redirects.
38
+ const lang = get('sy-lang', 'sypnia-lang');
39
+ if (lang && lang !== d.lang && document.referrer.indexOf(location.origin + '/') !== 0) {
40
+ const alt = document.querySelector('link[rel="alternate"][hreflang="' + lang + '"]');
41
+ if (alt) { location.replace(new URL(alt.href).pathname + location.search + location.hash); return; }
42
+ }
43
+ const apply = () => {
44
+ const s = get('sy-surface', 'sypnia-surface'), n = get('sy-density'), f = get('sy-nav', 'sypnia-nav');
45
+ if (s === 'night' || s === 'paper') d.dataset.surface = s; else delete d.dataset.surface;
46
+ if (n === 'compact') d.dataset.density = n; else delete d.dataset.density;
22
47
  if (f === 'hidden') d.dataset.nav = 'hidden'; else delete d.dataset.nav;
23
48
  d.classList.add('sy-js');
24
- } catch {} };
25
- apply(document.documentElement);
26
- // Pages change with no animation, so the browser's View Transitions add nothing but their overlay, which takes the
27
- // pointer until it ends: a click right after a page change landed nowhere. Hidden here, before the router loads,
28
- // the router swaps the page directly.
29
- try { if (!window.__syKeepViewTransitions) Object.defineProperty(document, 'startViewTransition', { value: undefined, configurable: true }); } catch {}
30
- if (!window.__syPrefs) { window.__syPrefs = true; document.addEventListener('astro:before-swap', (e) => apply(e.newDocument.documentElement)); }
49
+ // the search shortcut is written as this keyboard writes it (⌘ K or Ctrl K), before it is painted
50
+ if (/Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)) d.classList.add('sy-mac');
51
+ const surface = d.dataset.surface || (matchMedia('(prefers-color-scheme: light)').matches ? 'paper' : 'night');
52
+ const meta = document.querySelector('meta[data-sy-theme-color]');
53
+ if (meta) meta.content = meta.dataset[surface];
54
+ };
55
+ apply();
56
+ // A page prepared ahead read the choices when it was prepared; it reads them again when it is shown.
57
+ if (document.prerendering) document.addEventListener('prerenderingchange', apply, { once: true });
58
+ // Browsers without speculation rules fetch a page ahead when a link to it is hovered or focused.
59
+ if (!(HTMLScriptElement.supports && HTMLScriptElement.supports('speculationrules'))) {
60
+ const done = new Set(), skip = /\.(md|txt|json|xml|pdf|zip|svg|png|jpe?g|webp|mp4)$/i;
61
+ let timer = 0;
62
+ const ahead = (e) => {
63
+ const a = e.target.closest && e.target.closest('a[href]');
64
+ if (!a || a.target === '_blank' || a.hasAttribute('download') || a.closest('[data-no-prerender]')) return;
65
+ const u = new URL(a.href, location.href);
66
+ if (u.origin !== location.origin || skip.test(u.pathname) || (u.pathname === location.pathname && u.search === location.search)) return;
67
+ const href = u.pathname + u.search;
68
+ if (done.has(href)) return;
69
+ clearTimeout(timer);
70
+ timer = setTimeout(() => { done.add(href); const l = document.createElement('link'); l.rel = 'prefetch'; l.href = href; document.head.append(l); }, e.type === 'pointerover' ? 80 : 0);
71
+ };
72
+ document.addEventListener('pointerover', ahead, { passive: true });
73
+ document.addEventListener('focusin', ahead);
74
+ document.addEventListener('touchstart', ahead, { passive: true });
75
+ }
31
76
  })();
32
77
  </script>
33
- {router ? <ClientRouter fallback="none" /> : <script type="speculationrules" set:html={rules} />}
78
+ <script type="speculationrules" set:html={rules} />
@@ -3,7 +3,6 @@
3
3
  // the site's main links, the language, the product switcher, night or paper, and one call to action.
4
4
  // Slots: `brand` (instead of the Sypnia logo), `tools` (more buttons before the surface switch).
5
5
  import Icon from './Icon.astro';
6
- import Kbd from './Kbd.astro';
7
6
  import Logo from './Logo.astro';
8
7
  import { wordsOf } from './_locale';
9
8
  export interface DocsLink { label: string; href: string; current?: boolean }
@@ -13,23 +12,25 @@ interface Props {
13
12
  homeHref?: string; product?: string; section?: string;
14
13
  links?: DocsLink[]; languages?: DocsLanguage[]; products?: DocsProduct[];
15
14
  cta?: { label: string; href: string }; search?: boolean; locale?: string;
15
+ /** false: a page without side navigation (a 404, say): no buttons to open or fold it. */
16
+ navigation?: boolean;
16
17
  }
17
- const { homeHref = '/', product, section, links = [], languages = [], products = [], cta, search = true } = Astro.props;
18
+ const { homeHref = '/', product, section, links = [], languages = [], products = [], cta, search = true, navigation = true } = Astro.props;
18
19
  const { t, locale } = wordsOf(Astro);
19
20
  const other = languages.filter((l) => l.code !== locale);
20
21
  ---
21
22
  <header class="sy-dhead">
22
23
  <div class="sy-dhead__in">
23
- <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon sy-dhead__menu" data-nav-open aria-expanded="false" aria-controls="sy-dside" aria-label={t('openNav')}><Icon name="menu" /></button>
24
- <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon sy-btn--sm sy-dhead__fold" data-nav-fold aria-expanded="true" aria-controls="sy-dside" aria-label={t('hideNav')} title={t('hideNav')}><Icon name="sidebar-left" /></button>
24
+ {navigation && <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon sy-dhead__menu" data-nav-open aria-expanded="false" aria-controls="sy-dside" aria-label={t('openNav')}><Icon name="menu" /></button>}
25
+ {navigation && <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon sy-btn--sm sy-dhead__fold" data-nav-fold aria-expanded="true" aria-controls="sy-dside" aria-label={t('hideNav')} title={t('hideNav')}><Icon name="sidebar-left" /></button>}
25
26
  <a class="sy-dhead__brand" href={homeHref}>{Astro.slots.has('brand') ? <slot name="brand" /> : <Logo product={product} />}{section && <span class="sy-dhead__section">{section}</span>}</a>
26
27
  <div class="sy-dhead__mid">
27
- {search && <button type="button" class="sy-search-btn" data-search-open aria-haspopup="dialog"><Icon name="search" /><span>{t('searchDocs')}</span><Kbd>Ctrl K</Kbd></button>}
28
+ {search && <button type="button" class="sy-search-btn" data-search-open aria-haspopup="dialog"><Icon name="search" /><span>{t('searchDocs')}</span><kbd class="sy-kbd sy-kbd--pc">Ctrl K</kbd><kbd class="sy-kbd sy-kbd--mac">⌘ K</kbd></button>}
28
29
  {links.length > 0 && <nav class="sy-dhead__nav" aria-label={t('mainNav')}>{links.map((l) => <a class="sy-dhead__link" href={l.href} aria-current={l.current ? 'page' : undefined}>{l.label}</a>)}</nav>}
29
30
  </div>
30
31
  <div class="sy-dhead__end">
31
32
  {search && <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon sy-dhead__find" data-search-open aria-haspopup="dialog" aria-label={t('searchDocs')}><Icon name="search" /></button>}
32
- {other.map((l) => <a class="sy-btn sy-btn--quiet sy-btn--sm sy-dhead__lang" href={l.href} hreflang={l.code} lang={l.code} data-no-skeleton><Icon name="globe" />{l.label}</a>)}
33
+ {other.map((l) => <a class="sy-btn sy-btn--quiet sy-btn--sm sy-dhead__lang" href={l.href} hreflang={l.code} lang={l.code} data-set-lang={l.code} data-no-skeleton><Icon name="globe" />{l.label}</a>)}
33
34
  <slot name="tools" />
34
35
  {products.length > 0 && (
35
36
  <details class="sy-dswitch">
@@ -12,8 +12,8 @@
12
12
  // Slots: default (the article), `brand`, `tools` (header buttons), `toc-tools` (under «On this page»), `side-foot`
13
13
  // (under the navigation), `foot` (end of the article), `skeletons` (more <template data-skeleton-name="name"> for links
14
14
  // with data-next-skeleton="name").
15
- // With DocsHead's router, the navigation (and its scroll and open sections) and search stay from page to page; the
16
- // current page is lit again after each change.
15
+ // Moving between pages is a whole page load (see DocsHead). The navigation looks as if it never moved: its scroll and
16
+ // its open sections are put back before it is painted, and the current page is lit by the server.
17
17
  import DocsHeader, { type DocsLanguage, type DocsLink, type DocsProduct } from './DocsHeader.astro';
18
18
  import SideNav, { type SideNavSection } from './SideNav.astro';
19
19
  import TableOfContents, { type TocHeading } from './TableOfContents.astro';
@@ -24,7 +24,9 @@ import Logo from './Logo.astro';
24
24
  import { wordsOf } from './_locale';
25
25
  import type { SearchEntry } from '../src/dom/search';
26
26
  interface Props {
27
- nav: SideNavSection[];
27
+ nav?: SideNavSection[];
28
+ /** A page without side navigation and «On this page» (a 404, say): the header and the article only. */
29
+ bare?: boolean;
28
30
  current?: string;
29
31
  toc?: TocHeading[];
30
32
  /** No «On this page» column; the article takes the whole width. */
@@ -34,22 +36,24 @@ interface Props {
34
36
  cta?: { label: string; href: string };
35
37
  /** The search index: a URL to a JSON array of entries, or the entries themselves. Leave out for no search. */
36
38
  search?: string | SearchEntry[];
39
+ /** What the search offers before anything is typed (the sections of the site, say). */
40
+ searchStart?: SearchEntry[];
37
41
  navLabel?: string;
38
42
  locale?: string;
39
43
  class?: string;
40
44
  }
41
- const { nav, current, toc = [], wide, homeHref, product, section, links = [], languages = [], products, cta, search, navLabel, class: className } = Astro.props;
45
+ const { nav = [], bare, current, toc = [], wide, homeHref, product, section, links = [], languages = [], products, cta, search, searchStart, navLabel, class: className } = Astro.props;
42
46
  const { t, locale } = wordsOf(Astro);
43
- const hasToc = !wide && toc.length > 1;
47
+ const hasToc = !wide && !bare && toc.length > 1;
44
48
  ---
45
- <sy-docs class:list={['sy-docs', className]} data-locale={locale}>
49
+ <sy-docs class:list={['sy-docs', bare && 'sy-docs--bare', className]} data-locale={locale}>
46
50
  <a class="sy-skip" href="#sy-article">{t('skipToContent')}</a>
47
- <DocsHeader homeHref={homeHref} product={product} section={section} links={links} languages={languages} products={products} cta={cta} search={!!search} locale={locale}>
51
+ <DocsHeader homeHref={homeHref} product={product} section={section} links={links} languages={languages} products={products} cta={cta} search={!!search} navigation={!bare} locale={locale}>
48
52
  <Fragment slot="brand">{Astro.slots.has('brand') ? <slot name="brand" /> : <Logo product={product} />}</Fragment>
49
53
  <Fragment slot="tools"><slot name="tools" /></Fragment>
50
54
  </DocsHeader>
51
55
  <div class="sy-dshell">
52
- <aside class="sy-dside" id="sy-dside" aria-label={navLabel ?? t('docsNav')} transition:persist={`sy-dside-${locale}`}>
56
+ {!bare && <aside class="sy-dside" id="sy-dside" aria-label={navLabel ?? t('docsNav')}>
53
57
  <div class="sy-dside__head">
54
58
  <a class="sy-dhead__brand" href={homeHref ?? '/'}>{Astro.slots.has('brand') ? <slot name="brand" /> : <Logo product={product} />}</a>
55
59
  <button type="button" class="sy-btn sy-btn--quiet sy-btn--icon" data-nav-close aria-label={t('closeNav')}><Icon name="close" /></button>
@@ -62,9 +66,29 @@ const hasToc = !wide && toc.length > 1;
62
66
  <slot name="side-foot" />
63
67
  </div>
64
68
  </div>
65
- </aside>
66
- <button type="button" class="sy-dscrim" tabindex="-1" aria-hidden="true" data-nav-close></button>
67
- <main class:list={['sy-dmain', wide && 'sy-dmain--wide', !wide && !hasToc && 'sy-dmain--no-toc']} id="sy-main">
69
+ </aside>}
70
+ {!bare && <script is:inline>
71
+ // Before the first paint: the navigation scrolls back to where it was on the last page. When the page was
72
+ // reached from the navigation itself it stays exactly there (the pointer must stay on what it pressed);
73
+ // reached another way (search, previous and next, a link in the text), the current page is brought into view
74
+ // if it would be hidden.
75
+ (() => { try {
76
+ const side = document.getElementById('sy-dside');
77
+ const place = () => {
78
+ const y = Number(sessionStorage.getItem('sy-dside-y')), fromSide = sessionStorage.getItem('sy-dside-from') === (location.pathname.replace(/\/$/, '') || '/');
79
+ if (!document.prerendering) sessionStorage.removeItem('sy-dside-from'); // a page prepared ahead reads it again when shown
80
+ if (y) side.scrollTop = y;
81
+ const here = side.querySelector('.sy-snav [aria-current="page"]');
82
+ if (!here || fromSide) return;
83
+ const r = here.getBoundingClientRect(), b = side.getBoundingClientRect();
84
+ if (b.height && (r.top < b.top || r.bottom > b.bottom)) side.scrollTop += r.top - b.top - (b.height - r.height) / 2;
85
+ };
86
+ place();
87
+ if (document.prerendering) document.addEventListener('prerenderingchange', place, { once: true });
88
+ } catch {} })();
89
+ </script>}
90
+ {!bare && <button type="button" class="sy-dscrim" tabindex="-1" aria-hidden="true" data-nav-close></button>}
91
+ <main class:list={['sy-dmain', (wide || bare) && 'sy-dmain--wide', !wide && !bare && !hasToc && 'sy-dmain--no-toc']} id="sy-main">
68
92
  <article class="sy-darticle" id="sy-article" tabindex="-1">
69
93
  <slot />
70
94
  <slot name="foot" />
@@ -72,7 +96,7 @@ const hasToc = !wide && toc.length > 1;
72
96
  {hasToc && (Astro.slots.has('toc-tools') ? <TableOfContents headings={toc} locale={locale}><slot name="toc-tools" /></TableOfContents> : <TableOfContents headings={toc} locale={locale} />)}
73
97
  </main>
74
98
  </div>
75
- {search && <div transition:persist={`sy-search-${locale}`}><Search index={typeof search === 'string' ? search : undefined} entries={typeof search === 'string' ? undefined : search} locale={locale} /></div>}
99
+ {search && <Search index={typeof search === 'string' ? search : undefined} entries={typeof search === 'string' ? undefined : search} start={searchStart} locale={locale} />}
76
100
  <template data-skeleton-name="article"><DocsArticleSkeleton toc={hasToc} /></template>
77
101
  <template data-skeleton-name="wide"><DocsArticleSkeleton toc={false} /></template>
78
102
  <slot name="skeletons" />
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  // Search across the site, in a <dialog>, from an index of pages (`index`: a JSON URL, loaded on first open; or
3
3
  // `entries` inline). Opens with Ctrl K / ⌘ K, «/», or any button with data-search-open. Results are grouped; the
4
- // arrow keys choose and Enter goes. Behaviour: <sy-search>.
4
+ // arrow keys choose and Enter goes. `start`: what it offers before anything is typed. Behaviour: <sy-search>.
5
5
  import Icon from './Icon.astro';
6
6
  import Kbd from './Kbd.astro';
7
7
  import Character from './Character.astro';
8
8
  import { wordsOf } from './_locale';
9
9
  import type { SearchEntry } from '../src/dom/search';
10
- interface Props { index?: string; entries?: SearchEntry[]; placeholder?: string; locale?: string; id?: string }
11
- const { index, entries, id = 'sy-search' } = Astro.props;
10
+ interface Props { index?: string; entries?: SearchEntry[]; start?: SearchEntry[]; placeholder?: string; locale?: string; id?: string }
11
+ const { index, entries, start, id = 'sy-search' } = Astro.props;
12
12
  const { t } = wordsOf(Astro);
13
13
  const placeholder = Astro.props.placeholder ?? t('searchDocs');
14
14
  ---
@@ -32,5 +32,6 @@ const placeholder = Astro.props.placeholder ?? t('searchDocs');
32
32
  <span><Kbd>Esc</Kbd> {t('toClose')}</span>
33
33
  </div>
34
34
  </dialog>
35
- {entries && <script type="application/json" set:html={JSON.stringify(entries).replace(/</g, '\\u003c')} />}
35
+ {entries && <script type="application/json" data-entries set:html={JSON.stringify(entries).replace(/</g, '\\u003c')} />}
36
+ {start && start.length > 0 && <script type="application/json" data-start set:html={JSON.stringify(start).replace(/</g, '\\u003c')} />}
36
37
  </sy-search>
@@ -1,27 +1,44 @@
1
1
  ---
2
- // The navigation of a docs site: sections that fold (a native <details>, so it works without JavaScript), and the
3
- // light beside the page you are on. A section that holds the current page starts open; the others open as the
4
- // person left them (remembered in the browser).
2
+ // The navigation of a docs site: sections that fold, and the light beside the page you are on. A section that holds
3
+ // the current page starts open; the others open as the person left them (remembered in the browser, put back before
4
+ // the first paint). A section is a native <details> (it works without JavaScript); a section with a page of its own
5
+ // (`href`) is a link and a button that folds it (without JavaScript its pages are always shown).
5
6
  import Icon from './Icon.astro';
6
- export interface SideNavItem { label: string; href: string; planned?: boolean; count?: number; /** The skeleton DocsShell shows while this page loads. */ skeleton?: string; /** Load it as a whole page, not in place (pages with scripts of their own). */ reload?: boolean }
7
- export interface SideNavSection { title: string; items: SideNavItem[]; open?: boolean; collapsible?: boolean }
7
+ import { wordsOf } from './_locale';
8
+ import { nextId } from './_id';
9
+ export interface SideNavItem { label: string; href: string; planned?: boolean; count?: number; /** The skeleton DocsShell shows while this page loads. */ skeleton?: string; }
10
+ export interface SideNavSection { title: string; items: SideNavItem[]; open?: boolean; collapsible?: boolean; /** The section's own page: its title becomes a link, folded by a button beside it. */ href?: string; skeleton?: string }
8
11
  interface Props { sections: SideNavSection[]; current?: string; label?: string; class?: string }
9
12
  const { sections, label = 'Documentation', class: className } = Astro.props;
10
13
  const norm = (p: string) => p.replace(/\/$/, '') || '/';
11
14
  const current = norm(Astro.props.current ?? Astro.url.pathname);
12
15
  const isCurrent = (href: string) => norm(href) === current;
16
+ const { t } = wordsOf(Astro);
17
+ const base = nextId('sy-snav');
13
18
  ---
14
19
  <nav class:list={['sy-snav-wrap', className]} aria-label={label}>
15
20
  <ul class="sy-snav" role="list">
16
- {sections.map((s) => {
17
- const here = s.items.some((i) => isCurrent(i.href));
21
+ {sections.map((s, n) => {
22
+ const here = s.items.some((i) => isCurrent(i.href)) || (!!s.href && isCurrent(s.href));
18
23
  const list = (
19
24
  <ul class:list={['sy-snav__pages', s.collapsible === false && 'sy-snav__pages--flat']} role="list">
20
25
  {s.items.map((i) => (
21
- <li><a href={i.href} data-next-skeleton={i.skeleton} data-astro-reload={i.reload ? '' : undefined} aria-current={isCurrent(i.href) ? 'page' : undefined}><span>{i.label}</span>{i.count !== undefined && <span class="sy-snav__count">{i.count}</span>}{i.planned && <span class="sy-snav__planned" title="Planned" />}</a></li>
26
+ <li><a href={i.href} data-next-skeleton={i.skeleton} aria-current={isCurrent(i.href) ? 'page' : undefined}><span>{i.label}</span>{i.count !== undefined && <span class="sy-snav__count">{i.count}</span>}{i.planned && <span class="sy-snav__planned" title="Planned" />}</a></li>
22
27
  ))}
23
28
  </ul>
24
29
  );
30
+ if (s.href) {
31
+ const id = `${base}-${n}`, open = here || !!s.open;
32
+ return (
33
+ <li class="sy-snav__sec sy-snav__sec--link" data-key={s.title} data-here={here ? '' : undefined} data-open={open ? '' : undefined}>
34
+ <div class="sy-snav__row">
35
+ <a class="sy-snav__title" href={s.href} data-next-skeleton={s.skeleton} aria-current={isCurrent(s.href) ? 'page' : undefined}>{s.title}</a>
36
+ {s.items.length > 0 && <button type="button" class="sy-snav__toggle" data-snav-toggle aria-expanded={String(open)} aria-controls={id} aria-label={t('pagesIn', { section: s.title })}><Icon name="chevron-right" /></button>}
37
+ </div>
38
+ {s.items.length > 0 && <div id={id} class="sy-snav__fold">{list}</div>}
39
+ </li>
40
+ );
41
+ }
25
42
  return s.collapsible === false
26
43
  ? <li class="sy-snav__sec"><p class="sy-snav__label">{s.title}</p>{list}</li>
27
44
  : <li><details class="sy-snav__sec" data-key={s.title} data-here={here ? '' : undefined} open={here || s.open}><summary><span>{s.title}</span><Icon name="chevron-right" /></summary>{list}</details></li>;
@@ -30,11 +47,19 @@ const isCurrent = (href: string) => norm(href) === current;
30
47
  <script is:inline>
31
48
  // Before the first paint: the sections open as the person left them (the current page's section always open).
32
49
  (() => { try {
50
+ // The section of the current page is open, and stays open on the next pages until the person folds it.
33
51
  const open = JSON.parse(localStorage.getItem('sy-snav') || '{}'), nav = document.currentScript.parentElement;
52
+ for (const h of nav.querySelectorAll('[data-here][data-key]')) open[h.dataset.key] = true;
53
+ localStorage.setItem('sy-snav', JSON.stringify(open));
34
54
  for (const d of nav.querySelectorAll('details.sy-snav__sec[data-key]')) {
35
55
  if (d.hasAttribute('data-here')) continue;
36
56
  if (d.dataset.key in open) d.open = !!open[d.dataset.key];
37
57
  }
58
+ for (const li of nav.querySelectorAll('li.sy-snav__sec--link[data-key]')) {
59
+ if (li.hasAttribute('data-here') || !(li.dataset.key in open)) continue;
60
+ li.toggleAttribute('data-open', !!open[li.dataset.key]);
61
+ li.querySelector('[data-snav-toggle]')?.setAttribute('aria-expanded', String(!!open[li.dataset.key]));
62
+ }
38
63
  } catch {} })();
39
64
  </script>
40
65
  </nav>
package/css/base.css CHANGED
@@ -78,6 +78,8 @@ mark, .sy-mark { background: linear-gradient(transparent 12%, var(--mark) 12% 92
78
78
  .sy-icon .lit { fill: var(--icon-lit, currentColor); stroke: var(--icon-lit-ring, none); stroke-width: 1.2; }
79
79
  .sy-icon .lit.fail { fill: var(--icon-fail, var(--icon-lit)); }
80
80
  .sy-icon--plain .lit { fill: currentColor; stroke: none; }
81
+ /* Marks of other companies (BrandMark): their own shapes and colours, the size of an icon. */
82
+ .sy-brandmark { width: 1.25em; height: 1.25em; flex: none; display: inline-block; vertical-align: -0.2em; }
81
83
 
82
84
  /* ---- entering: things light up, they do not fly in. Opt in with data-enter. ---- */
83
85
  @keyframes sy-enter { from { opacity: 0; translate: 0 var(--shift); } }
@@ -0,0 +1,14 @@
1
+ /* QueryEditor: CodeMirror 6 dressed as a field. The box is the same as CodeEditor's; the colours of the code are the
2
+ .sy-tok-* classes below. CodeMirror's own parts are dressed by its editor theme in code-editor.tsx (see there why). */
3
+ @layer sypnia.components {
4
+ .sy-query-editor { --_lh: 1.6; display: flex; flex-direction: column; min-height: calc(var(--rows, 10) * var(--_lh) * 0.8125rem + 1.2rem); border: 1.5px solid var(--line-strong); border-radius: var(--r-2); background: var(--bg-inset); overflow: hidden; font-size: 0.8125rem; }
5
+ .sy-query-editor:focus-within { border-color: var(--focus); box-shadow: 0 0 0 4px var(--focus-halo); }
6
+ .sy-query-editor[data-skeleton] { display: grid; align-content: start; gap: 0.35rem; padding: 0.75rem 0.9rem; }
7
+ .sy-query-editor[data-skeleton] .sy-skeleton:nth-child(2n) { width: 70%; }
8
+ .sy-tok-keyword { color: var(--info-text); font-weight: 500; }
9
+ .sy-tok-string { color: var(--ok-text); }
10
+ .sy-tok-number { color: var(--warn-text); }
11
+ .sy-tok-comment { color: var(--fg-muted); font-style: italic; }
12
+ .sy-tok-type { color: var(--fg-soft); font-weight: 500; }
13
+ .sy-tok-operator { color: var(--fg-soft); }
14
+ }
@@ -16,6 +16,7 @@
16
16
  .sy-dhead__brand { display: inline-flex; align-items: center; gap: 0.7rem; width: max-content; max-width: 100%; color: var(--fg); text-decoration: none; padding-block: 0.4rem; min-width: 0; }
17
17
  .sy-dhead__section { padding-inline-start: 0.7rem; border-inline-start: 1px solid var(--line-strong); font-size: var(--text-sm); font-weight: 600; line-height: 1.5; color: var(--fg-soft); white-space: nowrap; }
18
18
  .sy-dhead__mid { display: flex; align-items: center; gap: var(--s-4); min-width: 0; padding-inline-start: var(--docs-gutter); }
19
+ .sy-mac .sy-kbd--pc, :root:not(.sy-mac) .sy-kbd--mac { display: none; }
19
20
  .sy-dhead__mid .sy-search-btn { width: min(100%, 22rem); min-height: 2.375rem; font-size: var(--text-sm); background: var(--bg-raised); border-color: var(--line); }
20
21
  .sy-dhead__nav { display: flex; gap: var(--s-1); min-width: 0; }
21
22
  .sy-dhead__link { padding: 0.4rem 0.65rem; border-radius: 7px; color: var(--fg-muted); font-size: var(--text-sm); font-weight: 600; text-decoration: none; white-space: nowrap; }
@@ -50,6 +51,8 @@
50
51
  .sy-darticle { min-width: 0; width: 100%; max-width: var(--content-w); justify-self: center; padding-bottom: var(--s-8); }
51
52
  .sy-dmain--wide .sy-darticle { max-width: 72rem; justify-self: start; }
52
53
  :root[data-nav='hidden'] .sy-dshell { grid-template-columns: minmax(0, 1fr); }
54
+ .sy-docs--bare .sy-dshell { grid-template-columns: minmax(0, 1fr); }
55
+ .sy-docs--bare .sy-dmain { padding-inline-start: 0; }
53
56
  :root[data-nav='hidden'] .sy-dside { display: none; }
54
57
  :root[data-nav='hidden'] .sy-dmain { padding-inline-start: 0; }
55
58
  /* While the next page loads: its skeleton takes the place of the article; the header and the navigation stay. */
@@ -69,6 +72,15 @@
69
72
  .sy-snav__sec > summary > span { flex: 1 1 0; min-width: 0; }
70
73
  .sy-snav__sec > summary > .sy-icon { width: 1rem; height: 1rem; color: var(--fg-muted); transition: rotate var(--dur-2) var(--ease-out); }
71
74
  .sy-snav__sec[open] > summary > .sy-icon { rotate: 90deg; }
75
+ .sy-snav__row { display: flex; align-items: center; gap: 0.25rem; margin-inline-start: -0.5rem; }
76
+ .sy-snav__title { flex: 1 1 0; min-width: 0; padding: 0.45rem 0.5rem; border-radius: var(--r-1); color: var(--fg); font-weight: 600; text-decoration: none; }
77
+ .sy-snav__title:hover { background: var(--state-hover); }
78
+ .sy-snav__title[aria-current='page'] { box-shadow: inset 2px 0 0 var(--light-fill); }
79
+ .sy-snav__toggle { flex: none; display: grid; place-items: center; width: 2rem; height: 2rem; padding: 0; border: 0; border-radius: var(--r-1); background: none; color: var(--fg-muted); cursor: pointer; }
80
+ .sy-snav__toggle:hover { background: var(--state-hover); color: var(--fg); }
81
+ .sy-snav__toggle > .sy-icon { width: 1rem; height: 1rem; transition: rotate var(--dur-2) var(--ease-out); }
82
+ .sy-snav__toggle[aria-expanded='true'] > .sy-icon { rotate: 90deg; }
83
+ .sy-js .sy-snav__sec--link:not([data-open]) > .sy-snav__fold { display: none; }
72
84
  .sy-snav__label { padding: 0.9rem 0 0.35rem; font-size: var(--text-2xs); font-weight: 600; color: var(--fg-muted); }
73
85
  .sy-snav__pages { margin: 0.15rem 0 0.7rem 0.3rem; padding: 0; list-style: none; border-inline-start: 1px solid var(--line); }
74
86
  .sy-snav__pages--flat { margin: 0; border: 0; }
@@ -84,7 +96,9 @@
84
96
  .sy-snav__count { flex: none; font-size: var(--text-2xs); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
85
97
 
86
98
  /* ---------- on this page ---------- */
87
- .sy-toc { position: sticky; top: calc(var(--hdr-h) + var(--s-6)); max-height: calc(100dvh - var(--hdr-h) - 3.5rem); overflow-y: auto; margin-inline-start: -6px; padding: 0 0 1rem 6px; font-size: var(--text-xs); line-height: 1.35; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
99
+ .sy-toc { position: sticky; top: calc(var(--hdr-h) + var(--s-6)); max-height: calc(100dvh - var(--hdr-h) - 3.5rem); overflow-y: auto; margin-inline-start: -6px; padding: 0 0 1rem 6px; font-size: var(--text-xs); line-height: 1.35; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; transition: opacity var(--dur-2); }
100
+ /* A page can ask «On this page» to step aside while something wide passes under it (data-away). */
101
+ .sy-toc[data-away] { opacity: 0; pointer-events: none; }
88
102
  .sy-toc__title { font-size: var(--text-xs); font-weight: 600; color: var(--fg); margin-bottom: 0.6rem; }
89
103
  .sy-toc ol { margin: 0; padding: 0; list-style: none; border-inline-start: 1px solid var(--line); }
90
104
  .sy-toc a { position: relative; display: block; padding: 0.32rem 0 0.32rem 0.9rem; color: var(--fg-muted); text-decoration: none; overflow-wrap: anywhere; }
@@ -408,6 +422,7 @@ sy-tabs:not(:defined) > [role='tabpanel'][hidden] { display: block; }
408
422
  /* phones and small tablets: one column, the navigation is a drawer */
409
423
  @media (max-width: 59.99rem) {
410
424
  .sy-docs { --hdr-h: 3.25rem; }
425
+ .sy-snav__toggle { width: 2.75rem; height: 2.75rem; }
411
426
  .sy-dhead__in { grid-template-columns: auto minmax(0, 1fr) auto; column-gap: var(--s-1); }
412
427
  .sy-dhead__in > .sy-dhead__brand { grid-column: 2; }
413
428
  .sy-dhead__menu, .sy-dhead__find { display: inline-flex; }
@@ -23,6 +23,8 @@
23
23
  .sy-seg__item:hover { color: var(--fg); }
24
24
  .sy-seg__item:is([aria-pressed='true'], [aria-checked='true'], [aria-selected='true']), .sy-seg__item:has(input:checked) { background: var(--bg-raised); color: var(--fg); box-shadow: var(--shadow-1), 0 0 0 1px var(--line); }
25
25
  .sy-seg__item input { position: absolute; opacity: 0; pointer-events: none; }
26
+ .sy-seg__item:has(input:disabled) { color: var(--fg-muted); opacity: 0.55; cursor: not-allowed; }
27
+ .sy-seg__item:has(input:disabled):hover { color: var(--fg-muted); }
26
28
  .sy-seg__item:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
27
29
  @media (max-width: 40rem) { .sy-seg { display: grid; grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; } }
28
30
 
@@ -37,7 +37,9 @@
37
37
  /* The light sits beside the current place. */
38
38
  .sy-nav-item[aria-current]::before { content: ''; position: absolute; left: -0.3rem; top: 50%; width: 6px; height: 6px; border-radius: 50%; translate: 0 -50%; background: var(--light-fill); box-shadow: 0 0 0 1.5px var(--light-ring), 0 0 0.6rem 0 color-mix(in oklab, var(--glow) 55%, transparent); }
39
39
 
40
- .sy-shell__main { grid-area: main; overflow-y: auto; overscroll-behavior: contain; min-width: 0; outline: none; scrollbar-gutter: stable; }
40
+ /* `position: relative` makes the main area the box of everything absolutely placed inside it (screen-reader-only live
41
+ regions, popovers anchored in the page): otherwise they escape its scrolling and the whole document scrolls too. */
42
+ .sy-shell__main { grid-area: main; position: relative; overflow-y: auto; overscroll-behavior: contain; min-width: 0; outline: none; scrollbar-gutter: stable; }
41
43
 
42
44
  /* Phones: five named items and «More», at the bottom, within reach of the thumb. */
43
45
  .sy-mobile-nav { display: none; }
package/css/index.css CHANGED
@@ -32,3 +32,4 @@
32
32
  @import './components/data-more.css';
33
33
  @import './components/screens.css';
34
34
  @import './components/viz.css';
35
+ @import './components/code-editor.css';