0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Surface and switch between versions of a page over time: release versions or per-page history, with navigate, swap and diff actions, an archived-version banner and page-info mounting.
Overview
<version-switcher> renders a small trigger button showing the current version of a page; clicking opens a picker popover listing every available version. Two modes auto-detected from the data shape:
Releases — entries have distinct URLs (/v1/page, /v2/page). Classic docs version selector.
History — entries share one URL but differ by date / author. Per-page edit-history list.
Override with data-mode="releases" or data-mode="history" if the data is ambiguous.
Provenance integration
Meta-tag manifest fallback
If no inline data-versions and no data-src are provided, the component falls back to <meta name="vb:versions-manifest"> and fetches the URL listed there. The provenance build pipeline emits this tag from the page's versionsManifest frontmatter (per meta-tag-contract-v1).
Page head + bare switcher
123456
<!-- in <head>: --><metaitemprop="version"content="v2.1"><metaname="vb:versions-manifest"content="/data/versions/api.json"><!-- in <body>: just drop the element — it fetches the manifest --><version-switcheraria-label="API version"></version-switcher>
Archived-version banner
Set data-banner to render a full-width warning banner above the trigger when the current version is archived AND a non-archived "latest" version exists. The banner is a labelled <aside> holding a role="status" line. The line is inserted empty and filled a moment later, so screen readers announce the notice. The Latest pointer is a link only when the latest entry has a safe url.
Banner on archived pages
1234567
<version-switcherdata-bannerdata-versions='[ {"id":"v2.1","label":"v2.1","url":"/v2.1/api"}, {"id":"v1.0","label":"v1.0","url":"/v1/api","current":true,"archived":true}]'></version-switcher><!-- Renders an aside above the trigger: "You’re viewing v1.0 (archived). Latest: v2.1" -->
Mount inside <page-info>
Set data-page-info-target="ID" to render the version list as a section inside the named <page-info>'s expandable panel instead of a standalone trigger. The standalone trigger is hidden in this mode, so readers find versions in the page-info panel next to authorship and provenance. The section gets the same entry styling as the picker, and it is removed when the switcher leaves the page.
Pick the action via data-action. Each action operates on the current page's versioned region — the first [data-versioned] element, or <main> when the page has none. Set data-versioned-region to a CSS selector to choose another element.
Action
Behavior
navigate (default)
Sets location.href to the picked entry's url. Cancellable via version-switcher:before-navigate. If the url is the page you are on, as with history entries that share one URL, nothing reloads; a version-switcher:error fires instead. Give each revision its own URL (for example /policy?rev=2026-04-01), or use swap or diff.
swap
Fetches the picked URL (same-origin only), extracts its versioned region, sanitizes it, and replaces the current versioned region in place. Updates <meta itemprop="version"> with the picked id. Uses document.startViewTransition for a crossfade when supported. Emits version-switcher:before-swap (cancellable) then version-switcher:swap.
diff
Fetches the picked URL (same-origin only), computes a line-level diff against the current versioned region, and mounts a <change-set> sibling containing the diff (use the change-set's tracking-view buttons to flip between final / original / both). data-diff-position="before|after" controls placement. Emits version-switcher:before-diff (cancellable) then version-switcher:diff.
Swap action — in-place page replacement
1234567
<version-switcherdata-action="swap"data-versions='[…]'></version-switcher><maindata-versioned><h1>Authentication API — v2.1</h1><p>…</p></main>
Diff action — line-level diff in a change-set
12345
<version-switcherdata-action="diff"data-diff-position="before"data-versions='[…]'></version-switcher><maindata-versioned>…</main><!-- A <change-set class="version-switcher-diff-host"> appears here on diff -->
When to use which primitive
Use this
When
<version-switcher>
Switch between known versions of THIS page (releases or history snapshots).
Show the current version + provenance + authors. Complementary — not the same.page-info answers "what version is this?"; version-switcher answers "what other versions exist?".
URL to navigate to (or fetch, for swap / diff). An entry whose url is a javascript:, vbscript: or data: URL is dropped.
date
string (ISO-8601)
no
Renders as a localised relative time (Intl.RelativeTimeFormat, nearest [lang]) with the full date in the tooltip.
author
string
no
Useful in history mode.
summary
string
no
One-line description (release-note excerpt or commit message).
archived
boolean
no
Renders the "archived" badge and mutes the entry.
draft
boolean
no
Renders the "draft" badge.
current
boolean
no
Marks the current entry. If absent, derived from a matching <meta itemprop="version"> or the first entry.
versionUrl
string
no
Optional link out to a changelog anchor (matches the vb:version-url meta tag semantics). Rendered beside the entry button, never inside it; an unsafe URL drops the link.
Security
Every entry url and versionUrl, and the banner's latest link, is checked against the shared sanitizer's isDangerousUrl. Script and data: URLs never reach an href or location.href.
swap and diff only fetch same-origin URLs. Swapped markup goes through sanitizeToFragment (the include-file fragment profile), so scripts and inline on* handlers never go live.
The untrusted sanitizer profile removes data-versions and data-src from any custom element, and removes every <script>. User-generated markup cannot carry a version list.
Wiring the events
Cancellable navigate (e.g. dirty-form guard)
123456789101112
const sw = document.querySelector('version-switcher');sw.addEventListener('version-switcher:before-navigate', (e) => {if (formIsDirty()) {if (!confirm(`Discard changes and switch to ${e.detail.entry.label}?`)) { e.preventDefault(); } }});// Programmaticsw.switchTo('v2.0');
Accessibility
Trigger:aria-haspopup="dialog", and aria-expanded tracks the open state. Its accessible name says what is being picked as well as the current value: the host's aria-label plus the version, such as API version: v2.1. The default is Version (data-label-trigger). The host itself has no role, so the label is applied to the trigger and the picker.
Picker:role="dialog" rendered by <pop-over> in the top layer, named like the trigger; light-dismiss via Escape and outside click. The heading (Versions or History) follows the current mode, including after a manifest loads or data-mode changes.
Each entry: a button whose name is its visible text: the label, any badges and the date, such as v1.4 archived last year. Author and summary sit beside the button and are linked with aria-describedby. The changelog link is a sibling of the button, never nested inside it.
Current entry:aria-current="true" + visual highlight; focused first when the picker opens.
Keyboard inside the picker: ArrowUp / ArrowDown move between entries; Home / End jump to first / last; Enter / Space activate.
Focus return: after the picker closes, focus returns to the trigger.
Banner: a labelled <aside> with a role="status" line that is filled after insertion, so it is announced.
Localisation
Every built-in string has a data-label-* override; {placeholders} are substituted. Dates use Intl.RelativeTimeFormat and Intl.DateTimeFormat with the nearest [lang].
French labels
123456789
<sectionlang="fr"><version-switcheraria-label="Version de l’API"data-label-heading-releases="Versions publiées"data-label-current="actuelle"data-label-archived="archivée"data-label-banner="Vous consultez {version} (archivée)."data-label-banner-latest="Dernière : {version}"data-src="/data/versions/api.json"></version-switcher></section>
URL of a JSON manifest to fetch when no inline data is provided. Falls back to <meta name="vb:versions-manifest"> if neither is set.
data-mode
string
derived
releases | history — override the auto-detected mode (sets the heading; observed).
data-action
string
navigate
navigate | swap | diff.
data-versioned-region
string (CSS selector)
none
Selector for the swappable / diffable region in this page AND in the fetched response document. Without it, the region is the first [data-versioned] element, or <main> when the page has none.
data-diff-position
string
before
before | after — where to mount the diff render relative to the versioned region.
data-banner
boolean
false
Render an archived-version warning banner above the trigger when the current entry is archived AND a non-archived "latest" exists.
data-page-info-target
string (ID)
—
ID of a <page-info> to mount inside as a section in its expandable panel; the standalone trigger is hidden in this mode.
aria-label
string
Version
What the switcher picks; names the trigger (API version: v2.1) and the picker.