mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(web-runtime): drop swipe, restrict pressKey to browser-meaningful keys
Web has no swipe gesture, so swipes dispatched pointer events into empty
divs. Make swipe() and the swipes builtin no-op. For PressKey, replace
the always-"back" choice with a random pick from {enter, tab, escape,
up, down, left, right} - keys that have real semantics in a browser.
This commit is contained in:
1 parent
82cf889e16
commit
9c42744c00
1 file changed
+14
-21
+14
-21
@@ -308,8 +308,9 @@ const runtime = {
|
||||
inputText(p: { into: unknown; text: string }): unknown {
|
||||
return { kind: "InputText", into: p.into, text: p.text };
|
||||
},
|
||||
swipe(p: { from: unknown; to: unknown; durationMillis?: number }): unknown {
|
||||
return { kind: "Swipe", from: p.from, to: p.to, durationMillis: p.durationMillis };
|
||||
swipe(_p: { from: unknown; to: unknown; durationMillis?: number }): unknown {
|
||||
// Why: web has no swipe gesture; the factory returns null so Swipe() calls in specs no-op.
|
||||
return null;
|
||||
},
|
||||
pressKey(p: { key: string }): unknown {
|
||||
return { kind: "PressKey", key: p.key };
|
||||
@@ -392,7 +393,7 @@ function resolveGenerator(handle: ActionGeneratorHandle): unknown {
|
||||
case "waitOnce":
|
||||
return { kind: "Wait", durationMillis: 500 };
|
||||
case "pressKey":
|
||||
return { kind: "PressKey", key: "back" };
|
||||
return randomPressKey();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -422,24 +423,16 @@ function randomTap(): unknown {
|
||||
}
|
||||
|
||||
function randomSwipe(): unknown {
|
||||
const width = window.innerWidth || 320;
|
||||
const height = window.innerHeight || 480;
|
||||
const cx = Math.round(width / 2);
|
||||
const cy = Math.round(height / 2);
|
||||
const magnitude = 200 + Math.floor(Math.random() * 401);
|
||||
const direction = Math.floor(Math.random() * 4);
|
||||
let toX = cx;
|
||||
let toY = cy;
|
||||
if (direction === 0) toY = Math.max(0, cy - magnitude);
|
||||
else if (direction === 1) toY = cy + magnitude;
|
||||
else if (direction === 2) toX = Math.max(0, cx - magnitude);
|
||||
else toX = cx + magnitude;
|
||||
return {
|
||||
kind: "Swipe",
|
||||
from: { x: cx, y: cy },
|
||||
to: { x: toX, y: toY },
|
||||
durationMillis: 250,
|
||||
};
|
||||
// Why: web has no swipe gesture; pointer drags into empty divs are noise.
|
||||
return null;
|
||||
}
|
||||
|
||||
const WEB_PRESS_KEYS = ["enter", "tab", "escape", "up", "down", "left", "right"];
|
||||
|
||||
function randomPressKey(): unknown {
|
||||
// Why: only emit keys with meaningful browser semantics; "back"/"home" don't navigate.
|
||||
const key = WEB_PRESS_KEYS[Math.floor(Math.random() * WEB_PRESS_KEYS.length)];
|
||||
return { kind: "PressKey", key };
|
||||
}
|
||||
|
||||
function pickFromArray(value: unknown): unknown {
|
||||
|
||||
Reference in new issue
Block a user