From f13d3445101c120de1730818cfe22f675a455f3b Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 14:24:19 +0000 Subject: [PATCH 1/4] Gallery (sc-9560): search, zoom and New badges in the JS library and the contract search (default 40: the grid's box shows once it has that many screens), zoom (default on, gestures and keys only) and newBadges (default off; decided in the reader's browser from the screen's newest since). Three new text keys: search, empty, new. Screens gain since in the model. --- clients/gallery/contract/SPEC.md | 63 +++++- .../contract/fixtures/dimensions/model.json | 12 +- .../contract/fixtures/duplicates/model.json | 13 +- .../contract/fixtures/escaping/model.json | 11 +- .../contract/fixtures/extras/gallery.html | 26 +++ .../contract/fixtures/extras/manifest.json | 23 ++ .../contract/fixtures/extras/model.json | 207 ++++++++++++++++++ .../contract/fixtures/extras/options.json | 7 + .../contract/fixtures/fleetlayer/model.json | 17 +- .../contract/fixtures/group-order/model.json | 11 +- .../contract/fixtures/light-only/model.json | 11 +- .../contract/fixtures/page-theme/model.json | 12 +- .../contract/fixtures/preload-off/model.json | 10 +- .../contract/fixtures/single-group/model.json | 10 +- .../contract/fixtures/strip-themes/model.json | 11 +- .../fixtures/strip-themes/options.json | 3 +- .../contract/fixtures/strip/model.json | 16 +- .../gallery/contract/fixtures/text/model.json | 11 +- .../contract/fixtures/thumbs/model.json | 10 +- .../contract/fixtures/visualci/model.json | 12 +- .../contract/fixtures/widths/model.json | 9 +- .../option-errors/newbadges-after-zoom.json | 1 + .../newbadges-after-zoom.message | 1 + .../option-errors/newbadges-too-many.json | 1 + .../option-errors/newbadges-too-many.message | 1 + .../option-errors/newbadges-zero.json | 1 + .../option-errors/newbadges-zero.message | 1 + .../option-errors/search-after-text.json | 1 + .../option-errors/search-after-text.message | 1 + .../option-errors/search-fraction.json | 1 + .../option-errors/search-fraction.message | 1 + .../option-errors/search-negative.json | 1 + .../option-errors/search-negative.message | 1 + .../contract/option-errors/search-string.json | 1 + .../option-errors/search-string.message | 1 + .../option-errors/zoom-after-search.json | 1 + .../option-errors/zoom-after-search.message | 1 + .../contract/option-errors/zoom-string.json | 1 + .../option-errors/zoom-string.message | 1 + clients/gallery/js/src/gallery.css | 68 +++++- clients/gallery/js/src/hydrate.ts | 169 +++++++++++++- clients/gallery/js/src/model.ts | 47 ++++ clients/gallery/js/src/render.ts | 13 ++ clients/gallery/js/test/hydrate.test.ts | 87 ++++++++ 44 files changed, 880 insertions(+), 27 deletions(-) create mode 100644 clients/gallery/contract/fixtures/extras/gallery.html create mode 100644 clients/gallery/contract/fixtures/extras/manifest.json create mode 100644 clients/gallery/contract/fixtures/extras/model.json create mode 100644 clients/gallery/contract/fixtures/extras/options.json create mode 100644 clients/gallery/contract/option-errors/newbadges-after-zoom.json create mode 100644 clients/gallery/contract/option-errors/newbadges-after-zoom.message create mode 100644 clients/gallery/contract/option-errors/newbadges-too-many.json create mode 100644 clients/gallery/contract/option-errors/newbadges-too-many.message create mode 100644 clients/gallery/contract/option-errors/newbadges-zero.json create mode 100644 clients/gallery/contract/option-errors/newbadges-zero.message create mode 100644 clients/gallery/contract/option-errors/search-after-text.json create mode 100644 clients/gallery/contract/option-errors/search-after-text.message create mode 100644 clients/gallery/contract/option-errors/search-fraction.json create mode 100644 clients/gallery/contract/option-errors/search-fraction.message create mode 100644 clients/gallery/contract/option-errors/search-negative.json create mode 100644 clients/gallery/contract/option-errors/search-negative.message create mode 100644 clients/gallery/contract/option-errors/search-string.json create mode 100644 clients/gallery/contract/option-errors/search-string.message create mode 100644 clients/gallery/contract/option-errors/zoom-after-search.json create mode 100644 clients/gallery/contract/option-errors/zoom-after-search.message create mode 100644 clients/gallery/contract/option-errors/zoom-string.json create mode 100644 clients/gallery/contract/option-errors/zoom-string.message diff --git a/clients/gallery/contract/SPEC.md b/clients/gallery/contract/SPEC.md index 2c7faf46..b09074db 100644 --- a/clients/gallery/contract/SPEC.md +++ b/clients/gallery/contract/SPEC.md @@ -12,7 +12,9 @@ change, and regenerate the fixtures (`UPDATE_GOLDEN=1 pnpm test` in `../js`), re 1. **The manifest**, `https://app.visualci.com/g//.json` (https://visualci.com/docs/gallery/): `{project, groups: [{name, title?, items: [{name, platform, url, width, height, sha256, since, bytes?, thumb?}]}]}`. - Only `name`, `title`, `items`, and each item's `name`, `url`, `width`, `height`, `bytes` and `thumb` are read. + Only `name`, `title`, `items`, and each item's `name`, `url`, `width`, `height`, `bytes`, `thumb` and `since` are + read. `since` is when that picture was approved, an RFC 3339 time in UTC (it changes only when the image does); + one that isn't a string is ignored, never an error. `bytes` is the image's size; `thumb` is a small copy for the cards, `{url, width, height, bytes?}` (VisualCI serves a 640 px WebP of each published shot wider than that). Both are optional: a manifest without them shows the originals in the cards and the preloader estimates sizes. @@ -35,6 +37,9 @@ change, and regenerate the fixtures (`UPDATE_GOLDEN=1 pnpm test` in `../js`), re | `preload` | `true` | Predictive preloading (Behaviour). `false` turns it off; `{fold?, count?, bytes?, parallel?}` sets its caps, the rest keeping their defaults (250, 500, 50000000, 4). | | `deepLinks` | `false` | The URL's hash names the shown tab, the open screen and the chosen values, so a link opens them (Deep links). Off, the gallery never changes the page's URL. | | `text` | `{}` | The gallery's own words, for another language or another tone (Text, below): any of its keys, each a string. | + | `search` | `40` | The grid's search box, which filters the cards by title and caption across tabs (Search). A number: shown once the gallery has that many screens (in every group); `true`, always; `false`, never. The strip never has one. | + | `zoom` | `true` | Zoom in the full-size view, by gestures and keys only (Zoom). `false` turns it off. | + | `newBadges` | `false` | A New badge on each screen whose picture changed in the last so many days (New badges): `true` for 30, or a whole number of days from 1 to 3650. | An option set to `null` is the same as leaving it out, except `title`, where `null` means no heading. An empty string is kept as it is. Each language takes them in its own spelling (`heading_level`, `group_order`, `theme_switch`, `see_all` in Ruby, @@ -56,6 +61,9 @@ keeps its default: | `forward` | `Scroll forward` | The strip's button that scrolls forward. | | `credit` | `Screenshots by {link}` | The credit line, when `credit` is true; `{link}` is the link to VisualCI. | | `and` | ` and ` | Between the values an image stands for in its alt text (`Light and Dark`). | +| `search` | `Search screens` | The search box's accessible name and placeholder. | +| `empty` | `No screens match` | What the grid says when no screen matches the search. | +| `new` | `New` | The New badge. | The words of the dimensions' switches are their labels (`dimensions`); the see-all link's is `seeAll.text`. @@ -118,10 +126,12 @@ word for word, in every language. An invalid option's message names it in the co `themeSwitch` booleans; `layout` `"grid"` or `"strip"`; `seeAll` an object with a string `href` and a `text` that's absent, null or a string; `preload` a boolean or an object with only `fold`, `count` and `bytes` (null or a whole number from 0 to 10^12) and `parallel` (null or a whole number from 1 to 8); `deepLinks` a boolean; `text` an object - with only the keys of Text, each null or a string. `seeAll.href` is an absolute URL as above, or a relative one: not empty, no character from + with only the keys of Text, each null or a string; `search` a boolean or a whole number from 0 to 1000000; `zoom` a + boolean; `newBadges` a boolean or a whole number from 1 to 3650. `seeAll.href` is an absolute URL as above, or a relative one: not empty, no character from U+0000 to U+0020 or U+007F, and not starting with a scheme (`^[A-Za-z][A-Za-z0-9+.-]*:`). - The manifest is checked first, then the options in this order, and the first problem is the error: `headingLevel`, - `title`, `id`, `dimensions`, `screens`, `groups`, `order`, `groupOrder`, `credit`, `themeSwitch`, `layout`, `seeAll`, `preload`, `deepLinks`, `text`. + `title`, `id`, `dimensions`, `screens`, `groups`, `order`, `groupOrder`, `credit`, `themeSwitch`, `layout`, `seeAll`, `preload`, `deepLinks`, `text`, `search`, + `zoom`, `newBadges`. - Other fields, in the manifest or the options, are ignored. ## Reading the manifest @@ -143,10 +153,11 @@ order below, a newline at the end). Renderers in other languages compare it as d ``` {layout, themeSwitch, seeAll: {href, text} | null, title: string | null, label, headingLevel, id, credit, preload: null | "off" | {fold, count, bytes, parallel}, deepLinks, - text: {label, open, previous, next, close, back, forward, credit, and}, + text: {label, open, previous, next, close, back, forward, credit, and, search, empty, new}, + search: boolean, zoom: boolean, newBadges: number | null, dimensions: [{key, label, missing, values: [{key, label, below | null, shape: "landscape" | "portrait" | null}]}], groups: [{name, title, slug, fit, values: {"": ["", …], …}, screens: [{key, title, - caption | null, variants: [{values: {"": "", …}, url, url2x | null, width, height, + caption | null, since | null, variants: [{values: {"": "", …}, url, url2x | null, width, height, bytes | null, bytes2x | null, thumb: {url, width, height, bytes | null} | null}]}]}]} ``` @@ -214,6 +225,9 @@ For each manifest group, in order: character (`screenshots/app/billing/free` among `screenshots/app/…` keys: "Billing, free"). Upper-casing uses the language's Unicode-aware upper case of that one character. - **Caption:** `options.screens[key].caption`, else `null`. +- **Since:** the greatest `since`, comparing strings by code point, of the manifest items whose name gives the + screen's key (2x copies included); items whose `since` is absent, not a string or empty don't count. `null` when + none has one. - **Order:** keys in `options.order` first, in that order; then the rest, by key, comparing strings by code point. ### Groups @@ -234,7 +248,10 @@ For each manifest group, in order: is the title or `text.label` when it's null, `layout`, `themeSwitch` (`layout == "grid"` and the option isn't false), `seeAll` (`null`, or `{href, text}` with the default text), `headingLevel`, `id`, `credit`, `deepLinks` as above. `preload`: `null` when the option is absent, null or -true; `"off"` when false; else the caps with every key filled in from the defaults. +true; `"off"` when false; else the caps with every key filled in from the defaults. `search` is true when the layout +is `grid` and the option is true, or a number no greater than the number of screens in every group (absent or null: +40); else false. `zoom` is the option, true when absent or null. `newBadges` is null when the option is absent, null +or false; 30 when true; else the number. ## The markup @@ -264,8 +281,9 @@ true; `"off"` when false; else the caps with every key filled in from the defaul size values whose shape is `portrait`, joined with a space. ``` -
+
[{title} when title isn't null] +[ when search] … the grid's or the strip's lines … [

{seeAll.text}

when seeAll] [

{TEXT(credit)}

when credit] @@ -317,6 +335,12 @@ Then for each group, `i` its index: ``` +After the last panel, when `search`: + +``` + +``` + ### The strip Every screen of every group, in order, that isn't off for `C`, in one row: @@ -337,7 +361,7 @@ Every screen of every group, in order, that isn't off for `C`, in one row: `url`, `url2x` and thumb `url`, in the order of each set's first variant; `first` is the card's image for `choice`. ``` -
  • {IMAGES}{title}[

    {caption}

    when wanted and not null]
  • +
  • {IMAGES}[ when newBadges and since]{title}[

    {caption}

    when wanted and not null]
  • ``` An image, for its variants (`v` the first of them): @@ -394,6 +418,29 @@ them. The card's link is the original. checked again when its width changes. - An image that can't load is replaced by its alt text, in the same place. +### Search + +With a `.vg-search-input` (the `search` option), every word typed (split on white space) must appear in a card's title +or caption, ignoring case and accents (Unicode NFD with the combining marks dropped). A card that doesn't match gets +`data-vg-unmatched` and isn't shown, a tab none of whose shown cards match is hidden, and when the shown tab is hidden +the first tab with a match is shown. When no tab has a match, `.vg-empty` shows. Previous and next step only through +the cards that match. An empty box shows everything again; the switches keep filtering what they did. + +### Zoom + +Unless the section has `data-vg-zoom="off"`, the full-size view's image zooms from 1 to 8 times, with no buttons: the +wheel with ctrl or cmd held (a trackpad's pinch), two fingers on a touch screen, a double-click on the image (2 times, +or back to 1), and `+` (or `=`), `-` and `0` while the view has focus. The point under the pointer stays where it +is. The image grows in the layout and the view scrolls, so a finger or the wheel pans it, and a mouse drags it while +zoomed (the view gets `data-vg-zoomed`). Zoom is instant, so there's no motion to reduce. Another screen, or closing +the view, starts at 1 again. + +### New badges + +With `data-vg-new="{days}"`, each card's `.vg-new` badge shows when its `data-vg-since` is in the past and less than +that many days ago, by the reader's clock. It's decided in the browser, so a page built long ago never calls an old +screen new. `since` changes whenever a screen's picture does, so a restyle that changes every screen marks them all. + ### Deep links With `data-vg-links` (the `deepLinks` option), the page's URL hash names what the gallery shows: diff --git a/clients/gallery/contract/fixtures/dimensions/model.json b/clients/gallery/contract/fixtures/dimensions/model.json index 2ee459f0..db64ae72 100644 --- a/clients/gallery/contract/fixtures/dimensions/model.json +++ b/clients/gallery/contract/fixtures/dimensions/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -132,6 +138,7 @@ "key": "pricing", "title": "Pricing", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -307,6 +314,7 @@ "key": "home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -818,6 +826,7 @@ "key": "settings", "title": "Settings", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -930,6 +939,7 @@ "key": "docs/start", "title": "Start", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/duplicates/model.json b/clients/gallery/contract/fixtures/duplicates/model.json index 0219481a..608fbf4c 100644 --- a/clients/gallery/contract/fixtures/duplicates/model.json +++ b/clients/gallery/contract/fixtures/duplicates/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "a/b/home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -130,6 +137,7 @@ "key": "ios/home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -180,6 +188,7 @@ "key": "web2/x", "title": "X", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -230,6 +239,7 @@ "key": "x/١٤٤٠", "title": "X, ١٤٤٠", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -263,6 +273,7 @@ "key": "y", "title": "Y", "caption": "", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/escaping/model.json b/clients/gallery/contract/fixtures/escaping/model.json index 8a082cc6..2acdd2ae 100644 --- a/clients/gallery/contract/fixtures/escaping/model.json +++ b/clients/gallery/contract/fixtures/escaping/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "q&a", "title": "Q&a", "caption": "Ask & answer ", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -130,6 +137,7 @@ "key": "café", "title": "Café", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -180,6 +188,7 @@ "key": "x", "title": "X", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/extras/gallery.html b/clients/gallery/contract/fixtures/extras/gallery.html new file mode 100644 index 00000000..37811511 --- /dev/null +++ b/clients/gallery/contract/fixtures/extras/gallery.html @@ -0,0 +1,26 @@ +
    +

    Screenshots

    + +
    + + +
    +
    +

    The app

    +
      +
    • Billing, LightBilling, Dark

      Billing

      Plans & invoices

    • +
    • Home, LightHome, Dark

      Home

    • +
    +
    + + + +

    +
    +
    +
    diff --git a/clients/gallery/contract/fixtures/extras/manifest.json b/clients/gallery/contract/fixtures/extras/manifest.json new file mode 100644 index 00000000..bb991dff --- /dev/null +++ b/clients/gallery/contract/fixtures/extras/manifest.json @@ -0,0 +1,23 @@ +{ + "project": "acme/web", + "groups": [ + { + "name": "app", + "title": "The app", + "items": [ + {"name": "home-light-1440", "platform": "", "url": "https://app.visualci.com/g/acme/web/home-light-1440.png", "width": 1440, "height": 900, "sha256": "e1", "since": "2026-11-01T09:00:00+00:00"}, + {"name": "home-dark-1440", "platform": "", "url": "https://app.visualci.com/g/acme/web/home-dark-1440.png", "width": 1440, "height": 900, "sha256": "e2", "since": "2026-12-03T10:30:00+00:00"}, + {"name": "billing-light-1440", "platform": "", "url": "https://app.visualci.com/g/acme/web/billing-light-1440.png", "width": 1440, "height": 900, "sha256": "e3"}, + {"name": "billing-dark-1440", "platform": "", "url": "https://app.visualci.com/g/acme/web/billing-dark-1440.png", "width": 1440, "height": 900, "sha256": "e4", "since": ""} + ] + }, + { + "name": "phone", + "title": "On a phone", + "items": [ + {"name": "inbox-light-390", "platform": "", "url": "https://app.visualci.com/g/acme/web/inbox-light-390.png", "width": 390, "height": 844, "sha256": "e5", "since": "2026-10-01T09:00:00+00:00"}, + {"name": "inbox-dark-390", "platform": "", "url": "https://app.visualci.com/g/acme/web/inbox-dark-390.png", "width": 390, "height": 844, "sha256": "e6", "since": "2026-10-02T09:00:00+00:00"} + ] + } + ] +} diff --git a/clients/gallery/contract/fixtures/extras/model.json b/clients/gallery/contract/fixtures/extras/model.json new file mode 100644 index 00000000..edf43a53 --- /dev/null +++ b/clients/gallery/contract/fixtures/extras/model.json @@ -0,0 +1,207 @@ +{ + "layout": "grid", + "themeSwitch": true, + "seeAll": null, + "title": "Screenshots", + "label": "Screenshots", + "headingLevel": 2, + "id": "vg", + "credit": false, + "preload": null, + "deepLinks": false, + "text": { + "label": "Screenshots", + "open": "{title}: view full size", + "previous": "Previous screen", + "next": "Next screen", + "close": "Close", + "back": "Scroll back", + "forward": "Scroll forward", + "credit": "Screenshots by {link}", + "and": " and ", + "search": "Find a screen", + "empty": "Nothing found", + "new": "Fresh" + }, + "search": true, + "zoom": false, + "newBadges": 14, + "dimensions": [ + { + "key": "theme", + "label": "Theme", + "missing": "error", + "values": [ + { + "key": "light", + "label": "Light", + "below": null, + "shape": null + }, + { + "key": "dark", + "label": "Dark", + "below": null, + "shape": null + } + ] + }, + { + "key": "size", + "label": "Screen size", + "missing": "hide", + "values": [ + { + "key": "desktop", + "label": "Desktop", + "below": null, + "shape": "landscape" + }, + { + "key": "phone", + "label": "Phone", + "below": 768, + "shape": "portrait" + } + ] + } + ], + "groups": [ + { + "name": "app", + "title": "The app", + "slug": "app", + "fit": "cover", + "values": { + "theme": [ + "light", + "dark" + ], + "size": [ + "desktop" + ] + }, + "screens": [ + { + "key": "billing", + "title": "Billing", + "caption": "Plans & invoices", + "since": null, + "variants": [ + { + "values": { + "theme": "light", + "size": "desktop" + }, + "url": "https://app.visualci.com/g/acme/web/billing-light-1440.png", + "url2x": null, + "width": 1440, + "height": 900, + "bytes": null, + "bytes2x": null, + "thumb": null + }, + { + "values": { + "theme": "dark", + "size": "desktop" + }, + "url": "https://app.visualci.com/g/acme/web/billing-dark-1440.png", + "url2x": null, + "width": 1440, + "height": 900, + "bytes": null, + "bytes2x": null, + "thumb": null + } + ] + }, + { + "key": "home", + "title": "Home", + "caption": null, + "since": "2026-12-03T10:30:00+00:00", + "variants": [ + { + "values": { + "theme": "light", + "size": "desktop" + }, + "url": "https://app.visualci.com/g/acme/web/home-light-1440.png", + "url2x": null, + "width": 1440, + "height": 900, + "bytes": null, + "bytes2x": null, + "thumb": null + }, + { + "values": { + "theme": "dark", + "size": "desktop" + }, + "url": "https://app.visualci.com/g/acme/web/home-dark-1440.png", + "url2x": null, + "width": 1440, + "height": 900, + "bytes": null, + "bytes2x": null, + "thumb": null + } + ] + } + ] + }, + { + "name": "phone", + "title": "On a phone", + "slug": "phone", + "fit": "cover", + "values": { + "theme": [ + "light", + "dark" + ], + "size": [ + "phone" + ] + }, + "screens": [ + { + "key": "inbox", + "title": "Inbox", + "caption": null, + "since": "2026-10-02T09:00:00+00:00", + "variants": [ + { + "values": { + "theme": "light", + "size": "phone" + }, + "url": "https://app.visualci.com/g/acme/web/inbox-light-390.png", + "url2x": null, + "width": 390, + "height": 844, + "bytes": null, + "bytes2x": null, + "thumb": null + }, + { + "values": { + "theme": "dark", + "size": "phone" + }, + "url": "https://app.visualci.com/g/acme/web/inbox-dark-390.png", + "url2x": null, + "width": 390, + "height": 844, + "bytes": null, + "bytes2x": null, + "thumb": null + } + ] + } + ] + } + ] +} diff --git a/clients/gallery/contract/fixtures/extras/options.json b/clients/gallery/contract/fixtures/extras/options.json new file mode 100644 index 00000000..be114559 --- /dev/null +++ b/clients/gallery/contract/fixtures/extras/options.json @@ -0,0 +1,7 @@ +{ + "search": 3, + "zoom": false, + "newBadges": 14, + "screens": {"billing": {"caption": "Plans & invoices"}}, + "text": {"search": "Find a screen", "empty": "Nothing found", "new": "Fresh"} +} diff --git a/clients/gallery/contract/fixtures/fleetlayer/model.json b/clients/gallery/contract/fixtures/fleetlayer/model.json index ba3b3648..76ad55d6 100644 --- a/clients/gallery/contract/fixtures/fleetlayer/model.json +++ b/clients/gallery/contract/fixtures/fleetlayer/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -81,6 +87,7 @@ "key": "overview", "title": "Overview", "caption": "What needs you, every machine with its sessions, and the newest events.", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -140,6 +147,7 @@ "key": "access", "title": "Access", "caption": "Requests waiting for your approval.", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -173,6 +181,7 @@ "key": "logo", "title": "Logo", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -206,6 +215,7 @@ "key": "pages-edit-preview", "title": "The preview", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -239,6 +249,7 @@ "key": "status", "title": "Status", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -289,6 +300,7 @@ "key": "ios/sessions", "title": "Sessions", "caption": "Every session on every machine.", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -322,6 +334,7 @@ "key": "ios/approval", "title": "Approval", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -372,6 +385,7 @@ "key": "mac/approval", "title": "Approval", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -405,6 +419,7 @@ "key": "mac/proposal", "title": "Proposal", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/group-order/model.json b/clients/gallery/contract/fixtures/group-order/model.json index 8b01a5f0..9f45a539 100644 --- a/clients/gallery/contract/fixtures/group-order/model.json +++ b/clients/gallery/contract/fixtures/group-order/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "ios/a", "title": "A", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -130,6 +137,7 @@ "key": "a", "title": "A", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -180,6 +188,7 @@ "key": "android/a", "title": "A", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/light-only/model.json b/clients/gallery/contract/fixtures/light-only/model.json index ff5209e4..7408b301 100644 --- a/clients/gallery/contract/fixtures/light-only/model.json +++ b/clients/gallery/contract/fixtures/light-only/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "issues", "title": "Issues", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -113,6 +120,7 @@ "key": "projects", "title": "Projects", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -146,6 +154,7 @@ "key": "wiki", "title": "Wiki", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/page-theme/model.json b/clients/gallery/contract/fixtures/page-theme/model.json index 14596112..430aaeca 100644 --- a/clients/gallery/contract/fixtures/page-theme/model.json +++ b/clients/gallery/contract/fixtures/page-theme/model.json @@ -21,8 +21,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -83,6 +89,7 @@ "key": "screenshots/app/account", "title": "Account", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -116,6 +123,7 @@ "key": "screenshots/app/billing/free", "title": "Billing, free", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -149,6 +157,7 @@ "key": "screenshots/app/build_detail", "title": "Build detail", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -199,6 +208,7 @@ "key": "screenshots/app/account", "title": "Account", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/preload-off/model.json b/clients/gallery/contract/fixtures/preload-off/model.json index d1ce0dba..671f1b27 100644 --- a/clients/gallery/contract/fixtures/preload-off/model.json +++ b/clients/gallery/contract/fixtures/preload-off/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -113,6 +120,7 @@ "key": "settings_page", "title": "Settings page", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/single-group/model.json b/clients/gallery/contract/fixtures/single-group/model.json index e6e3ff09..3899a545 100644 --- a/clients/gallery/contract/fixtures/single-group/model.json +++ b/clients/gallery/contract/fixtures/single-group/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -113,6 +120,7 @@ "key": "settings_page", "title": "Settings page", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/strip-themes/model.json b/clients/gallery/contract/fixtures/strip-themes/model.json index 792fbe3d..9df7ef5b 100644 --- a/clients/gallery/contract/fixtures/strip-themes/model.json +++ b/clients/gallery/contract/fixtures/strip-themes/model.json @@ -18,8 +18,14 @@ "back": "Earlier", "forward": "Later", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -102,6 +108,7 @@ "key": "home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -156,6 +163,7 @@ "key": "mac/menu", "title": "Menu", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -197,6 +205,7 @@ "key": "docs/start", "title": "Start", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/strip-themes/options.json b/clients/gallery/contract/fixtures/strip-themes/options.json index 1dc7c3d6..7b8a3c01 100644 --- a/clients/gallery/contract/fixtures/strip-themes/options.json +++ b/clients/gallery/contract/fixtures/strip-themes/options.json @@ -24,5 +24,6 @@ "text": { "back": "Earlier", "forward": "Later" - } + }, + "search": true } diff --git a/clients/gallery/contract/fixtures/strip/model.json b/clients/gallery/contract/fixtures/strip/model.json index 08fa5b98..54528112 100644 --- a/clients/gallery/contract/fixtures/strip/model.json +++ b/clients/gallery/contract/fixtures/strip/model.json @@ -21,8 +21,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -84,6 +90,7 @@ "key": "screenshots/signing", "title": "Signing", "caption": "Not shown in a strip", + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -117,6 +124,7 @@ "key": "screenshots/data-requests", "title": "Data requests", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -150,6 +158,7 @@ "key": "screenshots/html-editor", "title": "Html editor", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -183,6 +192,7 @@ "key": "screenshots/pdf-editor", "title": "Pdf editor", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -216,6 +226,7 @@ "key": "screenshots/settings", "title": "Settings", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -249,6 +260,7 @@ "key": "screenshots/submissions", "title": "Submissions", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -282,6 +294,7 @@ "key": "screenshots/templates", "title": "Templates", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -332,6 +345,7 @@ "key": "ios/home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/text/model.json b/clients/gallery/contract/fixtures/text/model.json index ad74c542..2bc6b792 100644 --- a/clients/gallery/contract/fixtures/text/model.json +++ b/clients/gallery/contract/fixtures/text/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Captures d'écran par {link}", - "and": " et " + "and": " et ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "logo", "title": "Logo", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -113,6 +120,7 @@ "key": "tableau", "title": "Tableau", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -163,6 +171,7 @@ "key": "ios/factures", "title": "Factures", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/thumbs/model.json b/clients/gallery/contract/fixtures/thumbs/model.json index 11050554..dda7a3f9 100644 --- a/clients/gallery/contract/fixtures/thumbs/model.json +++ b/clients/gallery/contract/fixtures/thumbs/model.json @@ -23,8 +23,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -86,6 +92,7 @@ "key": "screenshots/app/billing", "title": "Billing", "caption": null, + "since": null, "variants": [ { "values": { @@ -155,6 +162,7 @@ "key": "screenshots/app/usage", "title": "Usage", "caption": null, + "since": null, "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/visualci/model.json b/clients/gallery/contract/fixtures/visualci/model.json index 95bb0a8f..46c5395c 100644 --- a/clients/gallery/contract/fixtures/visualci/model.json +++ b/clients/gallery/contract/fixtures/visualci/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -80,6 +86,7 @@ "key": "screenshots/app/account", "title": "Account", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -113,6 +120,7 @@ "key": "screenshots/app/billing/free", "title": "Billing, free", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -146,6 +154,7 @@ "key": "screenshots/app/build_detail", "title": "Build detail", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { @@ -196,6 +205,7 @@ "key": "screenshots/app/account", "title": "Account", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/fixtures/widths/model.json b/clients/gallery/contract/fixtures/widths/model.json index 2926286d..9fddd7c9 100644 --- a/clients/gallery/contract/fixtures/widths/model.json +++ b/clients/gallery/contract/fixtures/widths/model.json @@ -18,8 +18,14 @@ "back": "Scroll back", "forward": "Scroll forward", "credit": "Screenshots by {link}", - "and": " and " + "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New" }, + "search": false, + "zoom": true, + "newBadges": null, "dimensions": [ { "key": "theme", @@ -81,6 +87,7 @@ "key": "home", "title": "Home", "caption": null, + "since": "2026-12-01T09:00:00+00:00", "variants": [ { "values": { diff --git a/clients/gallery/contract/option-errors/newbadges-after-zoom.json b/clients/gallery/contract/option-errors/newbadges-after-zoom.json new file mode 100644 index 00000000..c3ef3bd7 --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-after-zoom.json @@ -0,0 +1 @@ +{"newBadges": 0, "zoom": 1} diff --git a/clients/gallery/contract/option-errors/newbadges-after-zoom.message b/clients/gallery/contract/option-errors/newbadges-after-zoom.message new file mode 100644 index 00000000..c6ba41d4 --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-after-zoom.message @@ -0,0 +1 @@ +gallery option zoom is invalid diff --git a/clients/gallery/contract/option-errors/newbadges-too-many.json b/clients/gallery/contract/option-errors/newbadges-too-many.json new file mode 100644 index 00000000..4333ef54 --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-too-many.json @@ -0,0 +1 @@ +{"newBadges": 3651} diff --git a/clients/gallery/contract/option-errors/newbadges-too-many.message b/clients/gallery/contract/option-errors/newbadges-too-many.message new file mode 100644 index 00000000..3db95778 --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-too-many.message @@ -0,0 +1 @@ +gallery option newBadges is invalid diff --git a/clients/gallery/contract/option-errors/newbadges-zero.json b/clients/gallery/contract/option-errors/newbadges-zero.json new file mode 100644 index 00000000..0f9b4e6f --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-zero.json @@ -0,0 +1 @@ +{"newBadges": 0} diff --git a/clients/gallery/contract/option-errors/newbadges-zero.message b/clients/gallery/contract/option-errors/newbadges-zero.message new file mode 100644 index 00000000..3db95778 --- /dev/null +++ b/clients/gallery/contract/option-errors/newbadges-zero.message @@ -0,0 +1 @@ +gallery option newBadges is invalid diff --git a/clients/gallery/contract/option-errors/search-after-text.json b/clients/gallery/contract/option-errors/search-after-text.json new file mode 100644 index 00000000..b13fdbbf --- /dev/null +++ b/clients/gallery/contract/option-errors/search-after-text.json @@ -0,0 +1 @@ +{"search": "x", "text": 1} diff --git a/clients/gallery/contract/option-errors/search-after-text.message b/clients/gallery/contract/option-errors/search-after-text.message new file mode 100644 index 00000000..0bd4fd49 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-after-text.message @@ -0,0 +1 @@ +gallery option text is invalid diff --git a/clients/gallery/contract/option-errors/search-fraction.json b/clients/gallery/contract/option-errors/search-fraction.json new file mode 100644 index 00000000..61d585c3 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-fraction.json @@ -0,0 +1 @@ +{"search": 2.5} diff --git a/clients/gallery/contract/option-errors/search-fraction.message b/clients/gallery/contract/option-errors/search-fraction.message new file mode 100644 index 00000000..3eb03934 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-fraction.message @@ -0,0 +1 @@ +gallery option search is invalid diff --git a/clients/gallery/contract/option-errors/search-negative.json b/clients/gallery/contract/option-errors/search-negative.json new file mode 100644 index 00000000..85ad474c --- /dev/null +++ b/clients/gallery/contract/option-errors/search-negative.json @@ -0,0 +1 @@ +{"search": -1} diff --git a/clients/gallery/contract/option-errors/search-negative.message b/clients/gallery/contract/option-errors/search-negative.message new file mode 100644 index 00000000..3eb03934 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-negative.message @@ -0,0 +1 @@ +gallery option search is invalid diff --git a/clients/gallery/contract/option-errors/search-string.json b/clients/gallery/contract/option-errors/search-string.json new file mode 100644 index 00000000..58931a83 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-string.json @@ -0,0 +1 @@ +{"search": "yes"} diff --git a/clients/gallery/contract/option-errors/search-string.message b/clients/gallery/contract/option-errors/search-string.message new file mode 100644 index 00000000..3eb03934 --- /dev/null +++ b/clients/gallery/contract/option-errors/search-string.message @@ -0,0 +1 @@ +gallery option search is invalid diff --git a/clients/gallery/contract/option-errors/zoom-after-search.json b/clients/gallery/contract/option-errors/zoom-after-search.json new file mode 100644 index 00000000..eabee3b3 --- /dev/null +++ b/clients/gallery/contract/option-errors/zoom-after-search.json @@ -0,0 +1 @@ +{"newBadges": 0, "zoom": 1, "search": "x"} diff --git a/clients/gallery/contract/option-errors/zoom-after-search.message b/clients/gallery/contract/option-errors/zoom-after-search.message new file mode 100644 index 00000000..3eb03934 --- /dev/null +++ b/clients/gallery/contract/option-errors/zoom-after-search.message @@ -0,0 +1 @@ +gallery option search is invalid diff --git a/clients/gallery/contract/option-errors/zoom-string.json b/clients/gallery/contract/option-errors/zoom-string.json new file mode 100644 index 00000000..12a1d510 --- /dev/null +++ b/clients/gallery/contract/option-errors/zoom-string.json @@ -0,0 +1 @@ +{"zoom": "no"} diff --git a/clients/gallery/contract/option-errors/zoom-string.message b/clients/gallery/contract/option-errors/zoom-string.message new file mode 100644 index 00000000..c6ba41d4 --- /dev/null +++ b/clients/gallery/contract/option-errors/zoom-string.message @@ -0,0 +1 @@ +gallery option zoom is invalid diff --git a/clients/gallery/js/src/gallery.css b/clients/gallery/js/src/gallery.css index d3a19ae0..50519598 100644 --- a/clients/gallery/js/src/gallery.css +++ b/clients/gallery/js/src/gallery.css @@ -328,10 +328,59 @@ .vg[data-vg] .vg-missing[data-vg-shown] { display: grid; } -/* A card with no shot for the chosen value of a "hide" dimension (a desktop-only screen at Phone) isn't shown. */ -.vg[data-vg] .vg-card[data-vg-off] { +/* A card with no shot for the chosen value of a "hide" dimension (a desktop-only screen at Phone) isn't shown, nor one + the search doesn't match. */ +.vg[data-vg] .vg-card[data-vg-off], +.vg[data-vg] .vg-card[data-vg-unmatched] { display: none; } +/* The search box (the `search` option), over the tabs. */ +.vg[data-vg] .vg-search { + margin-bottom: var(--vg-gap); +} +.vg[data-vg] .vg-search-input { + box-sizing: border-box; + width: min(100%, 20rem); + padding: 0.5rem 0.75rem; + font: inherit; + font-size: var(--vg-small); + color: var(--vg-ink); + background: var(--vg-paper); + border: var(--vg-rule-width) solid var(--vg-rule); + border-radius: var(--vg-radius-sm); +} +.vg[data-vg] .vg-search-input:focus-visible { + outline: 2px solid var(--vg-accent); + outline-offset: 1px; +} +.vg-tabs [role="tab"][hidden] { + display: none; +} +.vg[data-vg] .vg-empty { + color: var(--vg-muted); + padding: var(--vg-gap) 0; +} +.vg[data-vg] .vg-empty[hidden], +.vg[data-vg] .vg-new[hidden] { + display: none; +} +/* The New badge (the `newBadges` option), over the card's top corner. */ +.vg-card { + position: relative; +} +.vg[data-vg] .vg-new { + position: absolute; + top: 0.5rem; + left: 0.5rem; + padding: 0.125rem 0.5rem; + font-size: 0.75rem; + font-weight: 600; + line-height: 1.5; + color: var(--vg-paper); + background: var(--vg-accent); + border-radius: 999px; + pointer-events: none; +} /* Before the script runs: the page's when it's set, else the reader's setting. */ :root[data-theme="light"] .vg:not([data-vg-theme]) @@ -504,6 +553,21 @@ max-height: 100%; object-fit: contain; } +/* Zoom: the browser leaves two-finger gestures to the gallery, and a zoomed image grows past the view, which scrolls. */ +.vg[data-vg]:not([data-vg-zoom="off"]) .vg-box-view { + touch-action: pan-x pan-y; +} +.vg-box-view[data-vg-zoomed], +.vg-box-view[data-vg-fit][data-vg-zoomed] { + display: block; + cursor: grab; +} +.vg-box-view[data-vg-zoomed] img, +.vg-box-view[data-vg-fit][data-vg-zoomed] img { + max-width: none; + max-height: none; + height: auto; +} .vg-box-view .vg-missing { display: grid; min-height: 12rem; diff --git a/clients/gallery/js/src/hydrate.ts b/clients/gallery/js/src/hydrate.ts index 6c37b11b..c3c9f4b2 100644 --- a/clients/gallery/js/src/hydrate.ts +++ b/clients/gallery/js/src/hydrate.ts @@ -327,6 +327,7 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery if (!dims.some((d) => d.key === key)) return; choice[key] = value; sync(); + if (searchBox?.value) filter(); if (!selecting) replan(); } @@ -355,7 +356,9 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery /** The cards the full-size view steps through: the shown tab's, those it shows. */ function cards(): HTMLElement[] { - return all(".vg-panel:not([hidden]) .vg-card").filter((c) => !c.hasAttribute("data-vg-off")); + return all(".vg-panel:not([hidden]) .vg-card").filter( + (c) => !c.hasAttribute("data-vg-off") && !c.hasAttribute("data-vg-unmatched"), + ); } /** The full-size view's values for a card: the choice's where the card has them, else its first. */ @@ -363,6 +366,7 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery function show(card: HTMLElement) { current = card; + resetZoom(); writeLink(card); boxTitle.textContent = card.querySelector(".vg-card-title")?.textContent ?? ""; // The view's switches offer only the values this screen has, so switching never shows nothing. @@ -463,6 +467,150 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery show(list[next]); } + // --- Search (the grid's .vg-search-input): every word typed must be in a card's title or caption, ignoring case and + // accents. Cards that don't match are marked data-vg-unmatched, tabs with none are hidden, and when no tab has any + // the empty state shows. + const searchBox = root.querySelector(".vg-search-input"); + const empty = root.querySelector(".vg-empty"); + const fold = (text: string) => + text + .toLowerCase() + .normalize("NFD") + .replace(/[\u0300-\u036f]/g, ""); + function filter() { + if (!searchBox) return; + const words = fold(searchBox.value).split(/\s+/).filter(Boolean); + let shown: HTMLButtonElement | null = null; + let first: HTMLButtonElement | null = null; + let any = false; + for (const p of all(".vg-panel")) { + let hits = 0; + for (const card of toArray(p.querySelectorAll(".vg-card"))) { + const text = fold( + `${card.querySelector(".vg-card-title")?.textContent ?? ""} ${card.querySelector(".vg-caption")?.textContent ?? ""}`, + ); + const hit = words.every((w) => text.indexOf(w) !== -1); + if (hit) card.removeAttribute("data-vg-unmatched"); + else card.setAttribute("data-vg-unmatched", ""); + if (hit && !card.hasAttribute("data-vg-off")) hits++; + } + if (hits > 0) any = true; + const tab = tabs.find((t) => t.getAttribute("aria-controls") === p.id); + if (!tab) continue; + tab.hidden = hits === 0 && words.length > 0; + if (!tab.hidden && !first) first = tab; + if (!tab.hidden && tab.getAttribute("aria-selected") === "true") shown = tab; + } + // The shown tab has no match: the first that has one. + if (!shown && first) select(first); + if (empty) empty.hidden = any || words.length === 0; + } + const onSearch = () => filter(); + + // --- New badges (data-vg-new=""): a card whose data-vg-since is within that many days shows its badge. It's + // decided here, in the reader's browser, so a page built long ago never calls an old screen new. + const newDays = Number(root.getAttribute("data-vg-new")); + if (newDays > 0) { + for (const card of all("[data-vg-since]")) { + const at = Date.parse(card.getAttribute("data-vg-since") ?? ""); + const badge = card.querySelector(".vg-new"); + if (badge) badge.hidden = !(at <= Date.now() && Date.now() - at < newDays * 86_400_000); + } + } + + // --- Zoom in the full-size view (on unless data-vg-zoom="off"): ctrl- or cmd-wheel and a trackpad's pinch, a + // double-click, two fingers on a touch screen, and the + - and 0 keys. No buttons. The image grows in the layout + // (not a transform), so the view's own scrolling pans it, a finger's included; a mouse drags it. Instant, so there's + // no motion to reduce. A new screen starts unzoomed. + const zoomable = root.getAttribute("data-vg-zoom") !== "off"; + const MAX_ZOOM = 8; + let scale = 1; + let baseWidth = 0; + function zoomTo(next: number, x?: number, y?: number) { + const img = view.querySelector("img"); + if (!zoomable || !img) return; + const to = Math.min(Math.max(next, 1), MAX_ZOOM); + if (to === scale) return; + const rect = view.getBoundingClientRect(); + // The point under the pointer (or the view's middle) stays where it is. + const px = x ?? rect.width / 2; + const py = y ?? rect.height / 2; + const cx = view.scrollLeft + px; + const cy = view.scrollTop + py; + if (scale === 1) baseWidth = img.getBoundingClientRect().width || Number(img.getAttribute("width")) || 0; + const ratio = to / scale; + scale = to; + if (scale === 1) { + resetZoom(); + return; + } + view.setAttribute("data-vg-zoomed", ""); + img.style.width = `${Math.round(baseWidth * scale)}px`; + view.scrollLeft = cx * ratio - px; + view.scrollTop = cy * ratio - py; + } + function resetZoom() { + scale = 1; + view.removeAttribute("data-vg-zoomed"); + view.querySelector("img")?.style.removeProperty("width"); + } + /** Zooms to `next` about a point on screen. */ + const zoomAt = (next: number, clientX: number, clientY: number) => { + const rect = view.getBoundingClientRect(); + zoomTo(next, clientX - rect.left, clientY - rect.top); + }; + const onWheel = (e: WheelEvent) => { + // A plain wheel scrolls; with ctrl (a trackpad's pinch sends that) or cmd it zooms. + if (!(e.ctrlKey || e.metaKey)) return; + e.preventDefault(); + zoomAt(scale * Math.exp(-e.deltaY * 0.01), e.clientX, e.clientY); + }; + const onDouble = (e: MouseEvent) => { + if (!(e.target as Element).closest?.("img")) return; + zoomAt(scale > 1 ? 1 : 2, e.clientX, e.clientY); + }; + const pointers = new Map(); + let pinch: { distance: number; scale: number } | null = null; + let drag: { x: number; y: number; left: number; top: number } | null = null; + const distance = () => { + const [a, b] = Array.from(pointers.values()); + return Math.hypot(a.x - b.x, a.y - b.y); + }; + const onDown = (e: PointerEvent) => { + pointers.set(e.pointerId, { x: e.clientX, y: e.clientY }); + if (pointers.size === 2) { + pinch = { distance: distance(), scale }; + drag = null; + } else if (pointers.size === 1 && e.pointerType === "mouse" && scale > 1 && e.button === 0) { + drag = { x: e.clientX, y: e.clientY, left: view.scrollLeft, top: view.scrollTop }; + e.preventDefault(); + } + }; + const onMove = (e: PointerEvent) => { + if (!pointers.has(e.pointerId)) return; + pointers.set(e.pointerId, { x: e.clientX, y: e.clientY }); + if (pinch && pointers.size === 2 && pinch.distance > 0) { + const [a, b] = Array.from(pointers.values()); + zoomAt((pinch.scale * distance()) / pinch.distance, (a.x + b.x) / 2, (a.y + b.y) / 2); + } else if (drag) { + view.scrollLeft = drag.left - (e.clientX - drag.x); + view.scrollTop = drag.top - (e.clientY - drag.y); + } + }; + const onUp = (e: PointerEvent) => { + pointers.delete(e.pointerId); + if (pointers.size < 2) pinch = null; + if (pointers.size === 0) drag = null; + }; + function zoomKey(e: KeyboardEvent): boolean { + if (!zoomable || e.ctrlKey || e.metaKey || e.altKey) return false; + if (e.key === "+" || e.key === "=") zoomTo(scale * 1.25); + else if (e.key === "-" || e.key === "_") zoomTo(scale / 1.25); + else if (e.key === "0") zoomTo(1); + else return false; + return true; + } + // --- Deep links (data-vg-links): `#[/][/][?=&…]` names the shown tab, the open // screen and the chosen values. Written with replaceState once the reader changes something, read on load and // when the hash changes. Anything it doesn't know is ignored. @@ -764,6 +912,7 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery if (box.open && box.contains(target)) { if (e.key === "ArrowRight") step(1); else if (e.key === "ArrowLeft") step(-1); + else if (zoomKey(e)) e.preventDefault(); return; } if (target.getAttribute("role") !== "tab") return; @@ -787,6 +936,8 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery unlock?.(); current = null; writeLink(); + resetZoom(); + pointers.clear(); view.replaceChildren(); if (opener?.isConnected) opener.focus(); opener = null; @@ -824,6 +975,15 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery root.addEventListener("keyup", onKeyUp); box.addEventListener("close", onClose); track?.addEventListener("scroll", edges, { passive: true }); + searchBox?.addEventListener("input", onSearch); + if (zoomable) { + view.addEventListener("wheel", onWheel, { passive: false }); + view.addEventListener("dblclick", onDouble); + view.addEventListener("pointerdown", onDown); + view.addEventListener("pointermove", onMove); + view.addEventListener("pointerup", onUp); + view.addEventListener("pointercancel", onUp); + } for (const img of all("img.vg-img")) watch(img); sync(); @@ -868,6 +1028,13 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery root.removeEventListener("keyup", onKeyUp); box.removeEventListener("close", onClose); track?.removeEventListener("scroll", edges); + searchBox?.removeEventListener("input", onSearch); + view.removeEventListener("wheel", onWheel); + view.removeEventListener("dblclick", onDouble); + view.removeEventListener("pointerdown", onDown); + view.removeEventListener("pointermove", onMove); + view.removeEventListener("pointerup", onUp); + view.removeEventListener("pointercancel", onUp); observer?.disconnect(); resize?.disconnect(); scheme.removeEventListener?.("change", onScheme); diff --git a/clients/gallery/js/src/model.ts b/clients/gallery/js/src/model.ts index e063ffc0..a49df513 100644 --- a/clients/gallery/js/src/model.ts +++ b/clients/gallery/js/src/model.ts @@ -107,6 +107,13 @@ export interface Options { deepLinks?: boolean; /** The gallery's own words, for another language or another tone: any of TEXT_DEFAULTS' keys. */ text?: Partial | null; + /** The search box over the grid, which filters cards by title and caption across tabs. A number (default 40): shown + * once the gallery has that many screens; true, always; false, never. The strip has none. */ + search?: boolean | number; + /** Zoom in the full-size view: pinch, ctrl-wheel, double-click and the + and - keys, with no buttons. Default true. */ + zoom?: boolean; + /** A New badge on screens whose picture changed in the last `days` days (true: 30). Default false. */ + newBadges?: boolean | number; } /** The gallery's own words. `{title}` in `open` is the screen's title; `{link}` in `credit` is the link to @@ -122,6 +129,9 @@ export interface Text { forward: string; credit: string; and: string; + search: string; + empty: string; + new: string; } export const TEXT_DEFAULTS: Text = { label: "Screenshots", @@ -133,7 +143,14 @@ export const TEXT_DEFAULTS: Text = { forward: "Scroll forward", credit: "Screenshots by {link}", and: " and ", + search: "Search screens", + empty: "No screens match", + new: "New", }; +/** The search box's default threshold: shown once the gallery has this many screens. */ +export const SEARCH_FROM = 40; +/** The New badge's default window, in days. */ +export const NEW_DAYS = 30; const TEXT_KEYS = Object.keys(TEXT_DEFAULTS) as (keyof Text)[]; /** The preloader's limits: `fold` above-the-fold thumbnails always load; past them at most `count` images and @@ -175,6 +192,8 @@ export interface Screen { key: string; title: string; caption: string | null; + /** The newest `since` of the manifest items it's made from (the last time one of its pictures changed), or null. */ + since: string | null; variants: Variant[]; } export interface Group { @@ -199,6 +218,11 @@ export interface Model { preload: null | "off" | Required; deepLinks: boolean; text: Text; + /** Whether the grid shows its search box. */ + search: boolean; + zoom: boolean; + /** The New badge's window in days, or null: no badges. */ + newBadges: number | null; dimensions: Dimension[]; groups: Group[]; } @@ -504,6 +528,19 @@ export function buildModel(manifest: Manifest, options: Options = {}): Model { const text = { ...TEXT_DEFAULTS }; for (const k of TEXT_KEYS) text[k] = textOpt[k] ?? TEXT_DEFAULTS[k]; const title = titleOpt === undefined ? text.label : titleOpt; + const searchOpt = + opt( + o.search, + (v) => typeof v === "boolean" || (typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= MAX_SIZE), + "search", + ) ?? SEARCH_FROM; + const zoom = opt(o.zoom, (v) => typeof v === "boolean", "zoom") ?? true; + const newOpt = + opt( + o.newBadges, + (v) => typeof v === "boolean" || (typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= 3650), + "newBadges", + ) ?? false; const slugs = new Set(); const groups: Group[] = []; @@ -524,9 +561,14 @@ export function buildModel(manifest: Manifest, options: Options = {}): Model { named[d.key] = keys.length > 0 ? keys : [d.values[0].key]; } const screens = new Map>(); + const sinces = new Map(); for (const { item, shot } of shots) { const variants = screens.get(shot.key) ?? new Map(); screens.set(shot.key, variants); + // Compared by code point: VisualCI writes every time in the same RFC 3339 form, in UTC. + const since = typeof item.since === "string" && item.since !== "" ? item.since : null; + const was = sinces.get(shot.key); + if (since !== null && (was === undefined || compare(since, was) > 0)) sinces.set(shot.key, since); const own = (d: Dimension) => Object.prototype.hasOwnProperty.call(shot.values, d.key); for (const values of combinations(dimensions, (d) => (own(d) ? [shot.values[d.key]] : named[d.key]))) { const vid = dimensions.map((d) => values[d.key]).join("."); @@ -594,6 +636,7 @@ export function buildModel(manifest: Manifest, options: Options = {}): Model { key, title: set?.title ?? humanize(key.split("/").slice(prefix)), caption: set?.caption ?? null, + since: sinces.get(key) ?? null, variants, }; }) @@ -612,6 +655,7 @@ export function buildModel(manifest: Manifest, options: Options = {}): Model { }); } if (groups.length === 0) fail("the gallery manifest has no screenshots to show"); + const screenCount = groups.reduce((n, g) => n + g.screens.length, 0); // Named groups first; the rest keep the manifest's order (the sort is stable). const groupRank = rankBy(groupOrder); @@ -629,6 +673,9 @@ export function buildModel(manifest: Manifest, options: Options = {}): Model { preload, deepLinks, text, + search: layout === "grid" && (searchOpt === true || (typeof searchOpt === "number" && screenCount >= searchOpt)), + zoom, + newBadges: newOpt === false ? null : newOpt === true ? NEW_DAYS : newOpt, dimensions: withShapes(dimensions, groups), groups, }; diff --git a/clients/gallery/js/src/render.ts b/clients/gallery/js/src/render.ts index 6e8faf7b..6a391a84 100644 --- a/clients/gallery/js/src/render.ts +++ b/clients/gallery/js/src/render.ts @@ -130,10 +130,14 @@ function card( `
  • " + `` + imgs.map((i) => image(model, g, sc.title, i, shown(i))).join("") + "" + + (model.newBadges !== null && sc.since !== null + ? `` + : "") + `<${heading} class="vg-card-title">${escapeHtml(sc.title)}` + (caption && sc.caption !== null ? `

    ${escapeHtml(sc.caption)}

    ` : "") + "
  • " @@ -215,9 +219,17 @@ export function render(model: Model): string { (model.themeSwitch ? "" : ' data-vg-theme-source="page"') + preloadAttr(model.preload) + (model.deepLinks ? " data-vg-links" : "") + + (model.zoom ? "" : ' data-vg-zoom="off"') + + (model.newBadges !== null ? ` data-vg-new="${model.newBadges}"` : "") + ">", ); if (model.title !== null) out.push(`<${h(0)} class="vg-title">${escapeHtml(model.title)}`); + if (model.search) { + const words = escapeHtml(model.text.search); + out.push( + ``, + ); + } if (model.layout === "strip") strip(model, id, choice, h(below), out); else grid(model, id, choice, h(below), h(below + 1), out); @@ -288,6 +300,7 @@ function grid(model: Model, id: string, choice: Choice, gh: string, ch: string, out.push(""); out.push(""); }); + if (model.search) out.push(``); } function strip(model: Model, id: string, choice: Choice, ch: string, out: string[]) { diff --git a/clients/gallery/js/test/hydrate.test.ts b/clients/gallery/js/test/hydrate.test.ts index ba885a51..bd1cf376 100644 --- a/clients/gallery/js/test/hydrate.test.ts +++ b/clients/gallery/js/test/hydrate.test.ts @@ -574,3 +574,90 @@ describe("dimensions", () => { expect(shown("docs/start")).toMatch(/docs\/start-light-fr-1440\.png$/); // English chosen; Docs is French only }); }); + +describe("search, zoom and New badges", () => { + const search = (text: string) => { + const input = q(".vg-search-input"); + input.value = text; + input.dispatchEvent(new Event("input")); + }; + const shownCards = () => + Array.from(document.querySelectorAll(".vg-panel:not([hidden]) .vg-card")) + .filter((c) => !c.hasAttribute("data-vg-unmatched") && !c.hasAttribute("data-vg-off")) + .map((c) => c.dataset.vgScreen); + + it("filter cards by title and caption across tabs, ignoring case and accents", () => { + page("extras"); + search("INVOICES"); + expect(shownCards()).toEqual(["billing"]); + expect(q("#vg-tab-phone").hidden).toBe(true); + search("inbóx"); + // The shown tab has no match: the first tab that has one is shown. + expect(q("#vg-panel-phone").hidden).toBe(false); + expect(q("#vg-tab-app").hidden).toBe(true); + expect(shownCards()).toEqual(["inbox"]); + expect(q(".vg-empty").hidden).toBe(true); + search("nothing like it"); + expect(q(".vg-empty").hidden).toBe(false); + search(""); + expect(q("#vg-tab-app").hidden).toBe(false); + expect(q("#vg-tab-phone").hidden).toBe(false); + expect(q(".vg-empty").hidden).toBe(true); + expect(shownCards()).toEqual(["inbox"]); + }); + + it("step only through the screens the search shows", () => { + page("extras"); + search("home"); + click(q('[data-vg-screen="home"] a')); + click(q('.vg-box [data-vg-step="1"]')); + expect(q(".vg-box-title").textContent).toBe("Home"); + }); + + it("show a New badge only within its window, decided in the browser", () => { + vi.useFakeTimers({ now: new Date("2026-12-10T00:00:00Z"), toFake: ["Date"] }); + try { + page("extras"); + expect(q('[data-vg-screen="home"] .vg-new').hidden).toBe(false); + expect(q('[data-vg-screen="inbox"] .vg-new').hidden).toBe(true); + } finally { + vi.useRealTimers(); + } + }); + + it("zoom with the keys and reset on the next screen; never with data-vg-zoom=off", () => { + page("visualci"); + const first = document.querySelector(".vg-panel:not([hidden]) .vg-card a")!; + click(first); + const view = q(".vg-box-view"); + const key = (k: string) => + view.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, cancelable: true })); + key("+"); + expect(view.hasAttribute("data-vg-zoomed")).toBe(true); + expect(view.querySelector("img")!.style.width).not.toBe(""); + key("0"); + expect(view.hasAttribute("data-vg-zoomed")).toBe(false); + key("+"); + click(q('.vg-box [data-vg-step="1"]')); + expect(view.hasAttribute("data-vg-zoomed")).toBe(false); + + page("extras"); + click(q('[data-vg-screen="home"] a')); + q(".vg-box-view").dispatchEvent(new KeyboardEvent("keydown", { key: "+", bubbles: true })); + expect(q(".vg-box-view").hasAttribute("data-vg-zoomed")).toBe(false); + }); + + it("zoom with ctrl-wheel about the pointer, and scroll with a plain wheel", () => { + page("visualci"); + click(document.querySelector(".vg-panel:not([hidden]) .vg-card a")!); + const view = q(".vg-box-view"); + const plain = new WheelEvent("wheel", { deltaY: -100, cancelable: true }); + view.dispatchEvent(plain); + expect(plain.defaultPrevented).toBe(false); + expect(view.hasAttribute("data-vg-zoomed")).toBe(false); + const pinch = new WheelEvent("wheel", { deltaY: -100, ctrlKey: true, cancelable: true }); + view.dispatchEvent(pinch); + expect(pinch.defaultPrevented).toBe(true); + expect(view.hasAttribute("data-vg-zoomed")).toBe(true); + }); +}); From 5806f4cf85a5370f3c019a58a8e8490be7da000f Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 14:28:23 +0000 Subject: [PATCH 2/4] Gallery (sc-9560): search, zoom and newBadges in Ruby, Python, Rust and Hugo, and the docs Every renderer matches the contract's extras fixture and the new option errors. The options guide gains Search, Zoom and New badges sections and the three text keys; the language guides list the options. --- clients/gallery/astro/README.md | 2 +- clients/gallery/astro/src/Gallery.astro | 2 +- .../layouts/_partials/visualci-gallery.html | 5 +- .../_partials/visualci-gallery/card.html | 6 +- .../visualci-gallery/check-names.html | 4 +- .../visualci-gallery/check-options.html | 8 +- .../_partials/visualci-gallery/model.html | 26 ++++++- .../_partials/visualci-gallery/render.html | 7 ++ .../visualci-gallery/text-defaults.html | 5 +- clients/gallery/hugo/tests/assets/units.json | 4 +- clients/gallery/js/README.md | 5 +- clients/gallery/python/README.md | 8 +- .../python/src/visualci_gallery/__init__.py | 2 +- .../python/src/visualci_gallery/_model.py | 27 +++++++ .../python/src/visualci_gallery/_render.py | 13 ++++ clients/gallery/python/tests/test_gallery.py | 21 ++++++ clients/gallery/ruby/README.md | 6 +- clients/gallery/ruby/lib/visualci/gallery.rb | 28 ++++++- .../ruby/lib/visualci/gallery/renderer.rb | 14 +++- clients/gallery/ruby/test/gallery_test.rb | 15 +++- clients/gallery/rust/README.md | 19 ++++- clients/gallery/rust/src/lib.rs | 6 +- clients/gallery/rust/src/model.rs | 73 ++++++++++++++++++- clients/gallery/rust/src/render.rs | 22 +++++- clients/gallery/rust/tests/contract.rs | 27 +++++++ frontend/content/docs/gallery/hugo.md | 2 +- frontend/content/docs/gallery/mkdocs.md | 2 +- frontend/content/docs/gallery/options.md | 27 +++++++ frontend/content/docs/gallery/python.md | 4 +- frontend/content/docs/gallery/ruby.md | 4 +- frontend/content/docs/gallery/rust.md | 2 +- 31 files changed, 353 insertions(+), 43 deletions(-) diff --git a/clients/gallery/astro/README.md b/clients/gallery/astro/README.md index 5f72dc1e..be83ca70 100644 --- a/clients/gallery/astro/README.md +++ b/clients/gallery/astro/README.md @@ -20,7 +20,7 @@ import Gallery from "visualci-astro-gallery"; ``` The props are `visualci-gallery`'s options (`title`, `headingLevel`, `id`, `screens`, `order`, `groups`, -`groupOrder`, `credit`, `layout`, `themeSwitch`, `seeAll`, `preload`, `deepLinks`, `text`) and `load()`'s (`manifest`, `timeout`, `attempts`, +`groupOrder`, `credit`, `layout`, `themeSwitch`, `seeAll`, `preload`, `deepLinks`, `text`, `search`, `zoom`, `newBadges`) and `load()`'s (`manifest`, `timeout`, `attempts`, `fetch`). Give the gallery your site's look with the `--vg-*` CSS variables, set on `.vg` or any element around it. They win over the component's defaults in any stylesheet order: diff --git a/clients/gallery/astro/src/Gallery.astro b/clients/gallery/astro/src/Gallery.astro index 63d84112..c332392a 100644 --- a/clients/gallery/astro/src/Gallery.astro +++ b/clients/gallery/astro/src/Gallery.astro @@ -6,7 +6,7 @@ // // // The props are the library's options (title, headingLevel, id, screens, order, groups, groupOrder, credit, layout, -// themeSwitch, seeAll, preload, deepLinks, text) and load()'s (manifest, timeout, attempts, fetch). The default stylesheet comes with it; set the +// themeSwitch, seeAll, preload, deepLinks, text, search, zoom, newBadges) and load()'s (manifest, timeout, attempts, fetch). The default stylesheet comes with it; set the // --vg-* variables on .vg (or an ancestor) to give it the site's look. import { load, render, type LoadOptions } from "visualci-gallery/render"; import "visualci-gallery/gallery.css"; diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery.html index 6c88f4d6..26abb3bb 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery.html @@ -4,8 +4,9 @@ "page" is the page it's on (the gallery's script and stylesheet are added once a page), "manifest" the gallery manifest's URL (or a manifest already parsed), and every other key a gallery option in the contract's spelling (title, -headingLevel, id, dimensions, screens, order, groups, groupOrder, credit, layout, themeSwitch, seeAll, preload). A -manifest that can't be read, or has nothing to show, and invalid options fail the build. */ -}} +headingLevel, id, dimensions, screens, order, groups, groupOrder, credit, layout, themeSwitch, seeAll, preload, +deepLinks, text, search, zoom, newBadges). A manifest that can't be read, or has nothing to show, and invalid options +fail the build. */ -}} {{- $page := .page -}} {{- $where := .where -}} {{- if not $where }}{{ $where = "a template" }}{{ with $page }}{{ $where = .RelPermalink }}{{ end }}{{ end -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/card.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/card.html index 4a09d96a..1569d53b 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/card.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/card.html @@ -47,6 +47,8 @@ {{- $out := printf `
  • ` $out (partial "visualci-gallery/escape.html" (index $first.vs 0).url) $open -}} {{- range $img := $imgs -}} @@ -62,6 +64,8 @@ {{- end -}} {{- $out = printf "%s%s" $out (partial "visualci-gallery/image.html" (dict "model" $model "group" $.group "title" $sc.title "variants" $img.vs "ids" $ids "shown" $shown)) -}} {{- end -}} -{{- $out = printf `%s<%s class="vg-card-title">%s` $out .heading $title .heading -}} +{{- $out = printf "%s" $out -}} +{{- if $new }}{{ $out = printf `%s` $out (partial "visualci-gallery/escape.html" $model.text.new) }}{{ end -}} +{{- $out = printf `%s<%s class="vg-card-title">%s` $out .heading $title .heading -}} {{- if and .caption (ne $sc.caption nil) }}{{ $out = printf `%s

    %s

    ` $out (partial "visualci-gallery/escape.html" $sc.caption) }}{{ end -}} {{- return printf "%s
  • " $out -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-names.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-names.html index 55e269ff..488281c2 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-names.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-names.html @@ -1,10 +1,10 @@ {{- /* An option name the gallery doesn't have: its message, or "". The contract ignores other fields, but in a shortcode or a partial call a misspelled option (heading_level, themeswitch) would otherwise do nothing. */ -}} -{{- $known := slice "title" "headingLevel" "id" "dimensions" "screens" "order" "groups" "groupOrder" "credit" "layout" "themeSwitch" "seeAll" "preload" "deepLinks" "text" -}} +{{- $known := slice "title" "headingLevel" "id" "dimensions" "screens" "order" "groups" "groupOrder" "credit" "layout" "themeSwitch" "seeAll" "preload" "deepLinks" "text" "search" "zoom" "newBadges" -}} {{- $err := "" -}} {{- range $k, $_ := . -}} {{- if not (in $known $k) -}} - {{- $err = printf "unknown option %s (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks)" $k -}} + {{- $err = printf "unknown option %s (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks, newBadges)" $k -}} {{- break -}} {{- end -}} {{- end -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-options.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-options.html index 00f3a6d1..45324ec5 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-options.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/check-options.html @@ -4,7 +4,7 @@ {{- $sizeKeys := slice -}} {{- range .dims }}{{ if eq .key "size" }}{{ range .values }}{{ $sizeKeys = $sizeKeys | append .key }}{{ end }}{{ end }}{{ end -}} {{- $bad := "" -}} -{{- range $name := slice "screens" "groups" "order" "groupOrder" "credit" "themeSwitch" "layout" "seeAll" "preload" "deepLinks" "text" -}} +{{- range $name := slice "screens" "groups" "order" "groupOrder" "credit" "themeSwitch" "layout" "seeAll" "preload" "deepLinks" "text" "search" "zoom" "newBadges" -}} {{- $v := index $o $name -}} {{- if eq $v nil }}{{ continue }}{{ end -}} {{- $kind := partial "visualci-gallery/kind.html" $v -}} @@ -33,7 +33,7 @@ {{- else if in (slice "order" "groupOrder") $name -}} {{- $ok = eq $kind "list" -}} {{- if $ok }}{{ range $v }}{{ if ne (printf "%T" .) "string" }}{{ $ok = false }}{{ end }}{{ end }}{{ end -}} - {{- else if in (slice "credit" "themeSwitch" "deepLinks") $name -}} + {{- else if in (slice "credit" "themeSwitch" "deepLinks" "zoom") $name -}} {{- $ok = eq $kind "bool" -}} {{- else if eq $name "text" -}} {{- $ok = eq $kind "map" -}} @@ -43,6 +43,10 @@ {{- if not (and (isset $keys $k) (in (slice "null" "string") (partial "visualci-gallery/kind.html" $x))) }}{{ $ok = false }}{{ break }}{{ end -}} {{- end -}} {{- end -}} + {{- else if eq $name "search" -}} + {{- $ok = or (eq $kind "bool") (and (partial "visualci-gallery/whole.html" $v) (ge $v 0) (le $v 1000000)) -}} + {{- else if eq $name "newBadges" -}} + {{- $ok = or (eq $kind "bool") (and (partial "visualci-gallery/whole.html" $v) (ge $v 1) (le $v 3650)) -}} {{- else if eq $name "layout" -}} {{- $ok = and (eq $kind "string") (in (slice "grid" "strip") $v) -}} {{- else if eq $name "seeAll" -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/model.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/model.html index 59e883c0..73826af6 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/model.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/model.html @@ -80,11 +80,20 @@ {{- $s := newScratch -}} {{- $s.Set "variants" dict -}} {{- $s.Set "ids" dict -}} + {{- $s.Set "since" dict -}} {{- $screenKeys := slice -}} {{- range $shot := $shots -}} {{- $item := $shot.item -}} {{- $ids := index ($s.Get "ids") $shot.key -}} {{- if eq $ids nil }}{{ $ids = slice }}{{ $screenKeys = $screenKeys | append $shot.key }}{{ end -}} + {{- /* The screen's since: the greatest of its items', by code point (VisualCI writes every time in the same RFC + 3339 form, in UTC); one that isn't a string, or is empty, doesn't count. Compared with a letter in front, as in + ordered.html. */ -}} + {{- $since := index $item "since" -}} + {{- if and (eq (printf "%T" $since) "string") (ne $since "") -}} + {{- $was := index ($s.Get "since") $shot.key -}} + {{- if or (eq $was nil) (gt (print "k" $since) (print "k" $was)) }}{{ $s.SetInMap "since" $shot.key $since }}{{ end -}} + {{- end -}} {{- $opts := dict -}} {{- range $d := $dims -}} {{- $given := index $shot.values $d.key -}} @@ -187,7 +196,7 @@ {{- if eq $stitle nil }}{{ $stitle = partial "visualci-gallery/humanize.html" (after $prefix (split $sc.key "/")) }}{{ end -}} {{- $rank := len $order -}} {{- range $i, $k := $order }}{{ if and (eq $k $sc.key) (eq $rank (len $order)) }}{{ $rank = $i }}{{ end }}{{ end -}} - {{- $listed = $listed | append (dict "rank" $rank "key" $sc.key "item" (dict "key" $sc.key "title" $stitle "caption" (index $screen "caption") "variants" $sc.variants)) -}} + {{- $listed = $listed | append (dict "rank" $rank "key" $sc.key "item" (dict "key" $sc.key "title" $stitle "caption" (index $screen "caption") "since" (index ($s.Get "since") $sc.key) "variants" $sc.variants)) -}} {{- end -}} {{- $slugBase := partial "visualci-gallery/slugify.html" $g.name -}} {{- $slug := $slugBase -}} @@ -262,6 +271,18 @@ {{- $words = $filled -}} {{- end -}} {{- if not $titleSet }}{{ $title = $words.label }}{{ end -}} + {{- /* The search box: the grid's, when the option is true or a number no greater than the gallery's screens + (absent or null: 40). */ -}} + {{- $searchOpt := index $o "search" -}} + {{- if eq $searchOpt nil }}{{ $searchOpt = 40 }}{{ end -}} + {{- $screenCount := 0 -}} + {{- range $built }}{{ $screenCount = add $screenCount (len .screens) }}{{ end -}} + {{- $search := false -}} + {{- if eq $layout "grid" -}} + {{- if eq $searchOpt true }}{{ $search = true }}{{ else if ne $searchOpt false }}{{ $search = ge $screenCount $searchOpt }}{{ end -}} + {{- end -}} + {{- $newBadges := index $o "newBadges" -}} + {{- if or (eq $newBadges nil) (eq $newBadges false) }}{{ $newBadges = index dict "none" }}{{ else if eq $newBadges true }}{{ $newBadges = 30 }}{{ else }}{{ $newBadges = int $newBadges }}{{ end -}} {{- $out = dict "model" (dict "layout" $layout "themeSwitch" (and (eq $layout "grid") (ne $switch false)) @@ -274,6 +295,9 @@ "preload" $preload "deepLinks" (eq (index $o "deepLinks") true) "text" $words + "search" $search + "zoom" (ne (index $o "zoom") false) + "newBadges" $newBadges "dimensions" $shaped "groups" $built) -}} {{- end -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/render.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/render.html index 45e88f23..6c244342 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/render.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/render.html @@ -45,9 +45,15 @@ {{- end -}} {{- end -}} {{- if $model.deepLinks }}{{ $section = printf `%s data-vg-links` $section }}{{ end -}} +{{- if not $model.zoom }}{{ $section = printf `%s data-vg-zoom="off"` $section }}{{ end -}} +{{- with $model.newBadges }}{{ $section = printf `%s data-vg-new="%d"` $section . }}{{ end -}} {{- $out := slice (printf "%s>" $section) -}} {{- with $model.title }}{{ $out = $out | append (printf `<%s class="vg-title">%s` $h0 (partial "visualci-gallery/escape.html" .) $h0) }}{{ end -}} {{- if eq $model.title "" }}{{ $out = $out | append (printf `<%s class="vg-title">` $h0 $h0) }}{{ end -}} +{{- if $model.search -}} + {{- $words := partial "visualci-gallery/escape.html" $model.text.search -}} + {{- $out = $out | append (printf `` $gid $words $words) -}} +{{- end -}} {{- if eq $model.layout "strip" -}} {{- $out = $out | append (printf `
    ` $gid (index $shapes (index $choice "size"))) -}} @@ -100,6 +106,7 @@ {{- $out = $out | append "" -}} {{- $out = $out | append "
    " -}} {{- end -}} + {{- if $model.search }}{{ $out = $out | append (printf `` (partial "visualci-gallery/escape.html" $model.text.empty)) }}{{ end -}} {{- end -}} {{- with $model.seeAll -}} diff --git a/clients/gallery/hugo/layouts/_partials/visualci-gallery/text-defaults.html b/clients/gallery/hugo/layouts/_partials/visualci-gallery/text-defaults.html index fa359f84..5e354e22 100644 --- a/clients/gallery/hugo/layouts/_partials/visualci-gallery/text-defaults.html +++ b/clients/gallery/hugo/layouts/_partials/visualci-gallery/text-defaults.html @@ -9,4 +9,7 @@ "back" "Scroll back" "forward" "Scroll forward" "credit" "Screenshots by {link}" - "and" " and " -}} + "and" " and " + "search" "Search screens" + "empty" "No screens match" + "new" "New" -}} diff --git a/clients/gallery/hugo/tests/assets/units.json b/clients/gallery/hugo/tests/assets/units.json index c6bad369..69470efa 100644 --- a/clients/gallery/hugo/tests/assets/units.json +++ b/clients/gallery/hugo/tests/assets/units.json @@ -536,14 +536,14 @@ "options": { "themeswitch": false }, - "want": "unknown option themeswitch (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks)" + "want": "unknown option themeswitch (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks, newBadges)" }, { "options": { "heading_level": 3, "title": null }, - "want": "unknown option heading_level (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks)" + "want": "unknown option heading_level (options use the gallery's spelling: headingLevel, groupOrder, themeSwitch, seeAll, deepLinks, newBadges)" }, { "options": { diff --git a/clients/gallery/js/README.md b/clients/gallery/js/README.md index ecbce065..850e240a 100644 --- a/clients/gallery/js/README.md +++ b/clients/gallery/js/README.md @@ -44,7 +44,10 @@ page), `screens` (`{key: {title, caption}}`), `order` (screen keys), `groups` (` next; false turns it off; `{fold, count, bytes, parallel}` sets its caps, the rest keeping their defaults 250, 500, 50000000, 4), `deepLinks` (false: true keeps the open tab, screen and values in the URL's hash, so a link opens them), `text` (the gallery's own words, for another language: `{label, open, previous, next, close, back, forward, -credit, and}`, any of them). `load` and `mount` also take `manifest`, `timeout`, `attempts` and +credit, and, search, empty, new}`, any of them), `search` (40: the grid's search box shows from that many screens; +true always, false never), `zoom` (true: pinch, ctrl-wheel, double-click and the + and - keys in the full-size view; +false turns it off), `newBadges` (false: true badges screens whose picture changed in the last 30 days, a number sets +the days). `load` and `mount` also take `manifest`, `timeout`, `attempts` and `fetch`. [SPEC.md](../contract/SPEC.md) has the details, including how screenshot names pair (`-[-]` or `/-`). diff --git a/clients/gallery/python/README.md b/clients/gallery/python/README.md index db8b4d98..576ed83b 100644 --- a/clients/gallery/python/README.md +++ b/clients/gallery/python/README.md @@ -64,8 +64,12 @@ for an app's windows), `group_order`, `credit`, `layout` (`"grid"` or `"strip"`) `preload` (`False` turns predictive preloading off; `{"count": 100, "bytes": 20_000_000}` sets its caps, any of `fold`, `count`, `bytes` and `parallel`, the rest keeping their defaults), `deep_links` (`True`: the URL's hash names the shown tab, screen and values, so a link opens them), `text` (the gallery's own words, for another language: any of -`label`, `open`, `previous`, `next`, `close`, `back`, `forward`, `credit` and `and`, such as `{"close": "Fermer"}`; -`visualci_gallery.TEXT_DEFAULTS` has the defaults). +`label`, `open`, `previous`, `next`, `close`, `back`, `forward`, `credit`, `and`, `search`, `empty` and `new`, such as +`{"close": "Fermer"}`; `visualci_gallery.TEXT_DEFAULTS` has the defaults), `search` (the grid's search box, which +filters the cards by title and caption across tabs: a number, default 40, shows it once the gallery has that many +screens; `True`, always; `False`, never), `zoom` (default `True`: zoom in the full-size view by pinch, ctrl-wheel, +double-click and the `+` and `-` keys; `False` turns it off) and `new_badges` (a New badge on each screen whose +picture changed in the last so many days: `True` for 30, or a whole number from 1 to 3650; default `False`). ## Development diff --git a/clients/gallery/python/src/visualci_gallery/__init__.py b/clients/gallery/python/src/visualci_gallery/__init__.py index f394e20b..7bde39b1 100644 --- a/clients/gallery/python/src/visualci_gallery/__init__.py +++ b/clients/gallery/python/src/visualci_gallery/__init__.py @@ -62,7 +62,7 @@ def fetch(url: str, *, timeout: float = 20, attempts: int = 3) -> Any: def render(manifest: Any, **options: Any) -> str: """The gallery's HTML for a parsed manifest. Options are the contract's, in Python spelling: title (None for no heading), heading_level, id, dimensions, screens, order, groups, group_order, credit, layout, theme_switch, see_all, preload, - deep_links, text. + deep_links, text, search, zoom, new_badges. Raises GalleryError when the manifest or the options are invalid or nothing in the manifest can be shown.""" return render_model(build_model(manifest, **options)) diff --git a/clients/gallery/python/src/visualci_gallery/_model.py b/clients/gallery/python/src/visualci_gallery/_model.py index f86a2c46..daeb1099 100644 --- a/clients/gallery/python/src/visualci_gallery/_model.py +++ b/clients/gallery/python/src/visualci_gallery/_model.py @@ -21,7 +21,14 @@ "forward": "Scroll forward", "credit": "Screenshots by {link}", "and": " and ", + "search": "Search screens", + "empty": "No screens match", + "new": "New", } +# The search box's default threshold: shown once the gallery has this many screens. +SEARCH_FROM = 40 +# The New badge's default window, in days. +NEW_DAYS = 30 SEE_ALL_TEXT = "See all screenshots" # The built-in dimensions (contract/SPEC.md, "Dimensions"): the `dimensions` option changes them and adds others. DEFAULT_DIMENSIONS: list[dict[str, Any]] = [ @@ -458,6 +465,9 @@ def build_model( preload: Any = None, deep_links: Any = None, text: Any = None, + search: Any = None, + zoom: Any = None, + new_badges: Any = None, ) -> dict[str, Any]: """The manifest as the gallery shows it (contract/SPEC.md), as a dict with the keys of the fixtures' model.json. Raises GalleryError when it or the options are invalid, or nothing in it can be shown.""" @@ -500,6 +510,13 @@ def build_model( words = {k: text_opt[k] if text_opt.get(k) is not None else d for k, d in TEXT_DEFAULTS.items()} if title is _UNSET: title = words["label"] + # A boolean, or a whole number in range: True is a boolean here, never the number 1. + search = _opt(search, lambda v: isinstance(v, bool) or (_integral(v) and 0 <= v <= MAX_SIZE), "search") + search = SEARCH_FROM if search is None else search + zoom = _opt(zoom, lambda v: isinstance(v, bool), "zoom") + zoom = True if zoom is None else zoom + new_badges = _opt(new_badges, lambda v: isinstance(v, bool) or (_integral(v) and 1 <= v <= 3650), "newBadges") + new_badges = False if new_badges is None else new_badges slugs: set[str] = set() def rank_of(v: dict[str, Any]) -> list[int]: @@ -519,8 +536,13 @@ def rank_of(v: dict[str, Any]) -> list[int]: keys = [v["key"] for v in d["values"] if any(shot["values"].get(d["key"]) == v["key"] for _, shot in shots)] named[d["key"]] = keys or [d["values"][0]["key"]] found: dict[str, dict[str, dict[str, Any]]] = {} + sinces: dict[str, str] = {} for item, shot in shots: variants = found.setdefault(shot["key"], {}) + # Compared by code point (Python's str order): VisualCI writes every time in the same RFC 3339 form, in UTC. + since = item.get("since") + if isinstance(since, str) and since != "" and (shot["key"] not in sinces or since > sinces[shot["key"]]): + sinces[shot["key"]] = since given = shot["values"] for values in _combinations(dims, lambda d: [given[d["key"]]] if d["key"] in given else named[d["key"]]): v = variants.setdefault( @@ -589,6 +611,7 @@ def rank_of(v: dict[str, Any]) -> list[int]: "key": key, "title": screen.get("title") if screen.get("title") is not None else humanize(key.split("/")[prefix:]), "caption": screen.get("caption"), + "since": sinces.get(key), "variants": variants, } ) @@ -615,6 +638,7 @@ def rank_of(v: dict[str, Any]) -> list[int]: ) if not built: _fail("the gallery manifest has no screenshots to show") + screen_count = sum(len(g["screens"]) for g in built) # Named groups first; the rest keep the manifest's order (the sort is stable). group_rank = _rank_by(group_order) @@ -636,6 +660,9 @@ def rank_of(v: dict[str, Any]) -> list[int]: "preload": _preload_model(preload), "deepLinks": deep_links, "text": words, + "search": layout == "grid" and (search is True or (search is not False and screen_count >= search)), + "zoom": zoom, + "newBadges": None if new_badges is False else NEW_DAYS if new_badges is True else int(new_badges), "dimensions": _with_shapes(dims, built), "groups": built, } diff --git a/clients/gallery/python/src/visualci_gallery/_render.py b/clients/gallery/python/src/visualci_gallery/_render.py index a2d3d392..67191b60 100644 --- a/clients/gallery/python/src/visualci_gallery/_render.py +++ b/clients/gallery/python/src/visualci_gallery/_render.py @@ -153,14 +153,17 @@ def shown(i: list[dict[str, Any]]) -> str | None: marks = [t for t in ("light", "dark") if holds(i, _card_combo(model, sc, {**choice, "theme": t}))] return " ".join(marks) if marks else None + badge = model["newBadges"] is not None and sc["since"] is not None return ( f'
  • " + f'' + "".join(_image(model, g, sc["title"], i, shown(i)) for i in imgs) + "" + + (f'' if badge else "") + f'<{heading} class="vg-card-title">{escape(sc["title"])}' + (f'

    {escape(sc["caption"])}

    ' if caption and sc["caption"] is not None else "") + "
  • " @@ -254,6 +257,8 @@ def _grid(model: dict[str, Any], gid: str, choice: Choice, gh: str, ch: str, out out.extend(_card(model, g, sc, start, sc["variants"], ch, True, g["fit"]) for sc in g["screens"]) out.append("") out.append("") + if model["search"]: + out.append(f'') def _strip(model: dict[str, Any], gid: str, choice: Choice, ch: str, out: list[str]) -> None: @@ -303,10 +308,18 @@ def h(offset: int) -> str: + ("" if model["themeSwitch"] else ' data-vg-theme-source="page"') + _preload_attr(model["preload"]) + (" data-vg-links" if model["deepLinks"] else "") + + ("" if model["zoom"] else ' data-vg-zoom="off"') + + (f' data-vg-new="{model["newBadges"]}"' if model["newBadges"] is not None else "") + ">" ) if model["title"] is not None: out.append(f'<{h(0)} class="vg-title">{escape(model["title"])}') + if model["search"]: + words = escape(model["text"]["search"]) + out.append( + f'' + ) if model["layout"] == "strip": _strip(model, gid, choice, h(below), out) else: diff --git a/clients/gallery/python/tests/test_gallery.py b/clients/gallery/python/tests/test_gallery.py index 41a6589a..ef0e2e80 100644 --- a/clients/gallery/python/tests/test_gallery.py +++ b/clients/gallery/python/tests/test_gallery.py @@ -18,6 +18,7 @@ "themeSwitch": "theme_switch", "seeAll": "see_all", "deepLinks": "deep_links", + "newBadges": "new_badges", } @@ -140,6 +141,26 @@ def test_json_integers_and_bools(self): self.assertEqual(2000, model["groups"][0]["screens"][0]["variants"][0]["bytes"]) self.assertEqual({"fold": 250, "count": 10, "bytes": 50_000_000, "parallel": 4}, model["preload"]) + def test_search_and_new_badges_bools_are_not_numbers(self): + manifest = {"groups": [{"name": "G", "items": [{"name": "a", "url": "https://x/a.png", "width": 10, "height": 10}]}]} + # True means always (search) and 30 days (new_badges), never the number 1. + self.assertTrue(build_model(manifest, search=True)["search"]) + self.assertFalse(build_model(manifest, search=2)["search"]) + self.assertTrue(build_model(manifest, search=1.0)["search"]) + self.assertTrue(build_model(manifest, search=0)["search"]) + self.assertFalse(build_model(manifest, search=False)["search"]) + self.assertFalse(build_model(manifest)["search"]) + self.assertFalse(build_model(manifest, search=True, layout="strip")["search"]) + self.assertEqual(30, build_model(manifest, new_badges=True)["newBadges"]) + self.assertIsNone(build_model(manifest, new_badges=False)["newBadges"]) + model = build_model(manifest, new_badges=7.0) + self.assertEqual(7, model["newBadges"]) + self.assertIsInstance(model["newBadges"], int) + with self.assertRaisesRegex(GalleryError, "zoom"): + build_model(manifest, zoom=1) + with self.assertRaisesRegex(GalleryError, "search"): + build_model(manifest, search=1.5) + class Fetch(unittest.TestCase): def serve(self, status: int, body: bytes): diff --git a/clients/gallery/ruby/README.md b/clients/gallery/ruby/README.md index 70bb03f7..940ed9fe 100644 --- a/clients/gallery/ruby/README.md +++ b/clients/gallery/ruby/README.md @@ -46,7 +46,11 @@ Keyword arguments, the contract's options in Ruby spelling: `title` (default `te `theme_switch`, `see_all`, `preload` (`false` turns predictive preloading off; `{ count: 100, bytes: 20_000_000 }` sets its caps, any of `fold`, `count`, `bytes` and `parallel`, the rest keeping their defaults), `deep_links` (`true` puts the shown tab, open screen and chosen values in the URL's hash), `text` (the gallery's own words, any of `label`, -`open`, `previous`, `next`, `close`, `back`, `forward`, `credit` and `and`: `{ label: 'Captures', close: 'Fermer' }`). +`open`, `previous`, `next`, `close`, `back`, `forward`, `credit`, `and`, `search`, `empty` and `new`: +`{ label: 'Captures', close: 'Fermer' }`), `search` (the grid's search box, filtering cards by title and caption: a +number, default `40`, shows it once the gallery has that many screens; `true` always, `false` never), `zoom` (`false` +turns off zooming in the full-size view) and `new_badges` (`true` marks screens whose picture changed in the last 30 +days New, or a number of days from 1 to 3650; default off). Hash keys may be strings or symbols. ## Development diff --git a/clients/gallery/ruby/lib/visualci/gallery.rb b/clients/gallery/ruby/lib/visualci/gallery.rb index 891bf911..7ba4f409 100644 --- a/clients/gallery/ruby/lib/visualci/gallery.rb +++ b/clients/gallery/ruby/lib/visualci/gallery.rb @@ -29,9 +29,14 @@ class Error < StandardError; end TEXT_DEFAULTS = { 'label' => 'Screenshots', 'open' => '{title}: view full size', 'previous' => 'Previous screen', 'next' => 'Next screen', 'close' => 'Close', 'back' => 'Scroll back', 'forward' => 'Scroll forward', - 'credit' => 'Screenshots by {link}', 'and' => ' and ' + 'credit' => 'Screenshots by {link}', 'and' => ' and ', 'search' => 'Search screens', 'empty' => 'No screens match', + 'new' => 'New' }.freeze SEE_ALL_TEXT = 'See all screenshots' + # The search box's default threshold: shown once the gallery has this many screens (SPEC.md, "Options"). + SEARCH_FROM = 40 + # The New badge's default window, in days. + NEW_DAYS = 30 # The largest width or height (SPEC.md, "Validation"): the density maths stays exact in every language. MAX_SIZE = 1_000_000 # The largest size in bytes or preload cap: a whole number every language holds exactly. @@ -101,7 +106,7 @@ def render(manifest, **options) # The model (SPEC.md, "The model") as a Hash with the same keys as the fixtures' model.json. def model(manifest, title: UNSET, heading_level: nil, id: nil, dimensions: nil, screens: nil, order: nil, groups: nil, group_order: nil, credit: nil, layout: nil, theme_switch: nil, see_all: nil, preload: nil, - deep_links: nil, text: nil) + deep_links: nil, text: nil, search: nil, zoom: nil, new_badges: nil) check_manifest(manifest) # Options in the contract's order (SPEC.md, "Validation"): the first problem is the error. level = opt(heading_level, 'headingLevel') { |v| integral?(v) } @@ -121,10 +126,16 @@ def model(manifest, title: UNSET, heading_level: nil, id: nil, dimensions: nil, preload = opt(preload, 'preload') { |v| preload?(v) } deep_links = opt(deep_links, 'deepLinks') { |v| boolean?(v) } text = text_model(opt(text, 'text') { |v| text?(v) }) + search = opt(search, 'search') { |v| boolean?(v) || (integral?(v) && v >= 0 && v <= MAX_SIZE) } + search = SEARCH_FROM if search.nil? + zoom = opt(zoom, 'zoom') { |v| boolean?(v) } + new_badges = opt(new_badges, 'newBadges') { |v| boolean?(v) || (integral?(v) && v >= 1 && v <= 3650) } title = text['label'] if title.equal?(UNSET) built = build_groups(manifest, dims, screens_opt, groups_opt, order, group_order) raise Error, 'the gallery manifest has no screenshots to show' if built.empty? + screen_count = built.sum { |g| g['screens'].length } + { 'layout' => layout, 'themeSwitch' => layout == 'grid' && switch != false, @@ -137,6 +148,12 @@ def model(manifest, title: UNSET, heading_level: nil, id: nil, dimensions: nil, 'preload' => preload_model(preload), 'deepLinks' => deep_links.nil? ? false : deep_links, 'text' => text, + 'search' => layout == 'grid' && (search == true || (search != false && screen_count >= search)), + 'zoom' => zoom.nil? ? true : zoom, + 'newBadges' => if new_badges.nil? || new_badges == false then nil + elsif new_badges == true then NEW_DAYS + else new_badges.to_i + end, 'dimensions' => with_shapes(dims, built), 'groups' => built } @@ -243,8 +260,13 @@ def build_groups(manifest, dims, screens_opt, groups_opt, order, group_order) [d['key'], keys.empty? ? [d['values'][0]['key']] : keys] end screens = {} + sinces = {} shots.each do |item, shot| variants = (screens[shot[:key]] ||= {}) + # Compared by code point (UTF-8 bytes order the same way): VisualCI writes every time in one RFC 3339 form. + since = item['since'].is_a?(String) && item['since'] != '' ? item['since'] : nil + was = sinces[shot[:key]] + sinces[shot[:key]] = since if !since.nil? && (was.nil? || since > was) combinations(dims) { |d| shot[:values].key?(d['key']) ? [shot[:values][d['key']]] : named[d['key']] }.each do |values| vid = dims.map { |d| values[d['key']] }.join('.') v = (variants[vid] ||= { 'values' => values, 'url' => '', 'url2x' => nil, 'width' => 0, 'height' => 0, @@ -296,7 +318,7 @@ def build_groups(manifest, dims, screens_opt, groups_opt, order, group_order) list = kept.map do |key, variants| screen = screens_opt[key] || {} { 'key' => key, 'title' => screen['title'] || humanize(key.split('/', -1).drop(prefix)), - 'caption' => screen['caption'], 'variants' => variants } + 'caption' => screen['caption'], 'since' => sinces[key], 'variants' => variants } end list = list.each_with_index.sort_by { |sc, i| [rank(order, sc['key']), sc['key'], i] }.map(&:first) base = slugify(g['name']) diff --git a/clients/gallery/ruby/lib/visualci/gallery/renderer.rb b/clients/gallery/ruby/lib/visualci/gallery/renderer.rb index 1f9744eb..a021cae6 100644 --- a/clients/gallery/ruby/lib/visualci/gallery/renderer.rb +++ b/clients/gallery/ruby/lib/visualci/gallery/renderer.rb @@ -19,8 +19,14 @@ def call out << %(
    ' + (@m['deepLinks'] ? ' data-vg-links' : '') + + (@m['zoom'] ? '' : ' data-vg-zoom="off"') + + (@m['newBadges'].nil? ? '' : %( data-vg-new="#{@m['newBadges']}")) + '>' out << "<#{h(0)} class=\"vg-title\">#{esc(@m['title'])}" unless @m['title'].nil? + if @m['search'] + words = esc(text('search')) + out << %() + end @m['layout'] == 'strip' ? strip(choice, out) : grid(choice, out) if (see = @m['seeAll']) out << %(

    #{esc(see['text'])}

    ) @@ -176,11 +182,14 @@ def card(g, sc, choice, variants, heading, caption) marks = %w[light dark].select { |t| holds.call(i, card_combo(sc, choice.merge('theme' => t))) } marks.empty? ? nil : marks.join(' ') end + badge = !@m['newBadges'].nil? && !sc['since'].nil? %(
  • ' + + (g['fit'] == 'contain' ? ' data-vg-fit="contain"' : '') + + (badge ? %( data-vg-since="#{esc(sc['since'])}") : '') + '>' + %() + imgs.map { |i| image(g, sc['title'], i, shown.call(i)) }.join + '' + + (badge ? %() : '') + %(<#{heading} class="vg-card-title">#{esc(sc['title'])}) + (caption && !sc['caption'].nil? ? %(

    #{esc(sc['caption'])}

    ) : '') + '
  • ' @@ -230,6 +239,7 @@ def grid(choice, out) out << '' out << '' end + out << %() if @m['search'] end def strip(choice, out) diff --git a/clients/gallery/ruby/test/gallery_test.rb b/clients/gallery/ruby/test/gallery_test.rb index 8392d706..2aee06e3 100644 --- a/clients/gallery/ruby/test/gallery_test.rb +++ b/clients/gallery/ruby/test/gallery_test.rb @@ -10,7 +10,8 @@ class GalleryContractTest < Minitest::Test CONTRACT = File.expand_path('../../contract', __dir__) OPTION_NAMES = { 'headingLevel' => :heading_level, 'groupOrder' => :group_order, 'themeSwitch' => :theme_switch, - 'seeAll' => :see_all, 'deepLinks' => :deep_links }.freeze + 'seeAll' => :see_all, 'deepLinks' => :deep_links, + 'newBadges' => :new_badges }.freeze def self.options(json) json.to_h { |k, v| [OPTION_NAMES.fetch(k, k.to_sym), v] } @@ -83,6 +84,18 @@ def test_text_symbol_keys assert_includes html, ' data-vg-links>' end + def test_search_zoom_and_new_badges + model = VisualCI::Gallery.model(MANIFEST) + assert_equal [false, true, nil], model.values_at('search', 'zoom', 'newBadges') + model = VisualCI::Gallery.model(MANIFEST, search: true, zoom: false, new_badges: true) + assert_equal [true, false, 30], model.values_at('search', 'zoom', 'newBadges') + refute VisualCI::Gallery.model(MANIFEST, search: true, layout: :strip)['search'] + html = VisualCI::Gallery.render(MANIFEST, search: 1, zoom: false, new_badges: 7, text: { search: 'Chercher' }) + assert_includes html, ' data-vg-zoom="off" data-vg-new="7">' + assert_includes html, 'placeholder="Chercher"' + assert_includes html, '' + end + def test_parse_shot_and_titles assert_equal({ key: 'shots/app/billing', values: { 'theme' => 'dark' }, x2: true, css_width: 1440 }, VisualCI::Gallery.parse_shot('shots/app/billing/1440-dark-2x')) diff --git a/clients/gallery/rust/README.md b/clients/gallery/rust/README.md index 290b0a55..52c0eed0 100644 --- a/clients/gallery/rust/README.md +++ b/clients/gallery/rust/README.md @@ -39,7 +39,8 @@ which sets `window.VisualCIGallery`), then ## Options `Options::default()` and its setters (`title`, `heading_level`, `id`, `dimension`, `screen`, `order`, `group`, -`group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `preload_caps`, `deep_links`, `text`), or +`group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `preload_caps`, `deep_links`, `text`, `search`, +`search_from`, `zoom`, `new_badges`, `new_badges_days`), or `Options::from_json` with the contract's JSON names. Shots differ by theme (light, dark) and size (desktop, phone) out of the box. `.dimension(key, label, missing, values)` @@ -63,8 +64,8 @@ let options = Options::default().preload_caps(None, Some(100), Some(20_000_000), `.deep_links(true)` makes the page's URL name the open tab, screen and values, so a link opens them. `.text(key, value)` changes one of the gallery's own words, for another language: `label`, `open` (`{title}` is the screen's title), -`previous`, `next`, `close`, `back`, `forward`, `credit` (`{link}` is the link to VisualCI) or `and`. An unknown key -is an error when the gallery renders. +`previous`, `next`, `close`, `back`, `forward`, `credit` (`{link}` is the link to VisualCI), `and`, `search`, `empty` +or `new`. An unknown key is an error when the gallery renders. ```rust use visualci_gallery::Options; @@ -72,6 +73,18 @@ use visualci_gallery::Options; let options = Options::default().deep_links(true).text("label", "Captures d'écran").text("close", "Fermer"); ``` +The grid gets a search box, which filters the cards by title and caption across tabs, once the gallery has 40 +screens: `.search_from(n)` changes that number (0 to 1000000), `.search(true)` always shows it and `.search(false)` +never does. The strip has none. Zoom in the full-size view (pinch, ctrl-wheel, double-click, `+` and `-`) is on by +default; `.zoom(false)` turns it off. `.new_badges(true)` puts a New badge on each screen whose picture changed in the +last 30 days, decided in the reader's browser; `.new_badges_days(days)` sets the window (1 to 3650): + +```rust +use visualci_gallery::Options; + +let options = Options::default().search_from(10).zoom(false).new_badges_days(14); +``` + ## Development `cargo test --all-features` checks the contract's golden fixtures, refusals and messages. diff --git a/clients/gallery/rust/src/lib.rs b/clients/gallery/rust/src/lib.rs index 6847eb9b..094293e1 100644 --- a/clients/gallery/rust/src/lib.rs +++ b/clients/gallery/rust/src/lib.rs @@ -25,9 +25,9 @@ mod render; use std::fmt; pub use model::{ - Dimension, DimensionValue, Group, Missing, Model, Options, Preload, PreloadCaps, SEE_ALL_TEXT, Screen, SeeAll, - Shape, Shot, TEXT_DEFAULTS, Text, Thumb, Values, Variant, build_model, default_dimensions, humanize, parse_shot, - slugify, + Dimension, DimensionValue, Group, Missing, Model, NEW_DAYS, Options, Preload, PreloadCaps, SEARCH_FROM, + SEE_ALL_TEXT, Screen, SeeAll, Shape, Shot, TEXT_DEFAULTS, Text, Thumb, Values, Variant, build_model, + default_dimensions, humanize, parse_shot, slugify, }; pub use render::{escape, render_model}; diff --git a/clients/gallery/rust/src/model.rs b/clients/gallery/rust/src/model.rs index 13523817..53f1d33a 100644 --- a/clients/gallery/rust/src/model.rs +++ b/clients/gallery/rust/src/model.rs @@ -11,7 +11,7 @@ use serde_json::{Map, Value}; use crate::Error; /// The gallery's own words by key, with their defaults (contract/SPEC.md, "Text"), in the model's order. -pub const TEXT_DEFAULTS: [(&str, &str); 9] = [ +pub const TEXT_DEFAULTS: [(&str, &str); 12] = [ ("label", "Screenshots"), ("open", "{title}: view full size"), ("previous", "Previous screen"), @@ -21,8 +21,15 @@ pub const TEXT_DEFAULTS: [(&str, &str); 9] = [ ("forward", "Scroll forward"), ("credit", "Screenshots by {link}"), ("and", " and "), + ("search", "Search screens"), + ("empty", "No screens match"), + ("new", "New"), ]; pub const SEE_ALL_TEXT: &str = "See all screenshots"; +/// The search box's default threshold: shown once the gallery has this many screens. +pub const SEARCH_FROM: u64 = 40; +/// The New badge's default window, in days. +pub const NEW_DAYS: u64 = 30; // Whole-string matches (\A…\z), ASCII digits only and "any character" including line breaks, so every language's // regex engine agrees (contract/SPEC.md, "A shot's name"). @@ -184,6 +191,8 @@ pub struct Screen { pub key: String, pub title: String, pub caption: Option, + /// The newest `since` of the manifest items it's made from (the last time one of its pictures changed). + pub since: Option, pub variants: Vec, } @@ -218,6 +227,9 @@ pub struct Text { pub forward: String, pub credit: String, pub and: String, + pub search: String, + pub empty: String, + pub new: String, } impl Text { @@ -234,6 +246,9 @@ impl Text { forward: w("forward"), credit: w("credit"), and: w("and"), + search: w("search"), + empty: w("empty"), + new: w("new"), } } } @@ -260,6 +275,11 @@ pub struct Model { pub preload: Option, pub deep_links: bool, pub text: Text, + /// Whether the grid shows its search box. + pub search: bool, + pub zoom: bool, + /// The New badge's window in days; None: no badges. + pub new_badges: Option, pub dimensions: Vec, pub groups: Vec, } @@ -648,9 +668,30 @@ impl Options { pub fn deep_links(self, on: bool) -> Self { self.set("deepLinks", on.into()) } + /// The grid's search box, which filters the cards by title and caption across tabs: `true` always shows it, + /// `false` never. By default it shows once the gallery has 40 screens; the strip never has one. + pub fn search(self, on: bool) -> Self { + self.set("search", on.into()) + } + /// The grid's search box, shown once the gallery has this many screens (in every group), from 0 to 1000000. + pub fn search_from(self, screens: u64) -> Self { + self.set("search", screens.into()) + } + /// Zoom in the full-size view, by gestures and keys only: on by default, `false` turns it off. + pub fn zoom(self, on: bool) -> Self { + self.set("zoom", on.into()) + } + /// A New badge on each screen whose picture changed in the last 30 days (`true`); off by default. + pub fn new_badges(self, on: bool) -> Self { + self.set("newBadges", on.into()) + } + /// A New badge on each screen whose picture changed in the last `days` days, from 1 to 3650. + pub fn new_badges_days(self, days: u64) -> Self { + self.set("newBadges", days.into()) + } /// One of the gallery's own words, by key (contract/SPEC.md, "Text"): `label`, `open` (`{title}` is the screen's - /// title), `previous`, `next`, `close`, `back`, `forward`, `credit` (`{link}` is the link to VisualCI) or `and`. An - /// unknown key makes the options invalid. + /// title), `previous`, `next`, `close`, `back`, `forward`, `credit` (`{link}` is the link to VisualCI), `and`, + /// `search`, `empty` or `new`. An unknown key makes the options invalid. pub fn text(mut self, key: &str, value: &str) -> Self { let text = self.raw.entry("text").or_insert_with(|| Value::Object(Map::new())); if let Value::Object(m) = text { @@ -933,6 +974,13 @@ pub fn build_model(manifest: &Value, options: &Options) -> Result })?; let text = Text::with(|k| text_opt.and_then(|t| t.get(k)).and_then(Value::as_str).map(str::to_string)); let title = title_opt.unwrap_or_else(|| Some(text.label.clone())); + let search_opt = options.get("search", |v| v.is_boolean() || whole_in(v, 0, MAX_SIZE).is_some())?; + let zoom = options.get("zoom", Value::is_boolean)?.and_then(Value::as_bool).unwrap_or(true); + let new_badges = match options.get("newBadges", |v| v.is_boolean() || whole_in(v, 1, 3650).is_some())? { + None | Some(Value::Bool(false)) => None, + Some(Value::Bool(true)) => Some(NEW_DAYS), + Some(v) => integral(v).map(|n| n as u64), + }; let rank_of = |v: &Variant| -> Vec { dimensions.iter().map(|d| d.values.iter().position(|x| x.key == v.values[&d.key]).unwrap()).collect() }; @@ -968,7 +1016,13 @@ pub fn build_model(manifest: &Value, options: &Options) -> Result .collect(); // Screens in the order their key first appears, each with its variants in the order they were first filed. let mut screens: Vec<(String, Vec<(String, Variant)>)> = Vec::new(); + let mut sinces: HashMap = HashMap::new(); for (item, shot) in items.iter().zip(&shots) { + // Compared by code point: VisualCI writes every time in the same RFC 3339 form, in UTC. + let since = item.get("since").and_then(Value::as_str).filter(|s| !s.is_empty()); + if let Some(since) = since.filter(|s| sinces.get(&shot.key).is_none_or(|was| *s > was.as_str())) { + sinces.insert(shot.key.clone(), since.into()); + } let (w, h) = (size_of(item.get("width")).unwrap(), size_of(item.get("height")).unwrap()); let url = item["url"].as_str().unwrap(); let at = match screens.iter().position(|(k, _)| *k == shot.key) { @@ -1068,7 +1122,8 @@ pub fn build_model(manifest: &Value, options: &Options) -> Result humanize(&parts) }); let caption = set.and_then(|s| s.get("caption")).and_then(Value::as_str).map(str::to_string); - Screen { key, title, caption, variants } + let since = sinces.get(&key).cloned(); + Screen { key, title, caption, since, variants } }) .collect(); // Rust compares strings by code point, as the contract does. @@ -1094,6 +1149,13 @@ pub fn build_model(manifest: &Value, options: &Options) -> Result } // Named groups first; the rest keep the manifest's order (the sort is stable). groups.sort_by_key(|g| rank(&group_order, &g.name)); + let screen_count = groups.iter().map(|g| g.screens.len() as u64).sum::(); + let search = layout == "grid" + && match search_opt { + None => screen_count >= SEARCH_FROM, + Some(Value::Bool(on)) => *on, + Some(v) => integral(v).is_some_and(|n| screen_count as f64 >= n), + }; Ok(Model { theme_switch: layout == "grid" && switch, @@ -1110,6 +1172,9 @@ pub fn build_model(manifest: &Value, options: &Options) -> Result preload, deep_links, text, + search, + zoom, + new_badges, dimensions: with_shapes(dimensions, &groups), groups, }) diff --git a/clients/gallery/rust/src/render.rs b/clients/gallery/rust/src/render.rs index a155646a..87d84b6d 100644 --- a/clients/gallery/rust/src/render.rs +++ b/clients/gallery/rust/src/render.rs @@ -175,12 +175,19 @@ fn card( let off = if card_off(model, sc, choice) { " data-vg-off" } else { "" }; let fit = if g.fit == "contain" { r#" data-vg-fit="contain""# } else { "" }; let images: String = imgs.iter().map(|i| image(model, g, &sc.title, i, shown(i))).collect(); + let (since, badge) = match (&model.new_badges, &sc.since) { + (Some(_), Some(s)) => ( + format!(r#" data-vg-since="{}""#, escape(s)), + format!(r#""#, escape(&model.text.new)), + ), + _ => (String::new(), String::new()), + }; let caption = match (&sc.caption, caption) { (Some(c), true) => format!(r#"

    {}

    "#, escape(c)), _ => String::new(), }; format!( - r#"
  • {images}<{heading} class="vg-card-title">{}{caption}
  • "#, + r#"
  • {images}{badge}<{heading} class="vg-card-title">{}{caption}
  • "#, escape(&sc.key), escape(&first[0].url), fill(&model.text.open, "{title}", &escape(&sc.title)), @@ -299,6 +306,9 @@ fn grid(model: &Model, id: &str, choice: &Choice, gh: &str, ch: &str, out: &mut out.push("".into()); out.push("".into()); } + if model.search { + out.push(format!(r#""#, escape(&model.text.empty))); + } } fn strip(model: &Model, id: &str, choice: &Choice, ch: &str, out: &mut Vec) { @@ -367,14 +377,22 @@ pub fn render_model(model: &Model) -> String { } }; let links = if model.deep_links { " data-vg-links" } else { "" }; + let zoom = if model.zoom { "" } else { r#" data-vg-zoom="off""# }; + let new = model.new_badges.map_or(String::new(), |days| format!(r#" data-vg-new="{days}""#)); out.push(format!( - r#"
    "#, + r#"
    "#, model.layout, escape(&model.label) )); if let Some(title) = &model.title { out.push(format!(r#"<{h} class="vg-title">{}"#, escape(title), h = h(0))); } + if model.search { + let words = escape(&model.text.search); + out.push(format!( + r#""# + )); + } if model.layout == "strip" { strip(model, &id, &choice, &h(below), &mut out); } else { diff --git a/clients/gallery/rust/tests/contract.rs b/clients/gallery/rust/tests/contract.rs index 1f73421a..e4b7af71 100644 --- a/clients/gallery/rust/tests/contract.rs +++ b/clients/gallery/rust/tests/contract.rs @@ -171,6 +171,33 @@ fn text_builder_matches_json_options() { assert!(matches!(render(&manifest, &invalid), Err(Error::Invalid(m)) if m == "gallery option text is invalid")); } +#[test] +fn search_zoom_and_new_badges_builders_match_json_options() { + let dir = contract().join("fixtures/extras"); + let manifest = read(&dir.join("manifest.json")); + let from_json = Options::from_json(&read(&dir.join("options.json"))).unwrap(); + let built = Options::default() + .search_from(3) + .zoom(false) + .new_badges_days(14) + .screen("billing", None, Some("Plans & invoices")) + .text("search", "Find a screen") + .text("empty", "Nothing found") + .text("new", "Fresh"); + assert_eq!(render(&manifest, &from_json).unwrap(), render(&manifest, &built).unwrap()); + // true: always a search box, and New badges for 30 days; false: neither. + let model = build_model(&manifest, &Options::default().search(true).new_badges(true)).unwrap(); + assert_eq!((model.search, model.zoom, model.new_badges), (true, true, Some(30))); + let model = build_model(&manifest, &Options::default().search(false).new_badges(false)).unwrap(); + assert_eq!((model.search, model.new_badges), (false, None)); + let invalid = Options::default().new_badges_days(3651); + assert!( + matches!(render(&manifest, &invalid), Err(Error::Invalid(m)) if m == "gallery option newBadges is invalid") + ); + let invalid = Options::default().search_from(1_000_001); + assert!(matches!(render(&manifest, &invalid), Err(Error::Invalid(m)) if m == "gallery option search is invalid")); +} + #[test] fn gallery_displays_its_html() { let dir = contract().join("fixtures/single-group"); diff --git a/frontend/content/docs/gallery/hugo.md b/frontend/content/docs/gallery/hugo.md index 78f34a7c..1157b036 100644 --- a/frontend/content/docs/gallery/hugo.md +++ b/frontend/content/docs/gallery/hugo.md @@ -47,7 +47,7 @@ Use `{{< >}}`, not `{{% %}}`, so Markdown leaves the gallery's HTML alone. Each ## Options -Options go inside the shortcode as YAML, in the gallery's own spelling (`headingLevel`, `groupOrder`, `themeSwitch`, `seeAll`, `deepLinks`). On this page the gallery gets a heading, and two screens get a title and a caption. `order` puts two screens first. The Mac approver group gets a new title and shows its windows whole, and the iPhone tab comes first: +Options go inside the shortcode as YAML, in the gallery's own spelling (`headingLevel`, `groupOrder`, `themeSwitch`, `seeAll`, `deepLinks`, `newBadges`). On this page the gallery gets a heading, and two screens get a title and a caption. `order` puts two screens first. The Mac approver group gets a new title and shows its windows whole, and the iPhone tab comes first: ```md diff --git a/frontend/content/docs/gallery/mkdocs.md b/frontend/content/docs/gallery/mkdocs.md index 64b83278..45fbfa92 100644 --- a/frontend/content/docs/gallery/mkdocs.md +++ b/frontend/content/docs/gallery/mkdocs.md @@ -71,7 +71,7 @@ The block is YAML: `manifest`, then the gallery's options. Each manifest is read ## Options -The options are the [Python package's](/docs/gallery/python/), in its spelling (`heading_level`, `group_order`, `theme_switch`, `see_all`, `deep_links`), passed to it as they are. On this page the gallery gets a heading, and two screens get a title and a caption. `order` puts two screens first. The Mac approver group gets a new title and shows its windows whole, and the iPhone tab comes first: +The options are the [Python package's](/docs/gallery/python/), in its spelling (`heading_level`, `group_order`, `theme_switch`, `see_all`, `deep_links`, `new_badges`), passed to it as they are. On this page the gallery gets a heading, and two screens get a title and a caption. `order` puts two screens first. The Mac approver group gets a new title and shows its windows whole, and the iPhone tab comes first: ````md diff --git a/frontend/content/docs/gallery/options.md b/frontend/content/docs/gallery/options.md index ef68d687..01b09b82 100644 --- a/frontend/content/docs/gallery/options.md +++ b/frontend/content/docs/gallery/options.md @@ -81,6 +81,9 @@ Every option is optional. Ruby and Python spell the multi-word ones in snake cas | `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. | 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. @@ -117,6 +120,9 @@ labels, so a French site changes those too. These are the options of the gallery | `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. | ## Theming @@ -194,6 +200,27 @@ ignores the rest. It's off by default because your page may use the hash itself, 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 VisualCI approved the picture, so a page you built weeks ago doesn't still +call those screens new. 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. + ## 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. diff --git a/frontend/content/docs/gallery/python.md b/frontend/content/docs/gallery/python.md index 8c3262b7..67e5715a 100644 --- a/frontend/content/docs/gallery/python.md +++ b/frontend/content/docs/gallery/python.md @@ -336,7 +336,7 @@ Its template, `templates/index.html`, links the copied files by relative path: ## Options -`render` takes the gallery's options as keyword arguments, in snake case: `title`, `heading_level`, `id`, `screens`, `order`, `groups`, `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `deep_links` and `text`. `None` is the same as leaving an option out, except for `title`, where it means no heading. The Django view's options give two screens a title and a caption, put four screens first, and show the Mac app's windows whole: +`render` takes the gallery's options as keyword arguments, in snake case: `title`, `heading_level`, `id`, `screens`, `order`, `groups`, `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `deep_links`, `text`, `search`, `zoom` and `new_badges`. `None` is the same as leaving an option out, except for `title`, where it means no heading. The Django view's options give two screens a title and a caption, put four screens first, and show the Mac app's windows whole: ```python @@ -357,7 +357,7 @@ An option that's wrong (an unknown `layout`, an `id` that isn't a valid id) rais After the page has loaded, the gallery preloads the images a reader is likely to look at next. `preload=False` turns that off, and `preload={"count": 200, "bytes": 20_000_000}` sets your own limits. It's on by default, and [Preloading](/docs/gallery/options/#preloading) says what it fetches and when. -`deep_links=True` puts what the reader is looking at in the page's URL (the tab, the open screen, the values), so a copied link opens the same view; [Deep links](/docs/gallery/options/#deep-links) has the details. `text` changes the gallery's own words, for a site in another language: `text={"close": "Fermer", "open": "Agrandir « {title} »"}`. [Your own words](/docs/gallery/options/#your-own-words) lists every key and its default. +`deep_links=True` puts what the reader is looking at in the page's URL (the tab, the open screen, the values), so a copied link opens the same view; [Deep links](/docs/gallery/options/#deep-links) has the details. `text` changes the gallery's own words, for a site in another language: `text={"close": "Fermer", "open": "Agrandir « {title} »"}`. [Your own words](/docs/gallery/options/#your-own-words) lists every key and its default. `search=False` takes away the search box a gallery of 40 screens or more gets, `zoom=False` turns off zooming in the full-size view, and `new_badges=14` badges the screens that changed in the last 14 days ([Search](/docs/gallery/options/#search), [Zoom](/docs/gallery/options/#zoom), [New badges](/docs/gallery/options/#new-badges)). ## A band on the homepage diff --git a/frontend/content/docs/gallery/ruby.md b/frontend/content/docs/gallery/ruby.md index c4e4a110..1fd2ee38 100644 --- a/frontend/content/docs/gallery/ruby.md +++ b/frontend/content/docs/gallery/ruby.md @@ -273,11 +273,11 @@ bundle exec rackup ## Options -The helper and `render` take the [gallery options](/docs/gallery/options/#options) as keyword arguments, in snake case: `title`, `heading_level`, `id`, `screens`, `order`, `groups`, `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `deep_links` and `text`. Hash keys inside them can be strings or symbols, and `groups`' `size` and `fit` take either too (`fit: :contain`). The [screenshots view](#the-page) above uses five of them. +The helper and `render` take the [gallery options](/docs/gallery/options/#options) as keyword arguments, in snake case: `title`, `heading_level`, `id`, `screens`, `order`, `groups`, `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `deep_links`, `text`, `search`, `zoom` and `new_badges`. Hash keys inside them can be strings or symbols, and `groups`' `size` and `fit` take either too (`fit: :contain`). The [screenshots view](#the-page) above uses five of them. After the page has loaded, the gallery preloads the images a reader is likely to look at next. `preload: false` turns that off, and `preload: { count: 200, bytes: 20_000_000 }` sets your own limits. It's on by default, and [Preloading](/docs/gallery/options/#preloading) says what it fetches and when. -`deep_links: true` keeps the shown tab, the open screen and the chosen values in the page's URL, so a link opens them ([Deep links](/docs/gallery/options/#deep-links)). `text:` changes the gallery's own words, for another language or tone: `text: { label: 'Captures', open: 'Agrandir « {title} »', close: 'Fermer' }`. [Your own words](/docs/gallery/options/#your-own-words) lists every key. +`deep_links: true` keeps the shown tab, the open screen and the chosen values in the page's URL, so a link opens them ([Deep links](/docs/gallery/options/#deep-links)). `text:` changes the gallery's own words, for another language or tone: `text: { label: 'Captures', open: 'Agrandir « {title} »', close: 'Fermer' }`. [Your own words](/docs/gallery/options/#your-own-words) lists every key. `search: false` takes away the search box a gallery of 40 screens or more gets, `zoom: false` turns off zooming in the full-size view, and `new_badges: 14` badges the screens that changed in the last 14 days ([Search](/docs/gallery/options/#search), [Zoom](/docs/gallery/options/#zoom), [New badges](/docs/gallery/options/#new-badges)). An option the gem can't use raises `VisualCI::Gallery::Error`, naming the option as the [options page](/docs/gallery/options/) spells it (`gallery option headingLevel is invalid`). Give each gallery its own `id:` when a page has more than one. diff --git a/frontend/content/docs/gallery/rust.md b/frontend/content/docs/gallery/rust.md index 0b984fef..4be7a7a0 100644 --- a/frontend/content/docs/gallery/rust.md +++ b/frontend/content/docs/gallery/rust.md @@ -320,7 +320,7 @@ pub fn options() -> Options { } ``` -The setters are `title`, `heading_level`, `id`, `screen` (a screen's title and caption, by key), `order`, `group` (a group's title, size and fit, by name), `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `preload_caps`, `deep_links` and `text` (one of the gallery's own words, by key: `.text("close", "Fermer")`; see [Your own words](/docs/gallery/options/#your-own-words)). `title(None)` leaves out the heading. `Options::from_json` takes the same options as a `&serde_json::Value` object, with the names the JS library uses (`headingLevel`, `themeSwitch`). [Gallery options](/docs/gallery/options/) says what each one does. +The setters are `title`, `heading_level`, `id`, `screen` (a screen's title and caption, by key), `order`, `group` (a group's title, size and fit, by name), `group_order`, `credit`, `layout`, `theme_switch`, `see_all`, `preload`, `preload_caps`, `deep_links`, `search` and `search_from` (the search box always or never, or from a number of screens), `zoom`, `new_badges` and `new_badges_days` (the New badge, for 30 days or your own number), and `text` (one of the gallery's own words, by key: `.text("close", "Fermer")`; see [Your own words](/docs/gallery/options/#your-own-words)). `title(None)` leaves out the heading. `Options::from_json` takes the same options as a `&serde_json::Value` object, with the names the JS library uses (`headingLevel`, `themeSwitch`). [Gallery options](/docs/gallery/options/) says what each one does. After the page has loaded, the gallery preloads the images a reader is likely to look at next. `.preload(false)` turns that off, and `.preload_caps(None, Some(200), Some(20_000_000), None)` sets your own limits (fold, count, bytes and requests at once; `None` keeps a default). It's on by default, and [Preloading](/docs/gallery/options/#preloading) says what it fetches and when. From 2d04a6ac1c62c1e9181ee2f1060871ba05ccc573 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 14:30:10 +0000 Subject: [PATCH 3/4] Gallery zoom: a mouse wheel's notch zooms by about a quarter, not 2.7 times --- clients/gallery/js/src/hydrate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/gallery/js/src/hydrate.ts b/clients/gallery/js/src/hydrate.ts index c3c9f4b2..46aaeb9a 100644 --- a/clients/gallery/js/src/hydrate.ts +++ b/clients/gallery/js/src/hydrate.ts @@ -563,7 +563,9 @@ export function hydrate(el: HTMLElement, options: HydrateOptions = {}): Gallery // A plain wheel scrolls; with ctrl (a trackpad's pinch sends that) or cmd it zooms. if (!(e.ctrlKey || e.metaKey)) return; e.preventDefault(); - zoomAt(scale * Math.exp(-e.deltaY * 0.01), e.clientX, e.clientY); + // A mouse's notch (about 100) zooms by a quarter; a pinch sends many small steps. Lines and pages count as 20 px. + const dy = e.deltaMode === 0 ? e.deltaY : e.deltaY * 20; + zoomAt(scale * Math.exp(-Math.max(-50, Math.min(50, dy)) * 0.005), e.clientX, e.clientY); }; const onDouble = (e: MouseEvent) => { if (!(e.target as Element).closest?.("img")) return; From b21c18644e4ca8795c01afde98d2f269ca72a5ba Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 14:30:38 +0000 Subject: [PATCH 4/4] Changelog: gallery libraries 0.5.0, search, zoom and New badges --- ...26-12-06-0330-gallery-libraries-050-search-zoom-new-badges.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 frontend/content/changelog/2026-12-06-0330-gallery-libraries-050-search-zoom-new-badges.md diff --git a/frontend/content/changelog/2026-12-06-0330-gallery-libraries-050-search-zoom-new-badges.md b/frontend/content/changelog/2026-12-06-0330-gallery-libraries-050-search-zoom-new-badges.md new file mode 100644 index 00000000..ffb6e80d --- /dev/null +++ b/frontend/content/changelog/2026-12-06-0330-gallery-libraries-050-search-zoom-new-badges.md @@ -0,0 +1 @@ +**Gallery libraries 0.5.0:** three options, each quiet until a gallery needs it. `search` puts a box over the grid once it has 40 screens (or your own number, or always, or never) that filters cards by title and caption across tabs. `zoom` lets a reader pinch, ctrl-scroll, double-click or press + and - in the full-size view, with no buttons; on by default. `newBadges` marks the screens whose picture changed in the last 30 days (or your own number), decided in the reader's browser so an old build doesn't keep calling them new; off by default. Every language and the Hugo module have all three. [Options](/docs/gallery/options/#search)