A browser-based classic jigsaw puzzle game (React + Vite + TypeScript)
- TypeScript 92.7%
- CSS 7.1%
- HTML 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .opencode | ||
| e2e | ||
| openspec | ||
| public | ||
| src | ||
| .gitignore | ||
| .oxlintrc.json | ||
| AGENTS.md | ||
| index.html | ||
| package-lock.json | ||
| package.json | ||
| playwright.config.ts | ||
| README.md | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
| tsconfig.node.json | ||
| vite.config.ts | ||
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.tsprocedurally generates classic jigsaw piece outlines (interlocking tabs and blanks) as SVG paths from a grid size and a seed.src/lib/image.tsnormalizes any source image (built-in or uploaded) to a 4:3, ≤1600px PNG data URL via an offscreen canvas.src/hooks/usePuzzle.tsowns 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.