Skip to content

See how your app actually fits together. An interactive, plain-English map of your codebase, drawn by Claude or Codex.

Fix touch gestures on the map

Menachem Kurkus31f95297de20
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53bbed2..df758fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## Unreleased
- **Fits phones and tablets:** the top bar wraps instead of running off the screen, the details open as a sheet at the bottom of a phone (tap a box to see them), the long description under the title folds to a line with More / Less, and every control is at least 44 px to tap. Nothing changes with a mouse at 1000 px and wider. Requested in #18 and built by @menachem-kurkus in #19.
+- **Touch gestures on the map:** dragging or pinching on a phone or tablet made the map jump to unexpected places. A drag now follows only the finger that started it and ends when the browser takes over the touch (before, the drag stayed switched on and followed any later movement); a second finger starts a pinch instead of restarting the drag, and a third finger is ignored; two fingers zoom around the point between them and moving both pans; the first tap after a drag is no longer swallowed; and the browser no longer zooms or bounces the page under the map, or re-fits the map when a phone's address bar slides in and out. A mouse, a trackpad and the wheel work exactly as before.
## 0.4.2 (2026-10-30)
diff --git a/docs/development.md b/docs/development.md
index 4a01b6b..4cea1a3 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -93,6 +93,7 @@ The tests use Node's built-in test runner, so there's nothing to install (`npm t
| `agents.test.mjs` | telling Claude Code from Codex, and what a map built by each records and writes |
| `release.test.mjs` | the version agrees across both plugins' `plugin.json`, the README badge, the changelog and `CHECKSUMS.txt` |
| `supply-chain.test.mjs` | what the plugin can do stays what [Is it safe to install?](is-it-safe.md) says: no hooks, MCP servers or dependencies, one outbound request, a fixed list of programs and pre-approved scripts, no code loaded at run time, the vendored layout engine unchanged |
+| `touch.test.mjs` | touch gestures: a drag follows one finger and ends on a cancelled touch, two-finger pinch and pan, nothing re-fits the map mid-gesture (checks on the built page, not a real screen) |
Sample projects are written to a temp folder by `helpers.mjs` (`shopApp()`) or copied from `tests/fixtures/`. Anything secret-looking is assembled at runtime, so no real-looking key is ever committed.
diff --git a/skills/floorplan/assets/viewer.html b/skills/floorplan/assets/viewer.html
index 43dab0a..4b0ded8 100644
--- a/skills/floorplan/assets/viewer.html
+++ b/skills/floorplan/assets/viewer.html
@@ -138,6 +138,8 @@ header > * { pointer-events: auto; }
#stage { position: fixed; inset: 0; overflow: hidden; background-color: var(--bg); background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
#svg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
#svg.panning { cursor: grabbing; }
+#svg { touch-action: none; } /* a finger drags the map instead of the browser taking the touch; only affects touch */
+@media (pointer: coarse) { html, body { overscroll-behavior: none; } } /* no bounce of the page under the map */
#viewport { transform-origin: 0 0; }
#viewport.anim { transition: transform .5s var(--ease), opacity .35s var(--ease); }
#context { position: absolute; left: 24px; top: calc(var(--hh, 64px) + 8px); max-width: min(520px, calc(100% - var(--pw) - 64px)); pointer-events: none; transition: opacity .3s var(--ease); }
@@ -1274,17 +1276,58 @@ svg.addEventListener('wheel', (ev) => {
else zoomBy(Math.exp(-ev.deltaY * (ev.ctrlKey ? 0.01 : 0.0018)), ev.clientX - r.left, ev.clientY - r.top);
}, { passive: false });
let drag = null;
-svg.addEventListener('pointerdown', (ev) => { if (ev.button !== 0) return; drag = { x: ev.clientX, y: ev.clientY, tx: state.t.x, ty: state.t.y, moved: false }; });
+const fingers = new Map(); let pinch = null; // touch only: the fingers on the map, and the pinch they make
+let swallowClick = false; // touch screens don't reliably send a click after a drag or pinch, so a flag (cleared at the next touch) stops the end of a gesture selecting a box
+svg.addEventListener('click', (e) => { if (swallowClick) { swallowClick = false; e.stopPropagation(); } }, true);
+svg.addEventListener('pointerdown', (ev) => {
+ if (ev.button !== 0) return;
+ if (ev.pointerType === 'touch') {
+ if (fingers.size >= 2) return; // a third finger is ignored
+ fingers.set(ev.pointerId, { x: ev.clientX, y: ev.clientY }); swallowClick = false; vp.classList.remove('anim'); // a glide still running would keep moving the map under the finger
+ if (fingers.size === 2) { if (drag?.moved) swallowClick = true; drag = null; svg.classList.remove('panning'); hideTip(); pinch = { ...pinchNow(), t: { ...state.t }, moved: false }; return; }
+ }
+ drag = { id: ev.pointerId, x: ev.clientX, y: ev.clientY, tx: state.t.x, ty: state.t.y, moved: false };
+});
window.addEventListener('pointermove', (ev) => {
- if (!drag) return;
+ if (!drag || ev.pointerId !== drag.id) return; // only the finger that started the drag moves the map
const dx = ev.clientX - drag.x, dy = ev.clientY - drag.y;
if (!drag.moved && Math.hypot(dx, dy) < 4) return;
drag.moved = true; svg.classList.add('panning'); hideTip();
setT({ ...state.t, x: drag.tx + dx, y: drag.ty + dy }, false);
});
-window.addEventListener('pointerup', () => { if (drag?.moved) svg.addEventListener('click', (e) => e.stopPropagation(), { capture: true, once: true }); drag = null; svg.classList.remove('panning'); });
+const endDrag = (ev) => {
+ if (!drag || ev.pointerId !== drag.id) return;
+ if (drag.moved) { if (ev.pointerType === 'touch') swallowClick = true; else svg.addEventListener('click', (e) => e.stopPropagation(), { capture: true, once: true }); }
+ drag = null; svg.classList.remove('panning');
+};
+window.addEventListener('pointerup', endDrag);
+window.addEventListener('pointercancel', endDrag); // the browser took the touch over: end the drag instead of leaving it stuck
svg.addEventListener('click', () => select(null));
-window.addEventListener('resize', () => fit(false));
+// two fingers: pinch zooms around the point between them, and moving both together pans (one finger still drags)
+const pinchNow = () => { const [a, b] = [...fingers.values()]; return { d: Math.max(1, Math.hypot(a.x - b.x, a.y - b.y)), x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 }; };
+window.addEventListener('pointermove', (ev) => {
+ if (!fingers.has(ev.pointerId)) return;
+ fingers.set(ev.pointerId, { x: ev.clientX, y: ev.clientY });
+ if (!pinch || fingers.size !== 2) return;
+ const now = pinchNow(), r = stageRect(), t0 = pinch.t;
+ const k = clamp(t0.k * now.d / pinch.d, 0.08, 2.5), f = k / t0.k;
+ pinch.moved = true;
+ setT({ k, x: (now.x - r.left) - ((pinch.x - r.left) - t0.x) * f, y: (now.y - r.top) - ((pinch.y - r.top) - t0.y) * f }, false);
+});
+const liftFinger = (ev) => {
+ if (!fingers.delete(ev.pointerId)) return;
+ if (pinch?.moved) swallowClick = true; // lifting a finger after a pinch isn't a tap
+ if (fingers.size < 2) pinch = null;
+};
+window.addEventListener('pointerup', liftFinger);
+window.addEventListener('pointercancel', liftFinger);
+// on a touch device the browser's address bar sliding in and out resizes the window by a few pixels, mid-gesture: that must not re-fit the map
+let lastWidth = innerWidth;
+window.addEventListener('resize', () => {
+ const heightOnly = innerWidth === lastWidth; lastWidth = innerWidth;
+ if (matchMedia('(pointer: coarse)').matches && (heightOnly || drag || pinch)) return;
+ fit(false);
+});
$('#z-in').onclick = () => zoomBy(1.25);
$('#z-out').onclick = () => zoomBy(0.8);
$('#z-fit').onclick = () => fit(true);
diff --git a/tests/touch.test.mjs b/tests/touch.test.mjs
new file mode 100644
index 0000000..c9bff3d
--- /dev/null
+++ b/tests/touch.test.mjs
@@ -0,0 +1,39 @@
+// Touch gestures: the built map lets a finger drag it, two fingers pinch and move it, and no gesture leaves it stuck or
+// re-fits it. These are checks on the built page (the rules and the code are there), not on a real screen.
+import { test, before, after } from 'node:test';
+import assert from 'node:assert/strict';
+import fs from 'node:fs';
+import path from 'node:path';
+import { shopApp, scanAndBuild, cleanup } from './helpers.mjs';
+
+let root, html;
+before(() => { root = shopApp(); scanAndBuild(root); html = fs.readFileSync(path.join(root, 'floorplan', 'index.html'), 'utf8'); });
+after(() => cleanup(root));
+
+test('the map takes the touch itself, and the page does not bounce under it (touch screens only)', () => {
+ assert.match(html, /#svg \{ touch-action: none; \}/); // a finger can drag the map, and a pinch doesn't zoom the whole page
+ assert.match(html, /@media \(pointer: coarse\) \{ html, body \{ overscroll-behavior: none; \} \}/);
+});
+
+test('two fingers pinch the map (zooming around the point between them) and move it, using the same limits as the wheel', () => {
+ assert.match(html, /const k = clamp\(t0\.k \* now\.d \/ pinch\.d, 0\.08, 2\.5\)/);
+ assert.match(html, /const k = clamp\(state\.t\.k \* f, 0\.08, 2\.5\)/); // the wheel's limits
+ assert.match(html, /if \(fingers\.size === 2\) \{ if \(drag\?\.moved\) swallowClick = true; drag = null;/); // the second finger ends the one-finger drag
+});
+
+test('a drag follows only the finger that started it, ends when the browser cancels the touch, and a phone\'s address bar does not re-fit the map', () => {
+ assert.match(html, /if \(!drag \|\| ev\.pointerId !== drag\.id\) return;/);
+ assert.match(html, /window\.addEventListener\('pointercancel', endDrag\)/);
+ assert.match(html, /window\.addEventListener\('pointercancel', liftFinger\)/);
+ assert.match(html, /if \(matchMedia\('\(pointer: coarse\)'\)\.matches && \(heightOnly \|\| drag \|\| pinch\)\) return;\n fit\(false\);/);
+});
+
+test('a third finger is ignored, and the click that ends a drag is swallowed once and cleared at the next touch, so the next tap still works', () => {
+ assert.match(html, /swallowClick = false; vp\.classList\.remove\('anim'\)/);
+ assert.match(html, /if \(ev\.pointerType === 'touch'\) \{\n if \(fingers\.size >= 2\) return; \/\/ a third finger is ignored/);
+});
+
+test('none of this changes a mouse: the glide is only cancelled for a finger, and a mouse drag keeps its original one-time click guard', () => {
+ assert.match(html, /if \(ev\.pointerType === 'touch'\) swallowClick = true; else svg\.addEventListener\('click', \(e\) => e\.stopPropagation\(\), \{ capture: true, once: true \}\)/);
+ assert.match(html, /svg\.addEventListener\('click', \(\) => select\(null\)\);/);
+});