Skip to content

feat(tooling): variant sheets, version comparison and pixel-offset diagrams - #705

Merged
huichen merged 1 commit into
mainfrom
feat/shot-offsets
Sep 17, 2026
Merged

huichen merged 1 commit into
mainfrom
feat/shot-offsets

Conversation

@huichen

@huichen huichen commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #703/#704. Three more questions get asked about a release that the harness could not answer; now it can.

variants-* — pick one of several styles

Renders one scenario once per declared variant (an inject script each) and composes a labelled sheet:

"running-icon-variants": {
  "variantsTitle": "运行指示图标 · 三个备选样式",
  "variants": [ { "label": "A · 实心圆点", "inject": "injects/running-dot.js" }, … ],
  "steps": [ { "wait": 900 }, { "inject": "{variantInject}" }, { "shot": "d-icon.png" } ]
}

The {variantInject} placeholder puts the injection inside the steps rather than at boot, because React re-renders and restores what a boot-time mutation changed. Verified: a diff of the three panels is an ~8×10px region — the icon — with the rest identical.

Purely visual: it edits the DOM in the browser. Whatever is chosen still has to be implemented.

compare-* — two captures, differences highlighted

Three-panel sheet: A with changed regions boxed in red, B boxed in blue and numbered, plus a difference panel (unchanged content faded, changes red). --threshold and --min-area keep anti-aliasing noise out. Works for two style options or two versions; the docs cover the two-version workflow (older checkouts need the harness copied in).

Verified on a known pair: 1 changed region, red outline on the left panel, blue on the right, red marks on the diff panel.

offsets + measure-* — pixel spacing and movement

Draws each element's box (name + size) and the pixel distance to its neighbour (mode: gap) or to the viewport edge (mode: edge); axis picks vertical/horizontal. Numbers are CSS pixels at the emulated viewport. With --baseline (an earlier measure-* run) each element gains a green label stating its movement and size change — verified with a simulated 8px shift producing 位移 +0, +8px · 宽 +4px on all four rows.

Bug fixed along the way

Element matching is now ranked instead of first-hit: an element whose own text is exactly the wanted name beats one whose aria-label merely contains it. 技能 was matching the composer's 选择技能 button — a silently wrong measurement in an offset diagram, and a wrong click elsewhere. Every measurement now logs the element it actually hit.

Two more fixes this surfaced: composed sheets needed a real CJK font (Pillow's default bitmap font is unreadable beside a 1200px panel and renders Chinese as tofu boxes) and panel downscaling; and the compare panel offsets were computed from a wrong assumption about the title row.

Video quality

Chrome emits screencast frames at the CSS viewport size (it ignores the emulated device scale factor, unlike stills), so a mobile clip was 390×844 while stills were 780×1688. The encode now upscales with Lanczos to the stills' pixel dimensions and uses crf 18 instead of the x264 default. That is interpolation, not extra optical detail, and the docs say so. Verified: the mp4 is 780×1688 h264 and the upscaled text is crisp and legible.

Also

The pointer indicator now defaults to on while recording, off for stills — a product shot should not gain a stray dot because its scenario had to tap something. --pointer true or a {"pointer": [x, y]} step asks for it explicitly.

Guide gains recipes 5–7; CLAUDE.md lists the new subcommands. Makefile still untouched.

Verification

  • node --check on the driver and every inject script; ast.parse on capture.py; scenario JSON parses.
  • All three features exercised end to end with the results inspected (not just exit codes): variant diff regions, compare boxes, offset labels, baseline movement labels.
  • Existing scenarios still capture on both platforms; video pipeline re-recorded and probed.
  • check-docs.py clean for the changed docs. No media committed.

…agrams

Three more things the screenshot harness could not do, each one a question that
gets asked about a release:

- **`variants-*`** renders one scenario once per declared style variant (an
  `inject` script each) and composes a labelled sheet, for "show me a few options
  so I can pick". The injection runs as a *step*, because React re-renders and
  would restore what a boot-time mutation changed. Purely visual: it edits the DOM
  in the browser, the product is untouched.

- **`compare-*`** takes two captures of the same screen (two style options, or two
  versions) and produces a three-panel sheet: A with changed regions boxed in red,
  B boxed in blue and numbered, plus a difference panel with unchanged content
  faded and changes red. `--threshold` keeps anti-aliasing noise out.

- **`offsets` steps + `measure-*`** draw an element's box (name and size) and the
  pixel distance to its neighbours (`mode: gap`) or to the viewport edge
  (`mode: edge`). With `--baseline` (an earlier `measure-*` run) each element also
  shows how far it moved and how its size changed. Numbers are CSS pixels at the
  emulated viewport, matching what a design file quotes.

Element matching is now **ranked** rather than first-hit: an element whose own text
is exactly the wanted name beats one whose aria-label merely contains it. This was
a real bug — `技能` matched the composer's `选择技能` button, which silently
produced a wrong measurement in an offset diagram (and would have clicked the
wrong control elsewhere). Every measurement logs the element it actually hit, so a
wrong match is visible instead of silent.

Composed sheets needed two fixes of their own: Pillow's default bitmap font is
unreadable next to a 1200px panel and renders CJK as tofu boxes, so a real CJK
font is loaded and panels are downscaled; and the compare panel offsets were
computed from the wrong assumption about the title row.

Video quality: Chrome emits screencast frames at the CSS viewport size (it ignores
the emulated device scale factor, unlike stills), so the encode now upscales with
Lanczos to the stills' pixel dimensions and encodes at crf 18 instead of the x264
default. Interpolated, not extra optical detail — the docs say so.

Also: the pointer indicator now defaults to on while recording and off for stills,
so a product shot no longer gains a stray dot just because its scenario had to tap
something.

The guide gains recipes 5-7 for the above; CLAUDE.md lists the new subcommands.
@huichen
huichen enabled auto-merge (squash) September 17, 2026 10:51
@huichen
huichen merged commit 09cc48b into main Sep 17, 2026
12 checks passed
@huichen
huichen deleted the feat/shot-offsets branch September 17, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant