Kidsâ toys are physical. Screen time is digital. Most âeducational appsâ pick one side and stay there.
We wanted to see what happens when a physical building-block set has a digital counterpart that runs entirely in the browser â no app store, no download, no backend, no account. The result is a small jigsaw puzzle that uses scenes from our real block sets: Snow Garden, Sea Creatures, Coral Reef, Dinosaur Jungle, and Rainbow Waffle Blocks.
This post is about the engineering side: how the puzzle is sliced, dragged, snapped, and grouped, and what constraints came from the fact that the images are not random stock photos â they are photos of physical toys that kids already build with.
You can try the puzzle here: SUPUZZ Puzzle Online.
The constraints we started with
Three constraints shaped the implementation more than any library choice:
- It has to work on phones and tablets. The puzzle page says âWorks on phones and tablets,â and that is not marketing copy. Pointer events, not just mouse events, are the baseline.
- No backend state. There is no âsave gameâ API. The puzzle is a client-side state machine. If you reload, you start over. That is a deliberate trade-off: zero infrastructure, zero privacy surface.
- The images are product images. They are not generic jigsaw art. Each scene corresponds to a physical set, and the visual characteristics of the scene affect which grid sizes feel fair. More on that below.
Slicing the image into pieces
We use a CSS background-position approach rather than generating individual image files. The board is a grid, and each piece is a div with the full scene as its background, shifted by the pieceâs row and column.
function createPiece(sceneUrl, row, col, rows, cols) {
const piece = document.createElement('div');
piece.className = 'puzzle-piece';
piece.dataset.row = row;
piece.dataset.col = col;
piece.style.backgroundImage = `url(${sceneUrl})`;
piece.style.backgroundSize = `${cols * 100}% ${rows * 100}%`;
piece.style.backgroundPosition =
`${(col / (cols - 1)) * 100}% ${(row / (rows - 1)) * 100}%`;
return piece;
}
The grid sizes range from 3Ã3 to 7Ã7. The same scene is reused across difficulties, which means the slicing function has to be resolution-independent. A 3Ã3 Snow Garden and a 7Ã7 Snow Garden use the same source image; only rows and cols change.
This is also where the first product-design decision shows up: not every scene is equally readable at every difficulty. Snow Garden has large low-contrast areas, so 6Ã6 and 7Ã7 are harder than they look. Coral Reef has high-contrast shapes, so it tolerates denser grids. Dinosaur Jungle is detail-heavy and works well at 5Ã5 and above. We did not build an automatic difficulty scorer, but the scene selection in the UI reflects those observations.
Dragging with pointer events
The drag layer uses pointer events so the same code path works for mouse, touch, and pen. The piece follows the pointer with a CSS transform, and on pointerup we decide whether it snaps.
let activePiece = null;
let offsetX = 0;
let offsetY = 0;
board.addEventListener('pointerdown', (e) => {
const piece = e.target.closest('.puzzle-piece');
if (!piece) return;
activePiece = piece;
const rect = piece.getBoundingClientRect();
offsetX = e.clientX - rect.left;
offsetY = e.clientY - rect.top;
piece.setPointerCapture(e.pointerId);
piece.classList.add('dragging');
});
board.addEventListener('pointermove', (e) => {
if (!activePiece) return;
activePiece.style.transform =
`translate(${e.clientX - offsetX - activePiece.offsetLeft}px, ` +
`${e.clientY - offsetY - activePiece.offsetTop}px)`;
});
board.addEventListener('pointerup', () => {
if (!activePiece) return;
activePiece.classList.remove('dragging');
trySnap(activePiece);
activePiece = null;
});
Two details matter here. First, setPointerCapture keeps the drag alive even if the pointer leaves the piece, which is important on small screens. Second, we do not re-render the board on every move. The piece is transformed, and the snap decision happens once on pointerup.
Snapping and grouping with union-find
A jigsaw is not âeach piece snaps to its correct cell.â It is âpieces that are correctly adjacent become a group, and groups move together.â That is a union-find problem.
Each piece starts as its own group. When a piece is dropped near its correct board position, we check whether its immediate neighbors are already in their correct positions. If they are, we merge the groups.
const parent = new Map();
function find(id) {
if (parent.get(id) !== id) parent.set(id, find(parent.get(id)));
return parent.get(id);
}
function union(a, b) {
const ra = find(a);
const rb = find(b);
if (ra !== rb) parent.set(rb, ra);
}
function trySnap(piece) {
const row = Number(piece.dataset.row);
const col = Number(piece.dataset.col);
const target = cellCenter(row, col);
const current = pieceCenter(piece);
const distance = Math.hypot(current.x - target.x, current.y - target.y);
if (distance > SNAP_THRESHOLD) return;
piece.style.transform = '';
piece.dataset.locked = 'true';
// Merge with any neighbor that is already locked in place.
[[row - 1, col], [row + 1, col], [row, col - 1], [row, col + 1]]
.forEach(([r, c]) => {
const neighbor = pieceAt(r, c);
if (neighbor && neighbor.dataset.locked === 'true') {
union(piece.dataset.id, neighbor.dataset.id);
}
});
renderGroups();
}
renderGroups() is intentionally boring: it collects pieces by root group and applies a shared offset to the group container. The interesting part is that the snap threshold is generous. On touch devices, a tight threshold feels broken. A loose threshold feels forgiving. We tuned it by trying the puzzle on a phone, not by guessing.
What âno backendâ actually buys you
The puzzle page says: âYour photo stays in this browser and is never uploaded.â That is true for the custom-photo mode, and it is true because there is no upload endpoint. The image is read with FileReader or an object URL, sliced client-side, and never leaves the page.
That constraint is not just a privacy feature. It is an architecture decision that removes a whole class of problems: no storage costs, no moderation queue, no GDPR surface for user images, no server-side session state. The trade-off is equally clear: no cross-device save, no leaderboard, no analytics on individual puzzle completion unless you add client-side events.
For a small product site, that trade-off is worth it. The puzzle is a lightweight digital layer on top of a physical product, not a standalone game platform.
The phygital part: digital as a bridge to physical
The scenes are not decorative. Each one maps to a physical set. The Snow Garden puzzle uses the Snow Garden blocks. The Coral Reef puzzle uses the Coral Reef set. The Dinosaur Jungle puzzle uses the Dinosaur Jungle set.
That mapping changes the design brief. The puzzle is not trying to replace the physical toy. It is trying to be a preview and an extension: a child can play the digital puzzle, recognize the scene, and then build it with real blocks. The page describes the pictures as âconversation starters,â and that is the intended use: the digital puzzle gives the child and parent something to talk about before or after building.
From an engineering perspective, this is why the difficulty ramp matters more than the number of scenes. A 3Ã3 puzzle is for a very young child; a 7Ã7 puzzle is for an older child or an adult. The same scene has to work at both ends. That is a harder constraint than âmake a jigsaw puzzle.â
What we would do differently
Two things.
First, we would add a completion event that fires only client-side, so the page can show a small âyou finishedâ state without a backend. That is straightforward and we skipped it in the first version.
Second, we would make the snap feedback more explicit. Right now the piece locks into place, but there is no haptic or visual confirmation beyond the transform reset. On mobile, a short vibration or a subtle pulse would make the interaction feel more finished.
Neither of these is a rewrite. They are small refinements that come from watching people use the puzzle on a phone.
Try it
The puzzle is free and browser-only: SUPUZZ Puzzle Online. Each scene links back to the physical set that inspired it â for example, the Snow Garden building blocks and the Dinosaur Jungle set.
If you are building something similar â a physical product with a lightweight digital layer, or a client-side puzzle with no backend â I would be curious what constraints you ran into. The interesting part is rarely the drag-and-drop. It is the boundary between what stays digital and what stays physical.
Top comments (0)