Skip to content

feat: open the product image larger, with zoom, when the buyer taps it - #20

Merged
grunch merged 1 commit into
mainfrom
feat/product-image-viewer
Nov 7, 2026
Merged

grunch merged 1 commit into
mainfrom
feat/product-image-viewer

Conversation

@grunch

@grunch grunch commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

What

On a product page, tapping the shirt image did nothing. It now opens a dialog with the shirt larger, so the buyer can look at the print up close before buying.

  • The image is a button (#product-zoom, labelled "View larger image"), with a magnifier badge in its corner so it looks tappable.
  • The dialog redraws the shirt at twice the page's scale (VIEWER_SCALE = 2, a 2398 × 2624 canvas) in the colour picked, fitted to the screen. The title is the product and colour, e.g. "Mostro Invaders T-shirt in navy blue".
  • A tap on the image zooms in 2.5× (ZOOM_FACTOR) and keeps the tapped point under the finger. Another tap zooms back out. The buyer moves around by dragging (touch), scrolling or the arrow keys (the stage is focusable, since Safari does not focus a scroller by itself). The zoom button in the header does the same from the keyboard, centred, with aria-pressed.
  • It opens at once. A spinner shows while it draws, and the drawing happens after the dialog has painted, so the tap is answered even on a slow phone. A colour already drawn is not drawn again.
  • It closes on the close button, Escape, or a press that starts and ends on the backdrop. A drag that only ends there (a scrollbar, say) leaves it open. Focus goes back to the image. A turned phone or a resized window, and every new opening, start with the whole shirt in view.

Why this way

  • Pure where it can be. Where a tap falls and where to scroll so it stays under the finger are decisions, so they live in the pure src/store/zoom.js with unit tests at 100%. src/store/image-viewer.js only measures and wires events, like size-guide.js.
  • Answered at once. Drawing the large canvas before opening took ~250 ms in headless Chromium, and over a second with the CPU throttled 4× (software rendering, so pessimistic). The buyer would have seen the same "nothing happens" this PR is about. With the dialog opened first, it paints 6–22 ms after the tap at the same settings.
  • No new dependencies. It uses plain DOM and CSS, <dialog> as the size guide does, CSSOM only for the zoomed width (allowed by style-src 'self'), and text through el()/textContent. The CSP is untouched.

Decision for the maintainer

The spec said scale 1 was the largest drawing, so a design file larger than the print area was never seen. That is no longer true. At scale 2 a series' text is sharp when zoomed, and a design file up to twice the print area (1060 × 1400 px) shows its extra detail in the zoomed view. designs/invaders-design.png (1070 × 1470) already does. The six arcade designs were shrunk to scale-1 size in 5a10f81, so they look upscaled when zoomed. Larger source files for them would make the zoom worth more, at the cost of a heavier collection page. That trade-off is left to you; this PR only updates the spec sentence to describe it (docs/SPEC.md, "Add a full design"). The shirt itself is the 1199 × 1312 base photo, upscaled; no file change would give it more detail.

Files

  • src/store/zoom.js (new, pure) and tests/store/zoom.test.js.
  • src/store/image-viewer.js (new, DOM).
  • src/store/product-page.js: opens the viewer.
  • product.html: the button. The 16 <id>.html pages were regenerated with npm run seo.
  • css/store.css: the badge, the dialog and the spinner. The stage gradient became a --stage-backdrop token shared with .product-stage.
  • src/store/icons.js: the zoomIn and zoomOut icons.
  • src/store/strings/{en,es,fr,it,pt}.js: enlargeImage, zoomImage, zoomHint in all five languages.
  • docs/SPEC.md, AGENTS.md, README.md: the new behaviour and modules.

Test plan

  • npm run coverage: 297/297 unit tests, 100% lines, branches and functions.
  • npm run coverage:all: 38/38 browser tests, 100% combined line coverage of src/.
  • New browser scenario (desktop):
    • The tap is answered at once with a spinner, and zoom before the drawing does nothing.
    • The canvas is twice the page's size, and a point of the shirt's body matches the page's colour.
    • The tapped point stays under the pointer when zoomed. The keyboard zoom centres, and the arrow keys scroll.
    • Escape, the close button and a backdrop press close it, but a drag that ends on the backdrop does not. Focus returns to the image.
    • The same colour is not redrawn (a mark on the canvas survives), and a new colour is.
  • New browser scenario (360 × 740 phone): the viewer fits the screen. Zoomed, it is more than twice the page's image and scrolls both ways. Turning the phone returns to the fitted view.
  • The drag-to-backdrop assertion fails with that fix reverted.
  • Looked at in Chromium at 1280 × 900 and at a 390 px phone with DPR 3 (Spanish UI): page badge, fitted view and zoomed view.
  • Not verified: a real iPhone or Android phone. Check the draw time, the touch panning and the memory of the 2398 × 2624 canvas (about 25 MB, kept while the page is open, on top of the page's own canvases).
  • Not verified: Safari keyboard focus on the stage (only Chromium runs the browser tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_016wLvLxLyWs3XJWb1qwvr5B

Summary by CodeRabbit

  • New Features
    • Product images can now be opened in a larger viewer. Tap or click the image to zoom in at that point, then toggle back to the fitted view.
    • Close the viewer with its close button, the backdrop, or Escape; zoom resets when the window is resized.
    • Image-viewer controls and guidance are available in English, Spanish, French, Italian, and Portuguese.
  • Tests
    • Added coverage for viewer opening, zooming, closing, image updates, and behavior on phone-sized screens.

Tapping the shirt on a product page did nothing, and on a phone its
1199 x 1312 drawing is shown about 330 px wide: too small to see the print
before buying. The image is now a button that opens a dialog. The shirt is
drawn again at twice the page's scale in the colour picked, fitted to the
screen, and a tap on it (or its zoom button, from the keyboard) zooms in
2.5x keeping that point under the finger; the buyer moves around by
dragging, scrolling or with the arrow keys.

The dialog opens at once with a spinner and draws once it has painted, so
the tap is answered even on a slow phone, and a colour already drawn is not
drawn again. A drag that only ends on the backdrop does not close it, and a
turned phone or resized window goes back to the whole shirt. The zoom
numbers and scroll math live in the pure zoom.js; the dialog is
image-viewer.js, driven by two browser scenarios (desktop and phone).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016wLvLxLyWs3XJWb1qwvr5B
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T15:34:04.057553Z 859f042 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Product pages now open an enlarged image viewer. The viewer draws the selected product at a larger scale, supports point-centered zoom and panning, and closes through its controls or Escape. Product pages, translations, styles, documentation, and tests include the viewer.

Changes

Product Image Viewer

Layer / File(s) Summary
Zoom geometry and tests
src/store/zoom.js, tests/store/zoom.test.js
Adds viewer scale and zoom constants, image-relative point and scroll calculations, and unit tests for these helpers.
Viewer dialog and interactions
src/store/image-viewer.js, src/store/icons.js, css/store.css, tests/e2e/store.e2e.js
Adds the dialog, deferred drawing, click and keyboard zoom, close behavior, viewer styling, and end-to-end coverage for drawing, zoom, focus, resizing, and reopening.
Product-page launch and localized labels
src/store/product-page.js, *.html, src/store/strings/*, README.md, docs/SPEC.md, AGENTS.md, css/store.css
Connects product-page buttons to the viewer, adds translated accessible labels and button styling, and updates product instructions, sizing guidance, and module inventories.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  actor Shopper
  participant product-page.js
  participant image-viewer.js
  participant ProductCanvas
  Shopper->>product-page.js: Click product-zoom
  product-page.js->>image-viewer.js: Open with product, color, label, and draw callback
  image-viewer.js->>ProductCanvas: Draw at VIEWER_SCALE when color key changes
  Shopper->>image-viewer.js: Tap image to toggle zoom
Loading

Possibly related PRs

  • MostroP2P/store#1: Adds the product page and drawing interface used to render the selected product in the viewer.
  • MostroP2P/store#2: Adds the translation interface used for viewer labels.
  • MostroP2P/store#12: Generates product pages from the template that now includes the zoom button.
Merge Risk: Minimal · up to 859f0

This adds a zoomable product image viewer. No actionable merge-blocking issue was identified; behavior on real phones was not tested by the author.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the new enlarged product image viewer and zoom feature.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 11 files. (21 skipped: 21 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit taps the shirt to see it wide,
The colors bloom, the fine threads hide no more.
A gentle scroll keeps details by its side,
One tap returns the whole design once more.
The rabbit hops, content with the view.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4285d186-ea74-46ac-8705-9ad5aa0e2576
Commits

Reviewing files that changed from the base of the PR and between 7ba6f3f and 859f042.

Files selected for processing: 32

  • AGENTS.md
  • README.md
  • a-wild-kyc-appeared.html
  • choose-your-fighter.html
  • css/store.css
  • docs/SPEC.md
  • fiatality.html
  • final-boss-inflation.html
  • high-scores.html
  • mostro-invaders.html
  • mostro-quotes-hold-my-invoice.html
  • mostro-quotes-i-buy-sats-from-strangers-on-the-internet.html
  • mostro-quotes-love-at-first-sat.html
  • mostro-quotes-mostro-do-it-better.html
  • mostro-quotes-my-node-my-rules.html
  • mostro-quotes-sex-is-great.html
  • mostro-quotes-somewhere-a-bank-is-crying.html
  • mostro-quotes-sovereign-at-first-sat.html
  • mostro-quotes-the-mostro-made-me-do-it.html
  • player-2-player.html
  • product.html
  • src/store/icons.js
  • src/store/image-viewer.js
  • src/store/product-page.js
  • src/store/strings/en.js
  • src/store/strings/es.js
  • src/store/strings/fr.js
  • src/store/strings/it.js
  • src/store/strings/pt.js
  • src/store/zoom.js
  • tests/e2e/store.e2e.js
  • tests/store/zoom.test.js

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@grunch
grunch merged commit 3c5aeb5 into main Nov 7, 2026
5 checks passed
@grunch
grunch deleted the feat/product-image-viewer branch November 7, 2026 15:39
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