Skip to content

Gallery: the HTML contract and the browser library visualci-gallery (sc-9297) - #189

Merged
ndbroadbent merged 6 commits into
mainfrom
sc-9297-gallery-js
Dec 4, 2026
Merged

ndbroadbent merged 6 commits into
mainfrom
sc-9297-gallery-js

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Story: sc-9297 (epic sc-9295).

This PR adds one screenshots page, built from a VisualCI public gallery manifest, that every site can use. It holds the shared contract and the reference renderer. The Astro component, Ruby gem, Python package and Rust crate come in later PRs and are tested against the same fixtures.

The contract (clients/gallery/contract)

  • SPEC.md covers:
    • how manifest names pair into screens: <screen>-<light|dark>[-<width>][-2x], as fleetlayer.ai names them, or <screen>/<width>-<light|dark>[-2x], as visualci.com does;
    • phone versus desktop;
    • high-density images, which are shown at the width in their name;
    • default titles, ordering and slugs;
    • the exact HTML, byte for byte.
  • fixtures/*/{manifest,options}.json give the golden model.json and gallery.html. errors/*.json are manifests every renderer must refuse.
  • There is no "the gallery is updating" fallback (Nathan, 4 Dec). A renderer that fetches the manifest fails when it can't read it or when it has nothing to show.

The library (clients/gallery/js, visualci-gallery on npm, not yet published: names and the go-ahead are in sc-9327)

  • mount(el, {manifest}) renders into an empty element. hydrate(el) brings markup a server rendered to life. load() and render() render at build time; they're also exported as visualci-gallery/render, which needs no DOM.
  • Two layouts:
    • grid: tabs per group, with Light/Dark and Desktop/Phone switches for the whole gallery;
    • strip: one row that scrolls sideways with scroll-snap, for a homepage band. DocSpring's screenshots work asked for it.
  • The full-size view is a native <dialog>. It has previous and next buttons, arrow keys, Escape and a backdrop click to close, returns focus to the card on close, and uses the -2x copy as a 2x source when there is one.
  • Each card is a link to its image, so the gallery works without JS and in browsers without <dialog>.
  • themeSwitch: false makes the gallery follow <html data-theme>.
  • The CSS doesn't use :has(), and the gallery respects reduced motion.
  • gallery.css uses --vg-* variables, so each site keeps its own look.
  • dist/gallery.iife.js is one ES5 file, checked with acorn, for sites without a bundler (DocSpring's Sprockets pages).

Tests and screenshots

  • 66 Vitest tests cover the golden fixtures, the model's rules, hydrate's behaviour in jsdom, load and mount failures, and the ES5 file in a bare jsdom window. CI's clients job runs the type check, the build and the tests.
  • scripts/screenshots/gallery.mjs, run by visual.sh capture, screenshots the golden markup with made-up images:
    • the views: the grid, a phone-only tab, a titled gallery, the strip and the full-size view;
    • each at 1440 and 390 px, in light and dark;
    • the script fails if any page scrolls sideways.
  • These screenshots are screenshots/gallery/** in this PR's VisualCI build. They aren't published to the public gallery.

@visualci-com

visualci-com Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #655 · 20 added, 486 unchanged · approved by visualci coordinator agent (MCP) for Nathan Broadbent

Rebase of #189 on main: the 20 gallery shots are the versions approved in builds 562/563/593.

This PR vs base: 28 changed, 72 added since #501, across 7 builds

Snapshot Before After
screenshots/gallery/grid-phone-tab/1440-dark (added) –
screenshots/gallery/grid-phone-tab/1440-light (added) –
screenshots/gallery/grid-phone-tab/390-dark (added) –
screenshots/gallery/grid-phone-tab/390-light (added) –
screenshots/gallery/grid/1440-dark (added) –
screenshots/gallery/grid/1440-light (added) –
screenshots/gallery/grid/390-dark (added) –
screenshots/gallery/grid/390-light (added) –
and 12 more in the build

docspring/visualci · journeys · build #653 · 50 unchanged · no changes

This PR vs base: 2 changed, 8 added since #489, across 8 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

@ndbroadbent ndbroadbent changed the title Gallery: the HTML contract and the browser library @visualci/gallery (sc-9297) Gallery: the HTML contract and the browser library visualci-gallery (sc-9297) Dec 4, 2026
@ndbroadbent
ndbroadbent force-pushed the sc-9297-gallery-js branch 2 times, most recently from bf71013 to 11adc64 Compare December 4, 2026 09:10
…den fixtures) and the browser library @visualci/gallery (sc-9297)

How a public gallery manifest becomes a screenshots page, written down so every renderer emits the same markup: names
pair into screens as <screen>-<light|dark>[-<width>][-2x] or <screen>/<width>-<light|dark>[-2x]; under 768 wide (or a
portrait image with no width) is a phone; an image wider than its name's width is shown at that width; titles default
from the key without the group's shared folders. Golden model.json and gallery.html per fixture, and manifests every
renderer must refuse.

clients/gallery/js: vanilla TS, no dependencies. mount() fetches and renders into an empty element, hydrate() brings
server-rendered markup to life, load() + render() render at build time and throw when the manifest can't be read or
shows nothing (no 'updating' fallback: a site's build fails). Grid (tabs per group, theme and size switches) or strip
(one row with scroll-snap, for a homepage band) layouts; a native <dialog> full-size view with previous/next and
arrow keys; cards are links to their image, so no-JS and pre-<dialog> browsers still work; themeSwitch: false follows
<html data-theme>; gallery.css styled through --vg-* variables, no :has(); dist/gallery.iife.js is one ES5 file for
sites without a bundler. CI's clients job type-checks, builds and tests it; visual-capture screenshots it.
- The full-size view shows the image at its own size (it took the thumbnail's rendered width); the screenshot script
  now fails when it doesn't.
- Validation in the contract and the library: the manifest's shape (names, items, integer sizes), http(s) item URLs
  with no control characters, and every option's type (null means absent; an unknown layout is an error); seeAll's
  href absolute or relative, never another scheme. errors/ and new option-errors/ fixtures.
- Groups with the same name keep the manifest's order; default titles ignore screens dropped for having only a 2x
  copy; SPEC's patterns are whole-string, ASCII digits and any-character, so Python, Ruby and Rust match the same.
- The view offers only the sizes the open screen has; opening a screen by key shows a size it has; stepping from a
  screen outside the list goes to the first or last.
- Every attribute is data-vg-* (the gallery's theme and size, the buttons, the images), so a site's [data-theme]
  rules can't reach it. Alt text names the theme an image really is.
- The strip's buttons sit inside it (no sideways page scroll at 390 px), follow its width (ResizeObserver), and long
  titles wrap; the overflow check runs with no page margin. The no-JS theme rule uses Level 3 media query syntax.
- load() works without AbortSignal.timeout (Safari 15); mount() again destroys the gallery it replaces.
- A duplicates fixture; tests for the image fallback, destroy, remounting and the view's sizes.
…elongs to another project; names in sc-9327)
One theme's image never stands in for the other's: the model refuses a screen with a light shot at
a size and no dark one (or the reverse), naming the screen, group, size and missing theme. A shot
whose name gives no theme still stands for both. Fixtures gain the missing shots; errors/one-theme.json
is the new golden refusal.
groups[name].size sets the size of a group's shots whose names give no width (a Mac app's portrait
window is still a desktop shot); groups[name].fit "contain" shows the group's images whole and
centred in their cards (data-vg-fit="contain", --vg-contain-padding and --vg-contain-shadow).
fleetlayer.ai's Mac approver tab needs both to move to the shared gallery without a visible change.
…nknown keys

Every errors/ and option-errors/ file has a .message beside it that each renderer must match word for
word; an invalid option's message names the option without echoing its value. groups entries refuse
an unknown key even when its value is null, and the spec fixes the order the one-theme rule checks
in (errors/one-theme-order.json).
@ndbroadbent
ndbroadbent merged commit 119142e into main Dec 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant