npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@uvalib/web-components

v1.14.0

Published

UVA Library reusable web components

Readme

@uvalib/web-components

Tests Accessibility Lighthouse

Reusable web components for UVA Library sites, built with Lit and TypeScript:

  • Page chrome: <site-page> (skip link, header with the library main navigation and live library alerts, one <main>, footer), <site-alerts> (the alerts, also usable alone), <site-header>, <site-main-nav>, <site-footer>, <site-analytics> and <uvalib-analytics> (Matomo, one element under two names) and <site-style> (legacy compatibility).
  • Navigation: <uvalib-breadcrumbs> (the breadcrumb trail) and <uvalib-contents> (sub-navigation or a table of contents).
  • Cards: <uvalib-card>, <uvalib-card-grid> and <uvalib-pager>.
  • Tabs: <uvalib-tabs>.
  • Long pages: <uvalib-back-to-top> (a “Back to top” button that appears once the top has scrolled away).
  • Records: <uvalib-metadata> (a record's details, credit, rights and how to cite) and <uvalib-citation> (a citation in several formats, with Copy citation).
  • Images: <uvalib-lightbox> (an image viewer over plain links), <uvalib-photo-grid> (justified rows of thumbnails) and <uvalib-image-regions> (numbered region outlines on an image, with their list).
  • Maps: <uvalib-map> (places on the page's own Leaflet map, sized by a count, with a linked list).
  • Search: <uvalib-filter>, <uvalib-date-range>, <uvalib-date-histogram>, <uvalib-combobox> (a text field that suggests values as you type), <uvalib-list-filter> (a field that filters a long list on the page as you type), <uvalib-filter-drawer> (the filters as a sidebar, or a modal panel on phones), <uvalib-dialog> (a modal dialog for search tips, Cite or a short form) and <uvalib-pagefind-search> (with pagefind.css, the library theme for Pagefind static-site search).
  • Reading texts: edition.css (reading styles for TEI texts converted to class-annotated HTML), and edition-epub.css / edition-print.css for the same texts as EPUB and PDF downloads.
  • Audio: <uvalib-audio> (a long recording played by chapter: an audiobook, an oral history).
  • QR codes: <uvalib-qr> (a QR code in the library's colours, for an event's page on a slide or a poster).
  • Slides: <uvalib-slides> with slides.css (a talk in the Library look, with a presenter view and a reader view; its own import, not in the package index).
  • Library hours: <site-hours-section>, <library-weekly-hours> and <library-hours-setup>.
  • Library events: <events-section>.
  • Search results: <bento-box> (library.virginia.edu/search), with its <catalog-section>, <articles-section>, <libguides-section> and <website-section>.

library.virginia.edu and the UVA Library design system are the style authority: these components exist so sites use the real chrome instead of copying it. Change appearance only through the theming surface below.

Quick start with a coding agent

The fastest route: install the agent skill, then ask your coding agent (Claude Code, Codex, Gemini CLI, GitHub Copilot, Cursor, Grok and others) to do the work. The skill teaches it which entry to load, how to pin versions, shadow vs light DOM, theming, alerts and hours, and how to check the result.

npx @uvalib/web-components install-skill            # this project, for every agent
npx @uvalib/web-components install-skill --global   # your home folder, for every project

It is an Agent Skills folder (SKILL.md and its references), the open format most coding agents read. By default it goes into .claude/skills/ (Claude Code) and .agents/skills/ (the shared folder that Codex, Gemini CLI, GitHub Copilot, Cursor, Grok and other tools read); --global uses ~/.claude/skills/ and ~/.agents/skills/ instead. See Installing the skill for one agent's own folder.

Then ask, for example:

Wrap this site's pages in the UVA Library <site-page> from the v1 CDN, with our own nav links in the header.

Example prompts

Name the skill so the agent loads it, say what to keep, and ask it to audit before editing and to check accessibility before finishing. These are starting points; add your site's specifics.

Brand a new or existing site

Use the uvalib-web-components skill to apply UVA Library branding to this site with the v1 CDN. First audit, with no changes: list how the current header, footer, navigation, buttons, forms and colours map to the library components and classes, and show me the list. Then wrap every page in <site-page site-name="Our site name"> with our own links as site links, link base.css in <head>, replace hand-built buttons and search forms with the library classes, and move our colours onto the --uva-* tokens. Keep every page and URL working. Verify with the skill's accessibility testing guide and commit on a new branch; don't push until I approve.

Migrate from the old components

Use the uvalib-web-components skill to move this project off the old /web-components/latest/ and cdn-v… URLs and @uvalib/<package> npm names to @uvalib/web-components v1. List every old reference first, then change them following the skill's migration guide, keeping the markup working. Run the site's tests and check each page in a browser.

Switch one library.virginia.edu page

Use the uvalib-web-components skill's "Switching library.virginia.edu" table to update the script URLs on the /hours page to v1. Change only the URLs, keep the markup, and tell me what to check after it's live.

Add one pattern

Use the uvalib-web-components skill to add breadcrumbs to every page under /collections/ (Home › Collections › the collection) with <uvalib-breadcrumbs>, placed where <site-page> puts them.

Use the uvalib-web-components skill to turn our collections list into a grid of clickable <uvalib-card>s (title and item count), and add <uvalib-pager> previous/next links to the reading pages.

Use the uvalib-web-components skill to show each record's details with <uvalib-metadata> (creator, date, subjects, downloads with file sizes, rights and how to cite), and open our IIIF page images in <uvalib-lightbox> instead of a new tab.

Use the uvalib-web-components skill to theme our Pagefind search with <uvalib-pagefind-search> and pagefind.css, keeping our index shards and filters.

Dark mode, analytics and search pages

Use the uvalib-web-components skill to turn on the library's opt-in dark mode (Light / Dark / System in the header) and make our own CSS follow the --uva-color-* role tokens. Check contrast in both schemes.

Use the uvalib-web-components skill to add Matomo analytics with <site-page matomo-id="42">. This is a single-page app, so record a page view per route; tag our own Download and Share buttons with data-uvalib-track.

Check and fix accessibility

Use the uvalib-web-components skill's accessibility testing guide to add a Playwright + axe test matched to Lighthouse and a Lighthouse CI config to this project, run them on the home, a list, a detail and the search page in light and dark at phone and desktop widths, and fix what they find. Report anything you couldn't test.

Ask for something the library doesn't have

Our pages need an accordion and the library has none. Use the uvalib-web-components skill to check the repo's issues for an existing request, then draft a new-component issue for uvalib/reusable-web-library (what it's for, our public page URLs, the library.virginia.edu pattern to match, accessibility needs). Show me the draft before filing it, and build a small accessible stopgap that links the issue.

Keep it current

Update the uvalib-web-components skill in this project to the latest release, then check whether anything we use changed and needs updating.

Installing the skill

npx fetches the package on the fly, so this works in any repository, including sites that only use script tags (it needs Node, not an npm dependency).

| Command | Installs to | | -------------------------------------- | ------------------------------------------------------------------------------- | | install-skill | .claude/skills/ and .agents/skills/ in this project | | install-skill --global | ~/.claude/skills/ and ~/.agents/skills/, for every project on this computer | | install-skill --agent gemini,copilot | each named agent's own folder (add --global for the home folder) | | install-skill --agent all | every folder below | | install-skill --dir <folder> | one folder of your choosing | | install-skill --list … | prints the folders it would use, and changes nothing |

| --agent | Project folder | Global folder | Read by | | --------- | ---------------- | ------------------- | ------------------------------------------------------------------------------------------ | | agents | .agents/skills | ~/.agents/skills | the shared Agent Skills folder: Codex, Gemini CLI, GitHub Copilot, Cursor, Grok and others | | claude | .claude/skills | ~/.claude/skills | Claude Code (also read by Copilot, Cursor and Grok) | | codex | .agents/skills | ~/.agents/skills | OpenAI Codex | | gemini | .gemini/skills | ~/.gemini/skills | Gemini CLI | | copilot | .github/skills | ~/.copilot/skills | GitHub Copilot (cloud agent, CLI, VS Code and other IDEs) | | cursor | .cursor/skills | ~/.cursor/skills | Cursor | | grok | .agents/skills | ~/.grok/skills | Grok |

The default (claude and agents) covers all of these. A tool that reads more than one of the folders (Copilot, Cursor and Grok read both .claude/skills and .agents/skills) may list the skill twice; the copies are identical, so it does no harm, or install for one folder with --agent. Agents check their folders when a session starts, so start a new session after installing. Add --force to replace an existing copy.

Other skills. The package also ships uvalib-presentations, for slide decks and talks with <uvalib-slides> (building, presenting, hosting, and converting impress.js or other HTML decks). The installer adds only uvalib-web-components unless you name others with --skill: install-skill --skill uvalib-presentations --global, --skill uvalib-web-components,uvalib-presentations, or --skill all (each folder in skills/). Each goes to <skills-folder>/<skill> with its own installed.json; --list shows where, and --check --skill … checks those skills.

Without the installer: copy node_modules/@uvalib/web-components/skills/uvalib-web-components into a skills folder, or point a chat assistant without skills at https://unpkg.internal.lib.virginia.edu/web-components/v1/skills/uvalib-web-components/SKILL.md. More in docs/usage.md.

Keeping the skill current

Each install is a copy stamped with its package version (installed.json next to SKILL.md), so it does not change as this library does. Update it after a release with the same options you installed with, plus --force:

npx @uvalib/web-components@latest install-skill --force            # or: --global --force

--check compares the installed copies with the latest release on npm. It prints one line per copy, with that update command, only when a copy is missing or out of date, is silent when they are current, and never fails offline (--strict exits 1 when one is out of date, for CI). To be told automatically, run it when your agent starts a session; for Claude Code, a SessionStart hook in the project's .claude/settings.json (or ~/.claude/settings.json with --global for the copies in your home folder):

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "npx --yes @uvalib/web-components@latest install-skill --check"
          }
        ]
      }
    ]
  }
}

Agents with their own session-start hooks can run the same command; otherwise run it with --strict in CI. Projects that commit .claude/skills/ and .agents/skills/ get each update as an ordinary reviewed change.

To do it by hand, read on.

Requests and bug reports

Ask for a new component, a feature or change in an existing one, or report a bug through the repository's issues. Each has a form: New component, Feature or change request and Bug report. The repository is public, so leave out passwords, tokens, internal-only hostnames and personal data. The agent skill knows the forms too: ask your agent to search the existing issues, draft one, and file it once you approve it (it uses the GitHub CLI, gh, or gives you the form's link).

Test results

Every push to main is tested before the examples site is published, and the results go up with it: test report. Lighthouse takes about half an hour, so it runs alongside: the site goes up as soon as the tests pass, showing the previous Lighthouse results (marked as from an earlier commit), and is published again with this commit's when the audit finishes. It lists:

  • Tests: every build and package test (Node) and every component test (Chromium), file by file, with each test's outcome.
  • Accessibility: the axe-core checks, in shadow and light DOM, light and dark, held to WCAG 2.2 AA plus the extra rules Lighthouse enables. Lighthouse must also score 100 for accessibility on every example.
  • Lighthouse: each example page's median performance, accessibility, best-practices, layout-shift and blocking-time results, against the budgets in Quality checks.

The badges above read the same report (report/results.json has the numbers for scripts). Locally, pnpm test, pnpm lhci and pnpm report write it to dist-site/report/.

Playground

Try every component and mode, edit the code, and share a link: https://uvalib.github.io/reusable-web-library/

The page is built with the library itself. Its header's main navigation is the examples menu: one group per component (Page, Header, Alerts, Search, Hours, Events), above one editor with a live preview; on phones the groups are accordions in the header's Menu. Each example has its own link, such as #weekly-hours. Copy link puts your edited files in the URL (#files=…), so the link opens with your changes; Reset goes back to the example. Old playground.html links, share links included, redirect to the page. The page also has dark mode: Light, Dark or System in the header (in the Menu on phones) switches the page and the editor; the previews run on another origin, so they keep their own scheme.

Install

CDN script tag (plain HTML, 11ty, Drupal templates)

<link rel="stylesheet" href="https://unpkg.internal.lib.virginia.edu/web-components/v1/base.css" />
<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/site-page.js"
></script>
  • https://unpkg.internal.lib.virginia.edu/web-components/v1/<tag>.js is the major alias. It follows releases within major 1 and is cached for about 5 minutes.
  • https://unpkg.internal.lib.virginia.edu/web-components/vX.Y.Z/<tag>.js is an exact, immutable version. Use it to pin.
  • tokens.css and base.css live at the same prefix (.../v1/tokens.css), and so does analytics.js, the analytics helpers for a page's own scripts (trackEvent, trackSearch, createSearchTracker; no element, no Lit; see Analytics).
  • Never use the legacy /web-components/latest/ or /web-components/cdn-v* paths; they belong to the old components. See migration.
  • site-page.js also loads the header and footer. For Matomo, give <site-page> a matomo-id (it then loads the analytics code itself), or add site-analytics.js and a <site-analytics> element; see Analytics.
  • Link base.css in <head> too. <site-page> installs the same page-level base styles itself, but only after the first paint, so without the link the page jumps once: the browser's default body margin goes away, and a heading's top margin stops collapsing through the not-yet-upgraded <site-page> (layout shifts Lighthouse counts on every page). With the link, <site-page> also stays invisible until its script has run, so its content never paints above where the header goes; if the script fails to load, the content appears anyway after two seconds. Sites with no-global-styles skip base.css, as that attribute turns those styles off.

npm (bundled apps)

npm i @uvalib/web-components
import '@uvalib/web-components/site-page.js'; // registers site-page, site-header, site-main-nav and site-footer

The define entries are site-page.js, site-header.js, site-main-nav.js, site-footer.js, site-analytics.js, uvalib-analytics.js, site-style.js, uvalib-filter.js, uvalib-date-range.js, uvalib-date-histogram.js, site-hours-section.js, library-weekly-hours.js, library-hours-setup.js, events-section.js, bento-box.js and uvalib-pagefind-search.js. The package root (import '@uvalib/web-components') exports the classes only and registers nothing. To use a class such as SitePage directly, also import the define entries. CSS is available as @uvalib/web-components/tokens.css, base.css and pagefind.css (the Pagefind theme, see Static-site search). @uvalib/web-components/analytics.js has the analytics helpers on their own (base.js exports them too). Do not load the same component from both the CDN and npm on one page.

Quick start

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Example page</title>
    <link
      rel="stylesheet"
      href="https://unpkg.internal.lib.virginia.edu/web-components/v1/base.css"
    />
    <script
      type="module"
      src="https://unpkg.internal.lib.virginia.edu/web-components/v1/site-page.js"
    ></script>
  </head>
  <body>
    <site-page>
      <h1>Example page</h1>
      <p>Page content goes here. Do not add a second main element.</p>
    </site-page>
  </body>
</html>

Use one <site-page> per page. It renders the skip link, the header, a single <main id="main-content"> and the footer around your content, so do not add your own <main>, skip link, header or footer. Put content for a band above the footer in an element with slot="pre-footer". Tool and app-like pages where the site footer does not belong (such as this repo's examples page) add no-footer, which hides the footer and any pre-footer band. Live library alerts are shown by default (see Alerts). Third-party sites use <site-page header-variant="vendor">. Links default to root-link-domain="https://www.library.virginia.edu".

Caveat: replacing a light-mode <site-page>'s children wholesale (innerHTML or textContent) destroys the chrome. Append content, or update a container inside it.

Site navigation

A site with its own navigation puts it in the header instead of the library utility links (My account, Ask a Librarian, Hours, Give, Alerts, Search). Give <site-page> (or a standalone <site-header>) <a slot="site-links"> children:

<site-page site-links-label="Web components">
  <a slot="site-links" href="./" aria-current="page">Examples</a>
  <a slot="site-links" href="https://github.com/uvalib/reusable-web-library#readme">README</a>
  …page content…
</site-page>

The links replace the utility links in both the inline nav on wide screens and the Menu popover on narrow ones, in order. Their href is used as written (not joined to root-link-domain), and aria-current, target, rel and hreflang are kept; mark the current page with aria-current="page", which is shown bold with a thick underline. site-links-label names the nav (default Site; the popover's nav is "… menu"). Adding, removing or editing the links later updates the header. Children that are not <a href> with text (a link with empty or whitespace-only text has no accessible name) are ignored with a console warning. Without site links the header is unchanged. The vendor header variant ignores site links and keeps its reduced link set.

Site name

A sub-site (Electronic Text Collections, a digital exhibit, a project site) names itself in the header with site-name on <site-page> (or a standalone <site-header>):

<site-page site-name="Electronic Text Collections" site-name-href="/">…page content…</site-page>

The name sits after the library logo, past a thin divider, in the header's text colour, as a link to the site's home: site-name-href, default /. The logo still links to library.virginia.edu. The links have distinct names, each starting with its visible text (for voice control): "UVA Library home" and "Electronic Text Collections home". The name is not a heading, so the page keeps its own <h1>. On wide screens it shares the logo row and wraps to at most two lines without making the header taller, so keep it short (about 30 characters fit on one line from 1200px). When the links would not fit beside it on one line (with color-scheme-switch, or many site links, mostly between 993px and 1199px), the name moves under the logo, as on phones, so the links are laid out exactly as without a name and never overflow; the header is then taller by the name's lines. At 992px and below it gets its own lines under the logo, so it wraps cleanly on phones with no horizontal scroll. It works in light DOM and with the vendor variant (a vendor-hosted site can name itself too). A click reports ['site-header', 'site-name-click']. Without site-name the header is unchanged.

Main navigation

Every full header shows the UVA Library main navigation, as on library.virginia.edu: About, Using the Library, Research & teaching support and Get help. It is on by default for <site-page> and a standalone <site-header>, with or without site links. Above 992px it is a full-width row under the logo row, with the brand-blue rule under it; at 992px and below it leads the Menu popover as accordions, above the utility or site links. The vendor header variant never shows it.

  • Turn it off with no-main-nav on <site-page> or <site-header>. The header is then exactly what it was before the main navigation existed.

  • Its name is "Main" (main-nav-label changes it). Exactly one main navigation landmark is visible at a time: the row above 992px, the accordion inside the open Menu popover at 992px and below (and none while the popover is closed).

  • Replace its links, in this order of precedence:

    1. A <nav slot="main-nav"> child of <site-page> or <site-header>. <li><a href> is a direct link; <li><span>Group</span><ul><li><a href>…</a></li></ul></li> is a group. The source markup stays hidden; adding, removing or editing it later updates the header. Invalid entries are skipped with one console warning, and links nested deeper than a group are shown in their group.
    2. The items property of a standalone <site-main-nav> (MainNavItem[]: { label, href } or { label, items: [{ label, href }] }). <site-page> and <site-header> have no such property; use the slot or main-nav-src there.
    3. main-nav-src on <site-page> or <site-header> (items-src on <site-main-nav>): a URL of JSON in the same shape, which needs CORS. The bundled menu shows until it loads. It is tried twice, a second apart, and each attempt times out after 10 seconds. If both fail (network errors, timeouts, or no valid entries), after about 21 seconds at worst, the bundled menu stays and site-main-nav-error is fired once, with detail { src, message }.
    4. Otherwise: the bundled snapshot of the live menu.

    The examples page is a working example: its main navigation is a slotted <nav> of #<id> links, one group per component, generated from its presets at build time (site/src/main-nav.ts).

    <site-page>
      <nav slot="main-nav">
        <ul>
          <li><a href="/exhibits">Exhibits</a></li>
          <li>
            <span>Collections</span>
            <ul>
              <li><a href="/collections/maps">Maps</a></li>
            </ul>
          </li>
        </ul>
      </nav>
      …page content…
    </site-page>
  • Links: relative hrefs are joined to root-link-domain; absolute ones are kept as written, and fragment-only ones (#…, a hash route) stay on the page. A plain click on a link closes the open group and the Menu popover, so a single-page app that handles the navigation in place leaves nothing open; a modified click (new tab or window) does not.

  • Keyboard: it is a disclosure navigation (buttons with aria-expanded and lists of links), not an ARIA menu, so Tab moves through everything as usual. Click, Enter or Space opens or closes a group, and only one is open at a time. Escape closes it and returns focus to its button. ArrowDown on an open group's button moves into its links; the arrow keys, Home and End move between the group buttons and between a group's links. On wide screens a group also closes when focus leaves the navigation or on a click outside it. Nothing opens on hover.

  • Current page: the link matching the page's URL (host and path; the query, the hash, a trailing slash and a leading www. are ignored) gets aria-current="page", and its group's button aria-current="true". Both are shown bold with a thick orange underline, not by colour alone. When two links differ only by hash, one is marked: the one with the page's hash, else the one without a hash; if every one has a hash, the first while the page has none, and none for a hash none of them has (a hash route the menu does not list). The marking follows same-document navigations (popstate, hashchange, and the Navigation API's currententrychange where the browser has it), so a single-page app that changes the URL needs nothing more. An app whose route is not its URL sets main-nav-current on <site-page> or <site-header> (current on <site-main-nav>) to the URL to mark; while it is set, the location is not followed.

  • Keeping it current: the menu is a snapshot of the desktop "Main navigation" menu on library.virginia.edu, committed in src/components/site-main-nav/main-nav-data.ts. There is no runtime fetch. pnpm sync:main-nav regenerates it from the live home page (the desktop menu is canonical; Drupal's separate "Mobile Main Nav" menu has drifted and is ignored). Review the diff and release.

  • Accessibility: focus rings sit inside the controls and keep 3:1 contrast (orange on white, brand blue on the grey of a hovered or open group). In forced-colors mode the open panel keeps an edge and the open group and hovered controls are outlined.

  • Header height: above 992px the header is about 54px taller (the main navigation row). At 992px and below it is unchanged.

Alerts

<site-page> shows live UVA Library alerts by default, drawn by this library's <site-alerts> in library.virginia.edu's look. The data comes from the alerts project: its <uvalib-alerts> element, released separately and loaded at runtime from the alerts CDN, now only provides the data (alerts, live updates, dismissals and regional matching), used headless; its own UI is no longer rendered. One <script type="module" src="{base}v1/uvalib-alerts.js"> is added to <head>, once per document however many pages there are, and not at all if <uvalib-alerts> is already defined or a script with that src is already present. <site-alerts>' own code is loaded only while alerts are on.

| Attribute | Default | | | ------------ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- | | alerts-env | production | production or staging. Any other value logs one console warning and uses production. | | alerts-src | | Base URL holding config.json, alerts.json and v1/uvalib-alerts.js. Overrides alerts-env; for a custom domain, local development and tests. | | no-alerts | off | Render no alert elements and load no script. |

The bases are https://d2q6t6fdv76k7r.cloudfront.net/ (production) and https://dzfvxb8mejnv6.cloudfront.net/ (staging), exported as ALERTS_PRODUCTION_SRC and ALERTS_STAGING_SRC; they move to alerts.lib.virginia.edu and alerts-staging.lib.virginia.edu once those names exist. The vendor header variant gets the same default.

Alerts render where Virgo shows them, inside landmarks: the header banner (<site-alerts show="header">) full-bleed at the very top of the header (flush with its top and both edges, after the skip link and before the logo row); the alert list (show="list") in a full-bleed band directly under the header and above <main>, a <section class="alerts-list" aria-label="Library alerts"> region that is hidden while the list has nothing to show; and the page-targeted regional alerts (show="regional") as the first child of <main>, inside its padding and before your content. <main>'s own padding is unchanged. <site-header> has an alerts slot for the banner, but a standalone header never loads anything. Changing no-alerts later adds or removes the alerts. Changing alerts-env or alerts-src later re-points the alerts at the new base without loading the code again. alerts-src is resolved against the document's base URL, with any query or hash dropped. If the script fails to load, one console warning is logged per URL, nothing is shown, the page is otherwise unchanged, and a later corrected alerts-src or env (or another page) tries again. In light mode (no-shadow-dom) these are real children (<site-alerts no-shadow-dom>): the regional one is the first child of <main>, the banner the first child of the header's <header>, and the section.alerts-list band sits between <site-header> and <main>, so host CSS such as main > :first-child or site-header + * matches them.

The look and accessibility (WCAG 2.2 AA, and AAA for alerts as the Library's web standard asks):

  • Header banner: teal, centred, the title in bold then ":", a polite role="status".
  • List alerts, most severe first: critical (red), warning (yellow) and information (blue), each with a 10px left border, the theme's severity icon (decorative) and a visually hidden "Critical:", "Warning:" or "Information:" before the title, so severity is never colour alone. Titles are <h2> (as on library.virginia.edu; heading-level changes them on a <site-alerts>). Only critical alerts are an assertive role="alert". Warning and information alerts have a 44px dismiss button, aria-label="Dismiss alert: <title>"; after a dismissal focus moves to the next alert (its button) or, with none left, to <main>, never to <body>. Information alerts stay listed until the reader closes them, as on library.virginia.edu (the alerts service marks them "seen" on arrival, Virgo's rule for its Alerts menu, so <site-alerts> keeps its own per-site record of what was closed, in localStorage under <storage-key>:site-alerts-closed); a closed warning is also dismissed in the alerts service. Closings are per site and sync across tabs.
  • Regional alerts: yellow (warning) or teal (information) boxes with a visually hidden severity.
  • Text is 7:1 or more on every alert background in light and dark (body text 10.1–13.0:1 light, 8.0–12.0:1 dark), icons follow the text colour, and the focus ring is the text colour on the alert's background. Under forced colors every alert keeps a system-colour border. library.virginia.edu's yellow and teal borders are decorative (1.7:1 and 2.0:1 on white); the icon, the hidden label and the background carry the alert.
  • Alert bodies are server-sanitized HTML; where the browser has setHTML() it re-applies the alerts project's allowlist.

<site-alerts> on its own. Pages without <site-page> can use the element directly (site-alerts.js; npm @uvalib/web-components/site-alerts.js): show is header, list, regional, sitewide (header and list) or all (default), with alerts-env, alerts-src, heading-level, storage-key (the localStorage key for dismissals), no-shadow-dom and no-style. However many there are, one hidden headless <uvalib-alerts> per document (per base and storage key) feeds them all; the first <site-alerts> creates it at the end of <body> and the last one removes it. Sites that used the alerts project's UI (<uvalib-alerts show="…"> with its script) can switch to <site-alerts show="…"> with site-alerts.js; drop their own uvalib-alerts.js script, which <site-alerts> loads itself.

Do not add another <site-alerts> or <uvalib-alerts> inside a <site-page>. An app that renders alerts itself (Virgo uses the component headless) sets no-alerts.

Content Security Policy: a site with a CSP must allow the alerts host in script-src (the component) and connect-src (config.json and alerts.json), plus the AppSync realtime socket in connect-src:

script-src  https://d2q6t6fdv76k7r.cloudfront.net;
connect-src https://d2q6t6fdv76k7r.cloudfront.net wss://*.appsync-realtime-api.us-east-1.amazonaws.com;

(Use the staging host, or your alerts-src host, instead where that applies.) Alert bodies can include images, so allow their hosts in img-src too. Alert bodies are inserted as HTML, so a page that enforces Trusted Types (require-trusted-types-for 'script') is incompatible with the alerts; use no-alerts there.

Printing

When a visitor prints a page (meeting minutes, a finding aid, an article), <site-page> prints only the content: the skip link, the header (with the main navigation and the header alert), the alert list band, the regional alerts, the breadcrumbs, the pre-footer band and the footer are left out, and <main> loses its side gutters. The content prints black on white, a dark scheme prints light, and the content's links are black and underlined, so they are told apart without colour. A short line above the content says where the page came from: “UVA Library — ” followed by the site-name (or else the page's <title>) and the page's URL, refreshed just before printing so a single-page app prints its current route. It is CSS generated content in a print-only rule, so screen readers never meet it on screen.

<!-- Print the page as it is shown, header and footer included. -->
<site-page print-chrome> … </site-page>
  • print-chrome keeps the header, alerts, breadcrumbs and footer in print (the scheme still prints light).
  • Both modes: the rules are in <site-page>'s own styles (shadow or no-shadow-dom); the link colours and the light scheme come from the page-level base styles, so with no-global-styles the links keep your own print colours. With no-style none of this applies: print styles are yours.
  • Your own print rules still apply: hide a sidebar or a back-to-top button of your own with @media print { … }. Browsers print the title and URL in the page margins too unless the visitor turns that off.

Breadcrumbs

<uvalib-breadcrumbs> is the breadcrumb trail, with library.virginia.edu's look (slash separators, underlined --uva-blue-alt-dark links) at body size (1rem), as the design system asks. Entry: uvalib-breadcrumbs.js on the CDN, @uvalib/web-components/uvalib-breadcrumbs.js on npm. Inside <site-page> give it slot="breadcrumbs" and load both scripts:

<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/site-page.js"
></script>
<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-breadcrumbs.js"
></script>
<site-page>
  <uvalib-breadcrumbs slot="breadcrumbs">
    <a href="/">Home</a>
    <a href="/research-and-teaching">Research &amp; teaching support</a>
    <span>Writing &amp; publication</span>
  </uvalib-breadcrumbs>
  <h1>Writing &amp; publication</h1>
</site-page>
  • Markup. A <nav aria-label="Breadcrumb"> (label changes the name) holding an <ol>, one <li> per step. The slashes are aria-hidden elements, so screen readers do not read them. The last step is the current page: a <span aria-current="page">, or a link with aria-current="page" when it has an href.
  • The trail as children. <a href> children, ending with the current page as a text-only element (<span>Writing</span>) or a link (<a href="…" aria-current="page">). The last child is always the current page; an earlier child without an href is shown as plain text (a level with no page of its own). Hrefs are used as written (relative, hash routes); an href with another scheme than http(s), mailto: or tel: (such as javascript: or data:) makes that step plain text, with one console warning. Children with no text, and bare text, are skipped with one console warning. The trail follows changes to the children (added, removed, href and text), so a single-page app can rewrite them on each route. An empty trail renders nothing and, in <site-page>, takes no space.
  • Back to the search. On a record reached from search results, give the Search crumb data-return-from with the search page's path (or several, separated by spaces): <a href="/" data-return-from="/">Search</a>. When the visitor came from that page on the same site with a query string (document.referrer; a trailing slash or index.html does not matter), the crumb links back to that search (/?q=budget&date_start=2023) instead of a blank one; its text stays the same. Otherwise (a new tab, another page, another site, no query, or a Referrer-Policy that sends no path) it keeps its href. Nothing is stored or sent. Referrers never carry the hash, so a hash-routed search cannot be returned to this way. In items the same is returnFrom. No inline script rewriting the crumb is needed.
  • Single-page apps. The trail is drawn from copies of the children, so a router's own click handlers on them don't run. A plain click on a trail link fires uvalib-breadcrumbs-navigate (detail: { href, index }, bubbling, cancelable): cancel it with preventDefault() and navigate in the app (the click's own navigation is then prevented). Hash links need nothing.
  • The trail as data. Apps that build it in JavaScript (React, Vue) set the items property: el.items = [{ label: 'Home', href: '/' }, { label: 'Search' }]. While set it wins over any children; assign a new array to change it, undefined to go back to the children. Entries without a label are skipped with one warning.
  • Placement. In <site-page> the trail sits where library.virginia.edu puts it: after the header and the alert list band, before <main> and outside it, so the skip link lands past it, lined up with <main>'s content (same max width and 40px side padding, 16px above). In light mode (no-shadow-dom) it is moved there as a real child of <site-page>, never into <main>. Without a slot="breadcrumbs" child the page is unchanged. Elsewhere it is an ordinary block: put it first in the page content, above the <h1>.
  • Styles. Links --uva-color-utility-link (else --uva-blue-alt-dark, #005679, as on library.virginia.edu), underlined; a linked current page in the text colour; the slash in --uva-color-text-muted (else --uva-grey-dark); the current page in the text colour; the library focus ring. Long trails wrap (no horizontal scroll at 320px). It follows dark mode through the role tokens. no-style keeps only the structure (an inline list without bullets or indent, the separators' spacing); light DOM styles are scoped to the tag in @layer uvalib, so a site's own CSS wins.

Cards

<uvalib-card> is one summary: a collection (title and “N texts”), a photo, or anything similar. <uvalib-card-grid> lays those cards out. <uvalib-pager> is the previous/next row on a reading page, or a numbered page list. Entries: uvalib-card.js, uvalib-card-grid.js and uvalib-pager.js on the CDN, and the same paths under @uvalib/web-components/ on npm.

<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-card.js"
></script>
<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-card-grid.js"
></script>
<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-pager.js"
></script>
<site-page>
  <h1>Collections</h1>
  <uvalib-card-grid>
    <uvalib-card href="/collections/early-american-fiction/">
      <span slot="heading">Early American Fiction</span>
      128 texts
    </uvalib-card>
  </uvalib-card-grid>
  <uvalib-pager
    prev-href="/text/eaf375v1/d8/"
    prev-label="The opening"
    next-href="/text/eaf375v1/d10/"
    next-label="What follows"
  ></uvalib-pager>
</site-page>
  • A clickable card. href makes the heading the link, and a CSS pseudo-element stretches that link over the card, so the whole card is one destination. The arrow is only a visual aid. Never wrap the card in an <a>. A clickable card must not contain another link, button or other control: the stretched link would cover it, and a link inside a link is invalid. The heading needs an accessible name (text, or an image alt or label); otherwise the link is hidden. A static card (no href, or an empty or unsafe one such as javascript:) has no stretch, so its excerpt may contain links. An unsafe href is shown as plain text, with one console warning.
  • Slots. media (an <img> with a real alt, or alt="" when the heading already names it), badge (for example “13 photos”, over the image), heading, meta (a date in <time>, or a byline), chip (one element per category), actions (links or buttons on a static card, such as “Read the story” and “Photos (132)”) and the default slot for the excerpt. A clickable card must not contain an actions row: the stretched link would cover those controls, and the card warns once.
  • Circle media. media-shape="circle" draws the media as a centered circle for a person or avatar. The image keeps its alt, and the count badge still sits on it. Any other value is ignored, with one warning.
  • Heading level. Unset, it is one below the nearest heading before the card, or 3 when there is none (the same rule as <events-section>). heading-level (1–6) wins.
  • The grid. A list, so a screen reader announces how many cards there are. Columns follow the grid’s own width: four above 992px, two through 767px, then one. Cards in a row match the tallest. min-card-width (a length such as 16rem) switches that to auto-fill / minmax; anything else is ignored, with one warning. Only <uvalib-card> children are listed.
  • Previous/next. prev-href and next-href (either may be omitted; with neither, nothing is rendered). Each link shows a “Previous” or “Next” kicker and, when set, prev-label or next-label. A long title truncates; the full text stays in the accessible name. The links use rel="prev" and rel="next". The landmark’s name is label, or “Sections”.
  • Numbered pages. Set pages (a positive count; it wins over previous/next, with one warning if those are set too). page is the current page, clamped to that range, and is text with aria-current="page", not a link. Other pages use href-template, which must contain {page} (the default is ?page={page}). A long range keeps the first page, a window around the current page, the last page, and an ellipsis where numbers are skipped. The landmark’s name is label, or “Pagination”.
  • One landmark name. Two pagers with the same accessible name fail the accessibility check. Give the second a different label.
  • Before the script runs. base.css draws the pager invisibly from its attributes, laid out as it will be, so the text under a top pager does not move when it upgrades. Put the titles in prev-label and next-label (not set later from script) for the hold to be exact. Numbered pages are exact except near the end of a long range on a container of about 280–310px. For load more, set has-more="false" on the last page: without it the button's room is held. If the script never loads, the space stays empty (nothing is shown that is not a link).
  • Load more. mode="load-more" replaces the landmark with a group: a “Load more” button (.uvalib-button) and a polite “Showing N of M” (shown and total). It wins over numbered pages and previous/next, with one warning when those are also set. The button hides once shown has reached a positive total. Without a known total (ranked or semantic search), leave total unset (or 0): the count reads “Showing N” and the button stays. Add has-more while there is more and remove it (or set hasMore = false; has-more="false" also works, for templates that print false) after the last page. Once set, has-more alone decides whether the button shows, over total; hasMore = undefined returns to following total. It is one flag rather than a has-more/no-more pair, so the two can never contradict each other. If the button goes away while it has focus and loaded() was not called first, focus moves to the first new item of the for list, or else to the count, never to the page. page is the last loaded page (default 1). A click fires load-more with { page } set to the next page. Call loaded(firstNewElement), or set for to the list’s id and call loaded(), and focus moves to that new item (an element that cannot take focus gets tabindex="-1"). The group’s name is label, or “More results”.
  • Single-page apps. A plain click fires uvalib-card-navigate (detail: { href, position }) or uvalib-pager-navigate (detail: { href, kind, page? }). Cancel it with preventDefault() and route in the app. position is 'single' or '1', '2', …. kind is 'next', 'previous' or 'number', and page is set only for 'number'.
  • Styles. A raised surface, a 1px border, and on hover or focus the shadow 0 0 20px 0 #DADADA. Focusing the heading link draws the focus ring on the card. The chip is --uva-blue-alt-300 on --uva-blue-alt-dark (6.13:1: WCAG AA for normal text, short of AAA’s 7:1). Dark mode follows the role tokens. no-style keeps the stretch, the grid and the truncation, and drops the colours.

Chips

<uvalib-chip-group> is a row of chips: a segmented control or single-select filter (a year rail, a sort toggle), filter chips that toggle, or suggestion chips that go somewhere. Entry: uvalib-chip-group.js on the CDN, @uvalib/web-components/uvalib-chip-group.js on npm.

<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-chip-group.js"
></script>
<uvalib-chip-group label="Year" count-label="shoots" value="" scroll url-param="year">
  <button value="" data-count="3694">All Years</button>
  <button value="2004" data-count="213">2004</button>
  <button value="2005" data-count="461">2005</button>
</uvalib-chip-group>
<uvalib-chip-group label="Sort by" segmented value="photos">
  <button value="photos">Most photos</button>
  <button value="date">Date</button>
  <button value="title">Title A–Z</button>
</uvalib-chip-group>
<uvalib-chip-group
  label="Search by"
  segmented
  value="keyword"
  description="Keyword matches your words. Meaning finds meetings about your topic, even when the minutes put it differently."
>
  <button value="keyword">Keyword</button>
  <button value="meaning">Meaning</button>
</uvalib-chip-group>
<uvalib-chip-group mode="multi" label="Category" value="traditions">
  <button value="traditions" data-count="9">Traditions</button>
  <button value="sports" data-count="21">Sports</button>
</uvalib-chip-group>
<uvalib-chip-group mode="links" label="Suggested searches">
  <a href="/search?q=snow+on+the+Lawn">snow on the Lawn</a>
</uvalib-chip-group>

A colour key: data-swatch (or swatch in items) draws a small square of that colour before the label, so the filter chips double as a chart's or map's legend.

<uvalib-chip-group mode="multi" label="Category" count-label="photos" value="athletics">
  <button value="athletics" data-count="4203" data-swatch="#e57200">Athletics</button>
  <button value="architecture" data-count="1180" data-swatch="#232d4b">Architecture</button>
  <button value="traditions" data-count="912" data-swatch="#25cad3">Traditions</button>
</uvalib-chip-group>
  • Modes. single (the default): native radios drawn as chips in a role="radiogroup". Tab enters at the selected chip and the arrow keys move and select, as in any radio group; value is a string. multi: toggle buttons with aria-pressed; value is an array (comma-separated as an attribute). links: links (or, without href, buttons) that fire select and have no selected state.
  • Chips. Children: <button value data-count> (the value falls back to data-value, then the text; disabled disables), or <a href> in links mode (an unsafe href such as javascript: makes the chip plain text, with one warning; an empty one makes it a button). Or set items ([{ value, label, count?, href?, disabled?, swatch? }]), which wins over the children while set. The chips follow changes to the children.
  • Description. description is a hint shown under the chips in small muted text and tied to the group (the radiogroup, or the group in multi and links) with aria-describedby, so a screen reader reads it when focus enters the group. It is an attribute, not a slot, on purpose: the text lives in the element's own root next to the group, so the reference works in shadow DOM (an aria-describedby from the page cannot reach into a shadow root, nor out of one) and in light DOM (a unique id). It is plain text, so it cannot hold a link; put a longer explanation with links next to the element. Works in every mode, with segmented, scroll and no-style; before the script loads base.css holds a line for it.
  • Names. label names the group and is required (one console warning without it). A count is shown smaller and muted, and read as part of the chip's name: “2005, 461 shoots” with count-label="shoots" (default “items”). Numbers are formatted for the page's language.
  • Swatches. data-swatch / swatch is any CSS colour (checked with CSS.supports; an invalid one is ignored with one console warning) and is set as a style property, never as CSS text. The square is decorative (aria-hidden="true", part="swatch"): the chip's name stays its label and count, so the colour is never the only cue; keep the chart's or map's own labels, and use the same label text in both. Its 1px border is the chip's text colour, so it shows against the chip unselected, selected, disabled and in dark mode (at least 3:1, WCAG 1.4.11), and the chip keeps its height. In forced colors the square keeps its real colour (forced-color-adjust: none on the square only, since it must match the chart or map, which forced colors leave alone in a canvas or image) with a system-colour border. It works in every mode, with segmented and scroll, and with no-style.
  • Events. change (detail: { value }) on the visitor's change only, never when the app sets value; select (detail: { value, href? }) in links mode, cancelable for a plain click on a link: cancel it to route in a single-page app. Both bubble and are composed.
  • Before the script loads. base.css hides each <uvalib-chip-group> and holds one row's height (44px, or the scrolling row's), so nothing below moves when it upgrades; the raw children show after two seconds if the script never arrives.
  • Look. The <uvalib-filter> scope chip (a pill with a grey border and blue text, filled blue when selected), with a tick on the selected chip so the state never rests on colour alone. segmented joins the chips into one bar like the header's Light / Dark / System control; it stays on one row. Each chip is a target at least 44px square; the visible pill is 36px. Chips wrap on narrow screens. scroll keeps them on one row that scrolls sideways: the scrollbar stays visible, the edge with more chips fades out, focus scrolls a chip into view, and Tab moves on past the group (no trap). Dark mode follows the role tokens; in forced colors the selected chip is Highlight. no-style keeps the layout, the targets and the hidden radios.
  • Address. url-param="year" keeps the value in the query (?year=2005; inside the hash on a hash route such as #/series?year=2005 or #chapter?year=2005; a multi value comma-separated). It is read on connect. The markup's value stands for the address without the parameter; any other value is written, an empty one as ?year=. Each change is one pushState: in multi at once, in single once the visitor settles (a second after the last change, so arrowing through a year rail adds one entry, and none when they end where they started). Back and Forward are followed and fire change with restored: true; a change still settling is dropped. With <site-analytics spa="auto"> each push is one page view.
  • Analytics. change with <label>: <chip label> and the count as the value (single: once the visitor settles, a second after the last change, and not when they end where they started); select with the group's label only, never the chip or its URL.

Tabs

<uvalib-tabs> is a tab set. Each direct child with data-tab is a panel (the attribute is the tab’s label; give the panel an id), or pair <button slot="tab"> labels with the panels in order. Entry: uvalib-tabs.js on the CDN, @uvalib/web-components/uvalib-tabs.js on npm.

<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-tabs.js"
></script>
<uvalib-tabs url-param="tab">
  <section data-tab="Events" id="events">
    <h2>Events</h2>
    <p>Upcoming.</p>
  </section>
  <section data-tab="Stories" id="stories">
    <h2>Stories</h2>
    <p>From the archive.</p>
  </section>
</uvalib-tabs>
  • Roles and keys. The component renders tablist, tab and tabpanel, with aria-selected, aria-controls and aria-labelledby. Arrow keys move (they wrap, and they flip in right-to-left), Home and End jump. Selection follows the arrow unless activation="manual", which waits for Enter or Space. Only the selected tab is in the tab order.
  • Selection. selected is the panel id (a label or a 0-based index is accepted and rewritten to the id). A change event carries { id, label, index }. The first panel is visible before the element upgrades, and a hidden panel is not in the accessibility tree.
  • Linkable tabs. url-param keeps the selected id in the query string, or inside the hash on a hash route. url-param="hash" uses a bare #panel-id. Opening from a URL that already names a tab does not rewrite it. Back and Forward restore the tab. Nothing is written on the first render.
  • Phone. The tabs wrap onto more than one line. Each tab stays at least 44px.
  • Analytics. A visitor’s click or key reports ['uvalib-tabs', 'change', '<tab label>']. The label is capped at 100 characters. Nothing is reported on render, on requestUpdate, or when Back restores a tab.

Contents and record metadata

Two components for Library sites with records and long texts, such as the Electronic Text Collections. Entries: uvalib-contents.js and uvalib-metadata.js on the CDN, @uvalib/web-components/uvalib-contents.js and @uvalib/web-components/uvalib-metadata.js on npm.

<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-contents.js"
></script>
<script
  type="module"
  src="https://unpkg.internal.lib.virginia.edu/web-components/v1/uvalib-metadata.js"
></script>
<uvalib-metadata
  creator="Smith, Richard Penn"
  rights="http://rightsstatements.org/vocab/NoC-US/1.0/"
  rights-info="https://www.library.virginia.edu/policies/use-of-materials"
  citation-title="The actress of Padua, and other tales"
>
  <dl>
    <dt>Date</dt>
    <dd>1836</dd>
    <dt>Subjects</dt>
    <dd>
      <ul>
        <li>Short stories</li>
        <li>American literature -- 19th century</li>
      </ul>
    </dd>
    <dt>Download</dt>
    <dd>
      <ul>
        <li><a href="eaf375v1.epub" download data-size="184 KB">EPUB</a></li>
        <li><a href="eaf375v1.txt" download data-size="369 KB">Plain text</a></li>
      </ul>
    </dd>
  </dl>
</uvalib-metadata>
<uvalib-contents sticky>
  <ol>
    <li><a href="/text/eaf375v1/d3/">Preface</a></li>
    <li>
      <a href="/text/eaf375v1/d8/">The actress of Padua</a>
      <ol>
        <li><a href="/text/eaf375v1/d9/">Part I. The Key</a></li>
        <li><a href="/text/eaf375v1/d10/">Part II. The Crucifix</a></li>
      </ol>
    </li>
  </ol>
</uvalib-contents>

<uvalib-contents>, sub-navigation as on library.virginia.edu:

  • Markup. A <nav> landmark named by label (default "Contents"), with the label as a visible headline (<h2>; heading-level 2 to 6), then the nested list: dividers between the top-level entries, a bar beside each nested level, links in --uva-color-utility-link (else #005679) and the library focus ring. Every link is at least 24px tall.

  • The list as a child. One <ol> or <ul> of <li>, each with an <a href> (or plain text, for a group label) and, for sub-entries, a nested <ol>/<ul>, to any depth. Other children (a heading) are ignored; entries with no text are skipped with one console warning; hrefs other than relative, http(s), mailto: and tel: become plain text. lang and dir on the links and items are kept, and so is inline markup in the text (em, cite, code, abbr…, copied element by element with only lang, dir and an abbr title; never parsed as HTML). It follows changes to the children. Apps set the items property instead: [{ label, href?, children? }], winning over the children while set.

  • From the page's headings. For a long document (minutes, transcriptions, reports, finding aids), headings-from="#article" builds the list from the headings in that element: levels (2-3 by default, or one level such as 2) picks which, each lower level nested under the heading before it, and min (default 2) is the fewest top-level entries worth a list (fewer shows nothing). Headings with no text or hidden with aria-hidden (and text inside aria-hidden, such as a # permalink) are skipped. A heading without an id gets one from its text (lowercase ASCII, accents dropped, anything else as -: "Résumé of the budget" is resume-of-the-budget, a repeat -2, -3); existing ids are kept, so links to sections keep working, and opening the page at such a section goes to it. Headings added, removed or retitled are followed; call refresh() after other changes. A child list or items wins while given. Without JavaScript there is no list: where the list can be rendered at build time, give it as children instead.

  • Current entry. aria-current="page" on the link to this page and aria-current="location" on the link to the section in the URL's hash, drawn bold with a bar. It is found from the page URL (path, ignoring a trailing slash or index.html, and hash; an entry whose href has a query string, such as ?part=2, matches only that query, one without matches whatever the query), followed through hashchange, popstate and the Navigation API, or from current (a URL, for apps whose route is not the page URL; hash-only entries are then places on that URL). With current unset, a valid aria-current the author put on a source link (page, location, or true for a page) is used, at most one of each.

  • Narrow screens. At and below collapse-below (a viewport width, default 64rem; 0 never collapses) the headline becomes a full-width 44px button with aria-expanded and aria-controls, and the list starts closed until the reader opens it (as the Electronic Text Collections' Contents does on phones, so the text comes first; the open attribute starts it open), and opening it shows the current entry. It measures the viewport, not the element (no container query) on purpose: a contents sidebar is always much narrower than 64rem, so its own width cannot tell a phone from a desktop.

  • Sidebars. sticky keeps it in view on wide screens (--uvalib-contents-sticky-top, default 1rem); the list then scrolls within the window's height (--uvalib-contents-max-height) and the current entry is scrolled into view inside it, never the page. In a .uvalib-sidebar-layout, use the layout's --sticky or this, not both.

  • Very long contents (issue #38). A text with hundreds of sections, each its own page, should not write the whole list into every page. Write only the entries near the current one (with their parents, so the nesting makes sense) and set full-href to the full contents: a "Full contents (243 sections)" link is drawn after the list, inside the landmark but not as an entry (bold and underlined with an arrow, as library.virginia.edu's "See all" links; 44px tall, the focus ring, LinkText in forced colors; outside the scrolling list, so it shows with sticky; inside the disclosure on narrow screens). full-label is its text ("Full contents"), total the number of entries in the full contents, shown as "(243 sections)" (noun, default "sections"; singular for one, as <uvalib-results-count>). A visually hidden line before the list tells screen readers it is partial ("Showing 25 of 243 sections."); the headline and the landmark's name stay the visible "Contents". base.css holds the link's line before the script runs. Where the whole list is in the page (or comes from items or headings-from), window="12" shows only the current entry and the 12 before and after it in document order (25 entries, shifted at either end), with their parents; the others are hidden, not removed, an ellipsis (hidden from assistive technology) marks each gap, and the window follows the current entry. With full-href the link follows it; without, a "Show all 243 sections" button (aria-expanded) shows the rest in place and "Show fewer" hides it again. The whole list shows until the script runs (base.css cannot hold a window), so prefer the build-time window for very long lists. Without JavaScript there is no link: the list shows alone. Analytics: full-contents-click, show-all, show-fewer, never the label or URL.

    <uvalib-contents class="uvalib-sidebar-layout__sidebar" full-href="/text/eaf375v1/" total="243">
      <ol>
        <li>
          <a href="/text/eaf375v1/d8/">The actress of Padua</a>
          <ol>
            <li><a href="/text/eaf375v1/d40/">Chapter XXXI</a></li>
            <li><a href="/text/eaf375v1/d41/">Chapter XXXII</a></li>
            <!-- … the entries near the current one … -->
          </ol>
        </li>
      </ol>
    </uvalib-contents>
  • Single-page apps. The list is drawn from copies of the children. A plain click on an entry fires uvalib-contents-navigate (detail: { href, level }, bubbling, cancelable; level 0 for t