A browser-based classic jigsaw puzzle game (React + Vite + TypeScript)
  • TypeScript 92.7%
  • CSS 7.1%
  • HTML 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-03 22:39:25 -05:00
.opencode Add OpenSpec planning for jigsaw puzzle game 2026-11-05 18:22:01 -05:00
e2e Add smart tray sort: edges first, then interior grouped by color 2026-12-03 22:37:56 -05:00
openspec Archive smart-sort 2026-12-03 22:39:25 -05:00
public Scaffold Vite + React + TypeScript app with test tooling 2026-11-05 18:31:51 -05:00
src Add smart tray sort: edges first, then interior grouped by color 2026-12-03 22:37:56 -05:00
.gitignore apply: implement the change and its tests 2026-11-27 22:34:11 +00:00
.oxlintrc.json Scaffold Vite + React + TypeScript app with test tooling 2026-11-05 18:31:51 -05:00
AGENTS.md Replace synthesized soundscapes with generated clips 2026-12-03 21:49:52 -05:00
index.html Make the puzzle playable by touch on phones 2026-12-02 22:09:47 -05:00
package-lock.json apply: implement the change and its tests 2026-11-27 22:34:11 +00:00
package.json apply: implement the change and its tests 2026-11-27 22:34:11 +00:00
playwright.config.ts apply: implement the change and its tests 2026-11-27 22:34:11 +00:00
README.md apply: implement the change and its tests 2026-11-27 22:34:11 +00:00
tsconfig.app.json Scaffold Vite + React + TypeScript app with test tooling 2026-11-05 18:31:51 -05:00
tsconfig.json Scaffold Vite + React + TypeScript app with test tooling 2026-11-05 18:31:51 -05:00
tsconfig.node.json Scaffold Vite + React + TypeScript app with test tooling 2026-11-05 18:31:51 -05:00
vite.config.ts apply: implement the change and its tests 2026-11-27 22:34:11 +00:00

Brooke — Jigsaw Puzzle

A browser-based classic jigsaw puzzle. Pick an image (a bundled sample or your own upload), choose a grid size, and solve the puzzle by dragging interlocking pieces from the tray onto the board. Puzzles made from a bundled image are remembered while in progress, so reopening the app offers a resume screen that restores each one exactly where you left off; puzzles from your own uploads are not remembered.

Built with React, Vite, and TypeScript. Fully client-side — no backend.

Requirements

  • Node.js 20+
  • npm 10+

Getting started

npm install
npm run dev

Then open the printed URL (default http://localhost:5173).

Scripts

Command What it does
npm run dev Start the Vite dev server with HMR
npm run build Typecheck and build a production bundle
npm run preview Serve the production build locally
npm run test Run the Vitest unit test suite once
npm run test:watch Run Vitest in watch mode
npx playwright test Run the Playwright browser smoke test
npm run lint Lint with oxlint
npm run typecheck Typecheck with tsc -b

Project layout

src/
  lib/        Pure puzzle logic (piece generation, image pipeline)
  hooks/      Game state (usePuzzle)
  components/ React UI (board, tray, pieces, picker, overlays)
  assets/     Built-in sample puzzle images
  test/       Test setup and app-level tests
openspec/     OpenSpec planning artifacts (specs, changes, archive)

How it works

  • src/lib/jigsaw.ts procedurally generates classic jigsaw piece outlines (interlocking tabs and blanks) as SVG paths from a grid size and a seed.
  • src/lib/image.ts normalizes any source image (built-in or uploaded) to a 4:3, ≤1600px PNG data URL via an offscreen canvas.
  • src/hooks/usePuzzle.ts owns the game state: piece positions, snapping, move count, timer, and completion.
  • Pieces are rendered as SVG <image> elements clipped to their jigsaw outline; dragging uses native pointer events (mouse + touch).
  • The tray keeps a fixed size: pieces render at a minimum scale, and when they do not all fit, the tray scrolls vertically — wheel over the tray or drag the scrollbar on its right edge. Pieces dropped back into the tray settle into the nearest empty slot instead of stacking.