# Gallery options and theming

> How a gallery pairs your screenshots, the dimensions they differ by (theme, size, language), every option the gallery libraries take, the --vg-* CSS variables that give it your site's look, and how it behaves in the browser.

Source: https://visualci.com/docs/gallery/options/
All of VisualCI's documentation: https://visualci.com/llms.txt

Every gallery library (JS, Astro, Ruby, Python and Rust) reads the same [manifest](https://visualci.com/docs/gallery.md), takes the same options and renders the same HTML, byte for byte. The JS library's script brings that HTML to life in the browser. This page is the reference for all of them; each library's guide shows the options in its own spelling.

## Naming screenshots

The gallery pairs a screen's shots by their names. A name is the screen, then what sets this shot apart, separated by
hyphens or in a folder of its own:

- `<screen>/<width>-<theme>`, as in `screenshots/app/billing/1440-light` and `screenshots/app/billing/390-dark`.
- `<screen>-<theme>[-<width>]`, as in `overview-light-1440`, `overview-dark-390` and `ios/usage-light`.

The parts after the screen can come in any order (`home-1440-light` works too). `<theme>` is `light` or `dark`. A width
under 768 is the phone size, anything wider is the desktop size; you can also name the size (`home-phone-dark`). With
no width or size, an image taller than it is wide is a phone shot, and the group's `size` option can say otherwise (a
Mac app's windows are `desktop`). A `-2x` at the end marks a high-density copy of the shot named before it
(`1440-light-2x`), used for the full-size view on high-density screens. A name with no theme stands for both themes.

Every size a screen has needs both themes. A screen with a light desktop shot and no dark one is an error that names
it, so a page never shows one theme's picture in place of the other's.

## Dimensions

Theme and size are the gallery's two built-in **dimensions**: ways a screen's shots differ, each with a switch. The
`dimensions` option adds your own, such as a language or a plan, and changes the built-in ones, such as a third theme
or a tablet size. Each value's key is a word in the shots' names. These are the options of the gallery contract's
`dimensions` example:

<!-- example: clients/gallery/contract/fixtures/dimensions/options.json -->

```json
{
  "dimensions": [
    { "key": "theme", "values": [{ "key": "light", "label": "Light" }, { "key": "dark", "label": "Dark" }, { "key": "high-contrast", "label": "High contrast" }] },
    { "key": "size", "values": [{ "key": "desktop", "label": "Desktop" }, { "key": "tablet", "label": "Tablet", "below": 1024 }, { "key": "phone", "label": "Phone", "below": 768 }] },
    { "key": "lang", "label": "Language", "values": [{ "key": "en", "label": "English" }, { "key": "fr", "label": "Français" }, { "key": "de", "label": "Deutsch" }, { "key": "ja", "label": "日本語" }] }
  ],
  "order": ["pricing", "home"]
}
```

With these, `pricing-high-contrast-fr-1440` is the Pricing screen in high contrast, in French, at the desktop size
(a width under 768 is a phone, under 1024 a tablet). A shot whose name has no language stands for every language.

- An entry with the key `theme` or `size` changes that dimension: the fields it gives replace the built-in ones
  (`values` replaces the whole list). An entry with any other key adds a dimension after them.
- `label` is the switch's accessible name; a value's `label` is its text. Both default to the key.
- `missing` says what a card does when it has no shot for the chosen value: `"error"` (the theme's default) means
  every screen of a group must have every value the group has, so one theme never stands in for another; `"hide"` (the
  size's default) hides the card while that value is chosen, as a desktop-only screen is hidden at Phone; `"first"`
  (the default for a dimension you add) shows the card's own first value, as a page not translated yet shows English.
- `below`, on the size's values only: a shot whose name gives a width under it has that size.
- Keys are lower case letters, digits and single hyphens (`high-contrast`), not only digits, and each value's key is
  used once across every dimension.
- A screen has the same values at every size: French at the desktop size means French at the phone size too.

A switch shows the values the tab has: none for one value, buttons for two or three, and a drop-down list (a WAI-ARIA
select-only combobox: arrow keys, Home and End, type to jump, Enter to choose, Escape to close) for four or more.

## Options

Every option is optional. Ruby and Python spell the multi-word ones in snake case. Rust sets each one with a method of `Options` of the same snake-case name; `screen` and `group` set one screen or group at a time.

| Option | Ruby, Python | Rust | Default | What it does |
| --- | --- | --- | --- | --- |
| `title` | `title` | `.title(Some("…"))` | `"Screenshots"` | The gallery's heading. Set it to null (`nil`, `None`) for no heading; the gallery's accessible name stays "Screenshots" (`text.label`). |
| `headingLevel` | `heading_level` | `.heading_level(2)` | `2` | The heading's level, from 1 to 4. Groups and cards take the levels below it. |
| `id` | `id` | `.id("…")` | `"vg"` | The prefix of every id in the markup. Give each gallery its own when a page has more than one. |
| `dimensions` | `dimensions` | `.dimension(…)` | `[]` | The ways a screen's shots differ over the built-in theme and size ([above](#dimensions)). |
| `screens` | `screens` | `.screen(key, title, caption)` | `{}` | A title and a caption for each screen, by key: `{"screenshots/app/billing": {"title": "Billing", "caption": "Plans and credits."}}`. Without a title, the key becomes one: among other `screenshots/app/…` keys, `screenshots/app/billing/free` becomes "Billing, free". |
| `order` | `order` | `.order(&[…])` | `[]` | Screen keys in the order they show. The rest follow, by key. |
| `groups` | `groups` | `.group(name, title, size, fit)` | `{}` | Per group, by name: `title` (over the manifest's), `size` (a size value, `"desktop"` or `"phone"` by default, for shots whose names give no width or size) and `fit` (`"cover"`, the default, fills the card and crops at the bottom; `"contain"` shows the whole image, centred, for an app's windows). |
| `groupOrder` | `group_order` | `.group_order(&[…])` | `[]` | Group names in the order their tabs show. The rest follow in the manifest's order. |
| `credit` | `credit` | `.credit(true)` | `false` | A "Screenshots by VisualCI" line under the gallery, when true. |
| `layout` | `layout` | `.layout("strip")` | `"grid"` | `"grid"` shows a tab per group and a grid of cards. `"strip"` shows every screen at one size in a single row that scrolls sideways, for a band on a homepage. |
| `themeSwitch` | `theme_switch` | `.theme_switch(false)` | `true` | The theme's switch. Without it the gallery follows the page (below). The strip never has one. |
| `seeAll` | `see_all` | `.see_all(href, text)` | none | A link under the gallery, `{"href": "/screenshots/", "text": "See all screenshots"}`. `text` is optional. Use it on a strip, to link to the full page. |
| `preload` | `preload` | `.preload(false)`, `.preload_caps(fold, count, bytes, parallel)` | `true` | Preloading the images a reader is likely to look at next ([below](#preloading)). `false` turns it off. `{"count": 200, "bytes": 20000000}` sets your own limits: `fold`, `count`, `bytes` and `parallel`, the rest keeping their defaults. |
| `deepLinks` | `deep_links` | `.deep_links(true)` | `false` | The page's URL names the open tab, screen and values, so a link opens them ([below](#deep-links)). Off, the gallery never changes the URL. |
| `text` | `text` | `.text("close", "Fermer")` | `{}` | The gallery's own words, for another language ([below](#your-own-words)). |
| `search` | `search` | `.search(true)`, `.search_from(20)` | `40` | A search box over the grid ([below](#search)). A number shows it once the gallery has that many screens; `true` always, `false` never. The strip has none. |
| `zoom` | `zoom` | `.zoom(false)` | `true` | Zoom in the full-size view, by pinching, ctrl-scrolling, double-clicking and the + and - keys ([below](#zoom)). No buttons. |
| `newBadges` | `new_badges` | `.new_badges(true)`, `.new_badges_days(14)` | `false` | A New badge on screens whose picture changed recently ([below](#new-badges)): `true` for the last 30 days, or a number of days. |
| `versions` | `versions` | `.versions(true)` | `false` | A Version switch over the grid, when your project [reports versions](https://visualci.com/docs/gallery/versions.md) ([below](#versions)). The strip has none. |

A library refuses options it can't use (an `id` that isn't a valid id, a `layout` it doesn't know) with an error that names the option, so a typo fails your build instead of rendering something else.

## Your own words

Every word the gallery writes itself, on screen or for screen readers, can be changed with `text`, for a site in
another language or with its own tone. Give only the ones you want to change. The switches' words are the dimensions'
labels, so a French site changes those too. These are the options of the gallery contract's `text` example:

<!-- example: clients/gallery/contract/fixtures/text/options.json -->

```json
{
  "credit": true,
  "deepLinks": true,
  "dimensions": [{"key": "theme", "label": "Thème", "values": [{"key": "light", "label": "Clair"}, {"key": "dark", "label": "Sombre"}]}],
  "text": {
    "label": "Captures d'écran",
    "open": "Agrandir « {title} »",
    "previous": "Écran précédent",
    "next": "Écran suivant",
    "close": "Fermer",
    "credit": "Captures d'écran par {link}",
    "and": " et "
  }
}
```

| Key | Default | Where it shows |
| --- | --- | --- |
| `label` | `Screenshots` | The default title, and the gallery's name for screen readers when `title` is null. |
| `open` | `{title}: view full size` | Each card's link, for screen readers. `{title}` is the screen's title. |
| `previous`, `next`, `close` | `Previous screen`, `Next screen`, `Close` | The full-size view's buttons. |
| `back`, `forward` | `Scroll back`, `Scroll forward` | The strip's scroll buttons. |
| `credit` | `Screenshots by {link}` | The credit line (with `credit` on). `{link}` is the link to VisualCI. |
| `and` | ` and ` | Between the values an image stands for in its description: "Billing, Light and Dark". |
| `search` | `Search screens` | The search box's placeholder and its name for screen readers. |
| `empty` | `No screens match` | What the grid says when nothing matches the search. |
| `new` | `New` | The New badge. |
| `change` | `New in {title}: see what changed` | A New badge's name for screen readers when it links to the change in VisualCI. `{title}` is the screen's title. If you change `new`, keep that word in `change` too, so the name a screen reader says contains the words on the badge. |
| `version` | `Version` | The Version switch's name for screen readers. |
| `latest` | `Latest` | The Version switch's choice for the gallery as it is now. |

## Theming

The stylesheet (`gallery.css`, which every library ships or links) styles the gallery through CSS variables. Set them on `.vg`, or on any element around the gallery, to your site's own colours and type. This is the Flask example's stylesheet:

<!-- example: clients/gallery/python/examples/flask/static/site.css#gallery -->

```css
/* The gallery in the site's colours, radii and type. */
.vg {
  --vg-ink: var(--text);
  --vg-ink-2: var(--text);
  --vg-muted: var(--text-muted);
  --vg-paper: var(--surface);
  --vg-paper-2: var(--surface-raised);
  --vg-rule: var(--border);
  --vg-accent: var(--link);
  --vg-radius-md: var(--radius);
  --vg-radius-lg: calc(var(--radius) * 1.5);
  font-family: var(--font);
}
```

When your tokens change with your site's theme, the gallery's colours change with them. Out of the box it follows the text colour and the page's `color-scheme`.

| Variable | Default | What it styles |
| --- | --- | --- |
| `--vg-ink` | `currentColor` | Headings, card titles, the chosen tab and switch. |
| `--vg-ink-2` | `currentColor` | The switches' text and the full-size view's text. |
| `--vg-muted` | the text colour at 65% | Captions, unchosen tabs, the credit line. |
| `--vg-paper` | `Canvas` | The full-size view's background, a chosen switch. |
| `--vg-paper-2` | the text colour at 5% over `Canvas` | Card backgrounds, the switches' track, behind the full-size image. |
| `--vg-rule` | the text colour at 16% | Borders and dividers. |
| `--vg-rule-width` | `1px` | Their width. |
| `--vg-accent` | `LinkText` | The chosen tab's underline, focus rings, the "See all" link. |
| `--vg-radius-sm`, `--vg-radius-md`, `--vg-radius-lg` | `4px`, `8px`, `12px` | The full-size image, cards, the full-size view. |
| `--vg-shadow` | a soft two-layer shadow | Cards and the full-size view. |
| `--vg-float-shadow` | a ring and a shadow | The strip's scroll buttons, over the screenshots. |
| `--vg-backdrop` | black at 60% | Behind the full-size view. |
| `--vg-gap` | `1.5rem` | The space between cards; other spacing scales from it. |
| `--vg-card-min`, `--vg-phone-card-min` | `22rem`, `9.5rem` | The narrowest a desktop or phone card gets before the grid drops a column. |
| `--vg-desktop-ratio`, `--vg-phone-ratio` | `1440 / 900`, `390 / 844` | The cards' shape. A taller screenshot shows its top. |
| `--vg-contain-padding`, `--vg-contain-shadow` | `7%`, a drop shadow | The room and shadow around images in a `fit: "contain"` group. |
| `--vg-title-size`, `--vg-group-title-size`, `--vg-card-title-size`, `--vg-small` | `2rem`, `1.5rem`, `1.125rem`, `0.875rem` | Type sizes. Captions and switches use `--vg-small`. |
| `--vg-duration`, `--vg-ease` | `150ms`, an ease-out curve | The cards' lift on hover. Reduced motion turns it off. |
| `--vg-strip-card`, `--vg-strip-phone-card` | `min(22.5rem, 80%)`, `min(11rem, 45%)` | The width of a card in the strip. |

You can put a gallery in the middle of a page's content. The page's own styles for headings, paragraphs and lists don't change it: a docs page's heading margins and list padding stay out of the gallery, and so do the heavier article styles of docs themes such as Material for MkDocs and VitePress. To keep them out, the rules for the gallery's own elements weigh (0,3,0), as in `.vg[data-vg] .vg-card-title`. A rule of your own that changes one of those elements needs at least that weight, and must come after `gallery.css`. The variables above are the easy way, and they're enough for colours, radii, spacing and type sizes.

## Light and dark

Before the script runs, the gallery shows the screenshots for `<html data-theme="light">` or `"dark"` when the page sets it, and for the reader's system setting when it doesn't. With the theme switch (the default for the grid), the gallery starts in that theme and the reader then chooses. With `themeSwitch` off, the gallery follows the page as it changes: a site with its own theme toggle on `<html data-theme>` switches the gallery's screenshots with it, for any theme the gallery has (`data-theme="high-contrast"` too).

Once the script runs, the gallery's section carries the shown tab's theme and size as `data-vg-theme` and `data-vg-size`, for your own CSS.

Every attribute the gallery reads or sets starts with `data-vg-`, so your site's own `[data-theme]` rules never reach inside it.

## In the browser

The JS library's `hydrate()` (the Astro component and the server libraries include the call) adds:

- One choice of each dimension's value for the whole gallery. On a screen narrower than 48rem it starts at the phone size. A tab without the chosen value shows its own first, and the next tab is back at the chosen one.
- Tabs that follow the WAI-ARIA tabs pattern: arrow keys, Home and End.
- The full-size view, a native `<dialog>`: the same switches (only the values the screen has), previous and next (buttons and arrow keys), Escape or a click outside to close, and focus back on the card. A shot of one screen (a desktop or phone screen, or a window in a `fit: "contain"` group) fits the view whole; a full-page capture scrolls inside it. The page behind it doesn't scroll.
- An image that can't load shows its description in its place.

## Deep links

With `deepLinks` on, the page's URL says what the reader is looking at, so they can copy it and send it on. Opening
the link shows the same tab, values and screen: in
`https://example.com/screenshots/#vg/iphone/ios/approval?theme=dark&size=phone`, that's the gallery's `id`, the tab, the screen open in the full-size view, then the values. The gallery changes the
URL in place as the reader goes (the back button still leaves the page), and only once they choose something: a page
that loads doesn't get a hash it didn't have. A link to something the gallery doesn't have opens what it can and
ignores the rest. It's off by default because your page may use the hash itself, for headings or a router.

Without JavaScript, each card is a link to its image, in the theme the reader's system prefers.

## Search

A gallery with 40 screens or more gets a search box over its tabs. Every word typed has to be in a screen's title or
caption, in any case and with or without accents. Tabs with no match are hidden, previous and next in the full-size
view step only through the matches, and when nothing matches the grid says so. `"search": 20` shows the box from 20
screens, `true` on every gallery and `false` on none.

## Zoom

In the full-size view a reader can zoom into a tall or detailed capture, up to 8 times: pinch on a trackpad or touch
screen, scroll with ctrl or cmd held, double-click the image (and again to go back), or press `+`, `-` and `0`. The
point under the pointer stays put. Zoomed in, the image scrolls inside the view, and a mouse can drag it. The next
screen starts unzoomed. There are no buttons for it, so nothing changes on screen; `"zoom": false` turns it off.

## New badges

`"newBadges": 14` puts a small New badge on each screen whose picture changed in the last 14 days (`true` for 30).
The reader's browser decides from the time the picture first appeared, so a page you built weeks ago doesn't still
call those screens new, and a build that keeps a picture as it was doesn't make it new again. A screen counts as
changed when any of its shots did, so a restyle that changes every screen marks them all. It's off by default.

When the project's builds are public, the badge links to the change in VisualCI: the snapshot page that shows the new
picture beside the old one. A private project's manifest carries no links to its builds, so its badges are labels
only.

## Versions

When your project [reports versions](https://visualci.com/docs/gallery/versions.md), `"versions": true` puts a Version switch over the
grid: Latest (the gallery as it is now), then each version, newest first, as buttons for up to two versions and a
drop-down list for more. Choosing one shows that version's screenshots in place, keeping the tab and the values the
reader chose; with `deepLinks` on, the link names the version too (`#vg@v2-0-0/iphone`). The page carries your
options so the browser can build each version the same way, so the switch works on a page any library rendered. A
project that reports no versions shows no switch. It's off by default.

To show one version for good, say on a versioned docs page, read its manifest instead of the main one: pass `ref`
(`"v1.0.0"`, or its key `v1-0-0`) where you give the manifest's URL. Its gallery is the screenshots as they were at
that release, and its switch, when on, starts there.

## Preloading

Once the page has loaded, the gallery fetches the images a reader is likely to look at next, so a tab or the full-size view shows at once. It starts when the browser is idle, runs a few requests at a time at low priority, and never delays the page itself: on visualci.com's screenshots page and fleetlayer.ai's, first paint and the load event take the same time with it on and off.

What it fetches, in order, each step in the theme the reader is looking at before the other one, and small card images before full-size ones:

1. The cards on screen in the open tab, then the rest of that tab.
2. The cards a reader would see first in each other tab, from the next tab on, then the rest of each tab.
3. The same in the other theme.
4. The full-size images, in the same order.

What the reader does comes first. Opening a tab loads its cards straight away at high priority. Pointing at a tab starts on its first cards. In the full-size view, the gallery fetches the next screen, the one after it, the previous one and the one before that.

The limits keep a gallery of thousands of screenshots from downloading hundreds of megabytes:

| Limit | Default | What it limits |
| --- | --- | --- |
| `fold` | `250` | The cards on screen in the open tab, which always load. |
| `count` | `500` | Images past those, for the whole visit. |
| `bytes` | `50000000` | Bytes past those, for the whole visit. VisualCI's manifest gives each image's size; a gallery from another source is estimated from its width and height. |
| `parallel` | `4` | Requests at once, from 1 to 8. |

Images the reader asks for (a tab they open) load whatever the limits say.

On a slow or metered connection it fetches only the open tab's cards: with the browser's Save-Data setting, on a 2G connection, or with `prefers-reduced-data`. Most browsers report none of these, so the gallery also times its own downloads: under 125 KB a second it drops to the open tab's cards, two at a time, and tries again later.

Where the manifest has a small copy of a screenshot (VisualCI makes one for each published screenshot), the cards show that and the full-size view shows the original, so the page's first load is lighter too.

## The markup

The exact HTML, and the tests every library passes to produce it, are in the gallery contract: [clients/gallery/contract/SPEC.md](https://github.com/DocSpring/visualci/blob/main/clients/gallery/contract/SPEC.md). A library in another language can render the same markup and use the JS library's script and stylesheet as they are.
