Files
pipelines/app/tool/capture/touch.mjs
T
alan fba3b924f1 Chat stack: hold and drag to reorder the open chats, or onto x to remove
A 300 ms hold lifts a chat in the open column; dragging opens a gap and
dropping commits through ChatWorkspaceController.movePane, the pane order
the server syncs. An x comes in at the bottom while dragging; dropping on
it removes the chat with Undo, which restores its place. Escape, a
cancelled pointer or a drop away from the column put it back. Move up,
Move down and Remove are semantic actions. Repaint-only motion; reduced
motion swaps at once. Also keep floating-layout tracking out of
initState, and let the capture kit hold a press before a drag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:17:51 +00:00

49 lines
1.9 KiB
JavaScript

// Touch input over one DevTools page session, for phone/tablet review:
// a touch-screen emulation switch, one-finger swipes and two-finger pinches.
// The events are trusted browser input, so they reach whatever the page puts
// under the finger (a Flutter canvas or an iframe platform view alike).
import { setTimeout as delay } from 'node:timers/promises';
/** Emulates a touch screen (mobile metrics, 5 touch points). */
export async function enableTouch(send, { width, height }) {
await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: true });
await send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 });
}
/** The finger a held swipe left down, if any: the next swipe moves it on. */
let held = null;
/**
* One finger down at [at], held [press] ms (a long press), moved by dx/dy in
* [steps] moves [gap] ms apart, lifted unless [hold] (to capture mid-drag;
* the next swipe continues from where it stopped instead of touching down).
*/
export async function swipe(send, at, { dx = 0, dy = 0, steps = 12, gap = 16, press = 0, hold = false } = {}) {
const touch = (type, x, y) => send('Input.dispatchTouchEvent', {
type, touchPoints: type === 'touchEnd' ? [] : [{ x, y, id: 1 }],
});
const from = held ?? at;
if (!held) await touch('touchStart', from.x, from.y);
if (press > 0) await delay(press);
for (let i = 1; i <= steps; i++) {
await delay(gap);
await touch('touchMove', from.x + (dx * i) / steps, from.y + (dy * i) / steps);
}
const to = { x: from.x + dx, y: from.y + dy };
if (hold) {
held = to;
} else {
held = null;
await touch('touchEnd');
}
return { from, to };
}
/** Two fingers spread (scale > 1) or closed (< 1) around [at]. */
export async function pinch(send, at, scale) {
await send('Input.synthesizePinchGesture', {
x: at.x, y: at.y, scaleFactor: scale, relativeSpeed: 300, gestureSourceType: 'touch',
});
return at;
}