Make the puzzle playable by touch on phones #8

Merged
cmoriarty merged 1 commit from mobile-touch-layout into main 2026-12-02 22:18:43 -05:00
Owner

What

Makes the puzzle playable one-handed on a phone. Pieces are sized so a finger can grab them, the page stops moving while you play, and the tray scrolls instead of shrinking.

  • Finger-sized pieces. planLayout measures the grabbable span on the narrow side of the piece box and floors it at MIN_PIECE_PX = 48 with at least MIN_SLOTS_PER_ROW = 3 columns, so a 4×4 on a 402pt-wide phone gives ~63×47pt pieces instead of ~28pt ones. The floor applies to at least half the pieces; flat-edged pieces draw a little smaller (~43×32) rather than forcing every puzzle down to 3 columns at 12×12.
  • No page scroll, pan or pinch while playing. .game-touch is position: fixed; touch-action: none; overscroll-behavior: none; the tray panel alone opts back into pan-y.
  • Tray as a scrolling panel. One native-scroller implementation now serves both the wide and the stacked (portrait) plan, so it merges with the tray minimum-size rule on main instead of re-implementing it. Tray size is fixed; content scrolls. Chevron paging is the reliable path because pieces cover every pixel a drag-to-pan would use.
  • Layered unplaced pieces (layer: 'shelf' | 'field') with derived shelf positions, so no two tray pieces can overlap by construction, plus a coarse snap threshold and cell alignment.
  • Resume keeps layers. SavedPiece.layer is optional and validated; v1 records without it map unplaced pieces to the shelf. Returning a piece to the shelf scrolls it into view.

Verification

  • Gate: npm test 122/122 (9 files), npm run typecheck clean, npm run lint 3 pre-existing warnings only, npm run build ok, npx playwright test 1/1. openspec validate mobile-touch-layout --strict passes.
  • Desktop 1440×900 unchanged: wheel scroll + thumb drag, mouse drag leaves the piece on the field, 144/144 solve, reveal-on-return.
  • Plan/DOM agreement at 402×713: 4×4 fits without scrolling, 6×6 scrolls, no piece clipped, no phantom scroll.
  • iOS Simulator (iPhone 17 Pro, Safari/WebKit, real HID touch events): layout matches the plan within ~1pt; taps drive the reference sheet, sorting and the setup flow; swipes reach WebKit; the page never pans or pinches under a swipe on the board or a two-finger pinch; and a dragged piece snapped — MOVES 0 → 1, PLACED 0/16 → 1/16, with the piece locked flush to the cell grid. Resume screen lists in-progress records.
  • Not covered by hand: on-device rotation (no simulator orientation hook) — covered by the unit and resize tests.

Notes for review

  • Rebased onto main (960c946); the tray minimum-size rule and resume-in-progress both survive, and the spec deltas were re-based on main's wording.
  • openspec archive mobile-touch-layout should happen after this is merged.
## What Makes the puzzle playable one-handed on a phone. Pieces are sized so a finger can grab them, the page stops moving while you play, and the tray scrolls instead of shrinking. - **Finger-sized pieces.** `planLayout` measures the grabbable span on the narrow side of the piece box and floors it at `MIN_PIECE_PX = 48` with at least `MIN_SLOTS_PER_ROW = 3` columns, so a 4×4 on a 402pt-wide phone gives ~63×47pt pieces instead of ~28pt ones. The floor applies to at least half the pieces; flat-edged pieces draw a little smaller (~43×32) rather than forcing every puzzle down to 3 columns at 12×12. - **No page scroll, pan or pinch while playing.** `.game-touch` is `position: fixed; touch-action: none; overscroll-behavior: none`; the tray panel alone opts back into `pan-y`. - **Tray as a scrolling panel.** One native-scroller implementation now serves both the wide and the stacked (portrait) plan, so it merges with the tray minimum-size rule on main instead of re-implementing it. Tray size is fixed; content scrolls. Chevron paging is the reliable path because pieces cover every pixel a drag-to-pan would use. - **Layered unplaced pieces** (`layer: 'shelf' | 'field'`) with derived shelf positions, so no two tray pieces can overlap by construction, plus a coarse snap threshold and cell alignment. - **Resume keeps layers.** `SavedPiece.layer` is optional and validated; v1 records without it map unplaced pieces to the shelf. Returning a piece to the shelf scrolls it into view. ## Verification - Gate: `npm test` 122/122 (9 files), `npm run typecheck` clean, `npm run lint` 3 pre-existing warnings only, `npm run build` ok, `npx playwright test` 1/1. `openspec validate mobile-touch-layout --strict` passes. - Desktop 1440×900 unchanged: wheel scroll + thumb drag, mouse drag leaves the piece on the field, 144/144 solve, reveal-on-return. - Plan/DOM agreement at 402×713: 4×4 fits without scrolling, 6×6 scrolls, no piece clipped, no phantom scroll. - **iOS Simulator (iPhone 17 Pro, Safari/WebKit, real HID touch events):** layout matches the plan within ~1pt; taps drive the reference sheet, sorting and the setup flow; swipes reach WebKit; the page never pans or pinches under a swipe on the board or a two-finger pinch; and a dragged piece **snapped** — MOVES 0 → 1, PLACED 0/16 → 1/16, with the piece locked flush to the cell grid. Resume screen lists in-progress records. - Not covered by hand: on-device rotation (no simulator orientation hook) — covered by the unit and resize tests. ## Notes for review - Rebased onto `main` (960c946); the tray minimum-size rule and resume-in-progress both survive, and the spec deltas were re-based on main's wording. - `openspec archive mobile-touch-layout` should happen **after** this is merged.
The whole field used to be scaled to fit the viewport, so phone pieces
rendered 15-45px and a mis-parsed drag panned the page instead of moving
a piece. planLayout() now picks an arrangement from the viewport and
input type: the mouse layout is unchanged, portrait touch gets a
full-width board with a scrolling, paging shelf beneath it, and coarse
landscape keeps the tray beside the board.

- Slot pitch comes from the real piece box and the grabbable span is
  clamped to 48 CSS px on its narrow side; one size per puzzle, so
  pieces stop resizing as the tray empties and the shelf scrolls instead
  of shrinking past the floor.
- Unplaced pieces live on a 'shelf' layer with derived positions, which
  lets the shelf re-flow, makes sort-edges a flag flip, and reserves the
  dragged piece's slot. Drops are snap / field / shelf.
- Touch drags lift the piece 30px above the fingertip (the lifted
  position is what lands), suppress taps, capture moves on the play
  surface and ends on window, and auto-scroll the shelf at its edges.
- The page can no longer pan, pinch or rubber-band during play; stats
  controls become SVG icon buttons, the reference becomes a full-screen
  sheet, and dragged pieces get no CSS filter on touch because WebKit
  paints drop-shadow trails.
- New src/lib/layout.test.ts plus a rewritten usePuzzle.test.ts (87
  tests). Verified in the iOS Simulator and by an end-to-end trusted
  touch solve (16/16 placed, no page scroll) at 402x713.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cmoriarty/brooke!8
No description provided.