@dloizides/game-e2e 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,52 +1,63 @@
1
- # Changelog
2
-
3
- All notable changes to `@dloizides/game-e2e` are documented here.
4
-
5
- ## 1.2.1
6
-
7
- - Listener lookup is one `Runtime.evaluate` (DevTools `getEventListeners`) instead of two CDP calls per element. The
8
- per-element calls slowed the walk enough that a screen re-rendering on a late fetch (Surge `stagePreview`) went red.
9
-
10
- ## 1.2.0
11
-
12
- NAV-1 "Every game menu works with arrow keys and controller", walker gap:
13
-
14
- - The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
15
- (`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
16
- with such a handler that is not focusable is reported `unreached`.
17
- - Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
18
- the attribute and properties are checked, and each result carries a `notes` line saying so.
19
- - Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
20
- menu container does not flag the container or its children. When nested elements are both flagged, only the
21
- innermost is reported.
22
- - `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
23
-
24
- ## 1.1.0
25
-
26
- NAV-1 "Every game menu works with arrow keys and controller", phase 1:
27
-
28
- - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
29
- by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
30
- opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
31
- Exemptions take a selector and a printed reason.
32
- - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
33
- - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
34
- - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
35
-
36
- ## 1.0.0
37
-
38
- First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
39
- strictest behaviour of the three:
40
-
41
- - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
42
- mobile UA, isMobile on the phone), resized; never a bare viewport.
43
- - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
44
- every active Phaser scene to re-create and throws when the global is missing.
45
- - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
46
- configurable canvas selector.
47
- - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
48
- - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
49
- `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
50
- - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
51
- - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
52
- gate, measured against the narrower of visualViewport width and clientWidth.
1
+ # Changelog
2
+
3
+ All notable changes to `@dloizides/game-e2e` are documented here.
4
+
5
+ ## 1.3.0
6
+
7
+ NAV-1 "Every game menu works with arrow keys and controller", phase 4 (canvas menus):
8
+
9
+ - `expectHookMenuWalkable(page, { screens, open, via?, sizes? })` / `walkHookMenus`: walks menus drawn on a canvas
10
+ (Phaser, Babylon GUI) through the `window.__menuWalk` hook (`MenuWalkHook` from `@dloizides/game-input` 1.6.0).
11
+ Per screen, at phone (360x640) and desktop (1280x720) viewports, by arrow keys and the stubbed pad: learns every
12
+ focus transition until no direction is left untried, fails naming each unreached item. `activates: { item, to }`
13
+ checks Enter / A opens a screen; Escape / B must leave the screen unless `leaves: false`.
14
+ - Arrow/pad driver moved to `menu-walk-driver.ts`, shared by the DOM and hook walkers (adds Enter / A `activate`).
15
+
16
+ ## 1.2.1
17
+
18
+ - Listener lookup is one `Runtime.evaluate` (DevTools `getEventListeners`) instead of two CDP calls per element. The
19
+ per-element calls slowed the walk enough that a screen re-rendering on a late fetch (Surge `stagePreview`) went red.
20
+
21
+ ## 1.2.0
22
+
23
+ NAV-1 "Every game menu works with arrow keys and controller", walker gap:
24
+
25
+ - The walker now finds pointer-only items whose click / pointerdown / pointerup handler is set as a property
26
+ (`el.onclick = ...`) or added with `addEventListener`, not only the `[onclick]` attribute. A visible element
27
+ with such a handler that is not focusable is reported `unreached`.
28
+ - Listeners are read through CDP `DOMDebugger.getEventListeners` (Chromium). Without CDP (Firefox, WebKit) only
29
+ the attribute and properties are checked, and each result carries a `notes` line saying so.
30
+ - Delegation: an element that contains a walk control, or sits inside one, is never flagged, so a listener on a
31
+ menu container does not flag the container or its children. When nested elements are both flagged, only the
32
+ innermost is reported.
33
+ - `WalkResult.notes` (new, printed as `note:` by `renderWalk`).
34
+
35
+ ## 1.1.0
36
+
37
+ NAV-1 "Every game menu works with arrow keys and controller", phase 1:
38
+
39
+ - `walkMenus()` / `expectMenuWalkable()`: open each screen, walk every focusable control by arrow keys and
40
+ by a stubbed gamepad (breadth-first from the focused control), report unreached controls, a dialog that
41
+ opens without focus inside it, sliders that ignore Left/Right, and Escape / B that does not close a dialog.
42
+ Exemptions take a selector and a printed reason.
43
+ - `stubGamepad()`: a `navigator.getGamepads()` stand-in driven from the test (`PadDriver.press`).
44
+ - `renderWalk()`, `walkFailed()`, `WALK_INPUTS`.
45
+ - Depends on `@dloizides/game-input` ^1.5.1 for the shared focusable and dialog selectors.
46
+
47
+ ## 1.0.0
48
+
49
+ First release. Playwright helpers that Aurora, Surge and Morphe each carried a copy of, unified on the
50
+ strictest behaviour of the three:
51
+
52
+ - `phone()` / `desktop()` / `gameProjects()`: Galaxy S5 and Desktop Chrome device descriptors (touch,
53
+ mobile UA, isMobile on the phone), resized; never a bare viewport.
54
+ - `armVisibleHeight()` / `shrinkVisibleHeight()`: a simulated browser toolbar. `relayoutGlobal` waits for
55
+ every active Phaser scene to re-create and throws when the global is missing.
56
+ - `expectFitTo()`, `expectCanvasHeight()`, `expectCanvasInside()`: game-shell fit assertions with a
57
+ configurable canvas selector.
58
+ - `domControls()`, `overlaps()`, `findOverlaps()`, `findOverlapsWithin()`, `canvasBoxToPage()`.
59
+ - `diffPngs()` / `regionDiff()` / `countDiff()`: exact by default (tolerance 0, sizes must match);
60
+ `ANTI_ALIAS_TOLERANCE` (48) and `width`/`height` opt into Surge's tolerant, scaled comparison.
61
+ - `auditTouchTargets()` + `expectTouchTargets(AcrossRoutes)()`: the 44x44 hit-box gate.
62
+ - `readHorizontalOverflow()` + `expectNoHorizontalOverflow(AcrossRoutes)()`: the no-horizontal-scroll
63
+ gate, measured against the narrower of visualViewport width and clientWidth.
package/dist/index.d.mts CHANGED
@@ -256,4 +256,32 @@ declare const STUB_FRAMES = 3;
256
256
  /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
257
  declare function stubGamepad(page: Page): Promise<PadDriver>;
258
258
 
259
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
259
+ interface HookScreen {
260
+ name: string;
261
+ /** Items deliberately not walkable, each with a reason (printed in the report). */
262
+ exempt?: ReadonlyArray<{
263
+ item: string;
264
+ reason: string;
265
+ }>;
266
+ /** Escape / B must leave the screen. Default true; false for a root screen with nowhere to go. */
267
+ leaves?: boolean;
268
+ /** Enter / A on `item` must open screen `to`. */
269
+ activates?: {
270
+ item: string;
271
+ to: string;
272
+ };
273
+ }
274
+ interface HookWalkOptions {
275
+ screens: ReadonlyArray<string | HookScreen>;
276
+ /** Loads the page fresh (page.goto, so the pad stub applies) and opens the named screen. */
277
+ open: (page: Page, screen: string) => Promise<void>;
278
+ via?: readonly WalkInput[];
279
+ sizes?: ReadonlyArray<readonly [string, Size]>;
280
+ }
281
+ declare const HOOK_WALK_SIZES: ReadonlyArray<readonly [string, Size]>;
282
+ /** Walks each hook screen at each size by keys and stubbed pad; one result per screen, size and input. */
283
+ declare function walkHookMenus(page: Page, opts: HookWalkOptions): Promise<WalkResult[]>;
284
+ /** NAV-1 gate for canvas menus: throws, naming every unreached item and problem, unless all screens walk. */
285
+ declare function expectHookMenuWalkable(page: Page, opts: HookWalkOptions): Promise<void>;
286
+
287
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, HOOK_WALK_SIZES, type HookScreen, type HookWalkOptions, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
package/dist/index.d.ts CHANGED
@@ -256,4 +256,32 @@ declare const STUB_FRAMES = 3;
256
256
  /** Replaces navigator.getGamepads with one standard pad (call before the page loads); returns its driver. */
257
257
  declare function stubGamepad(page: Page): Promise<PadDriver>;
258
258
 
259
- export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkMenus };
259
+ interface HookScreen {
260
+ name: string;
261
+ /** Items deliberately not walkable, each with a reason (printed in the report). */
262
+ exempt?: ReadonlyArray<{
263
+ item: string;
264
+ reason: string;
265
+ }>;
266
+ /** Escape / B must leave the screen. Default true; false for a root screen with nowhere to go. */
267
+ leaves?: boolean;
268
+ /** Enter / A on `item` must open screen `to`. */
269
+ activates?: {
270
+ item: string;
271
+ to: string;
272
+ };
273
+ }
274
+ interface HookWalkOptions {
275
+ screens: ReadonlyArray<string | HookScreen>;
276
+ /** Loads the page fresh (page.goto, so the pad stub applies) and opens the named screen. */
277
+ open: (page: Page, screen: string) => Promise<void>;
278
+ via?: readonly WalkInput[];
279
+ sizes?: ReadonlyArray<readonly [string, Size]>;
280
+ }
281
+ declare const HOOK_WALK_SIZES: ReadonlyArray<readonly [string, Size]>;
282
+ /** Walks each hook screen at each size by keys and stubbed pad; one result per screen, size and input. */
283
+ declare function walkHookMenus(page: Page, opts: HookWalkOptions): Promise<WalkResult[]>;
284
+ /** NAV-1 gate for canvas menus: throws, naming every unreached item and problem, unless all screens walk. */
285
+ declare function expectHookMenuWalkable(page: Page, opts: HookWalkOptions): Promise<void>;
286
+
287
+ export { ANTI_ALIAS_TOLERANCE, type Band, type Box, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, type CanvasFrame, type CanvasOptions, type ControlIdentity, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, type DiffOptions, type DiffResult, EXACT, FIT_TIMEOUT_MS, type FitOptions, GAME_SHELL_HEIGHT_VAR, type GameProject, type GameProjectsOptions, type GateSummary, HOOK_WALK_SIZES, type HookScreen, type HookWalkOptions, MAX_REPORTED, MIN_TARGET_PX, type OverflowMetrics, type OverflowReading, PHONE_DEVICE, PHONE_SIZE, type PadDriver, type PageFactory, RELAYOUT_TIMEOUT_MS, type Rect, type Region, type RegionInput, type RouteAudit, type RouteOverflow, STUB_FRAMES, type ShrinkOptions, type Size, type TargetAudit, type TargetFinding, type TargetProbeFunnel, WALK_INPUTS, type WalkInput, type WalkOptions, type WalkResult, type WalkScreen, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, overlaps, phone, readHorizontalOverflow, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTouchTargets, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
package/dist/index.js CHANGED
@@ -505,6 +505,30 @@ async function stubGamepad(page) {
505
505
  };
506
506
  }
507
507
 
508
+ // src/menu-walk-report.ts
509
+ var WALK_INPUTS = { keys: "keys", pad: "pad" };
510
+ var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
511
+ function renderWalk(results) {
512
+ return results.map((r) => [
513
+ `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
514
+ ...r.unreached.map((n) => ` unreached: ${n}`),
515
+ ...r.problems.map((p) => ` problem: ${p}`),
516
+ ...r.exempt.map((e) => ` exempt: ${e}`),
517
+ ...r.notes.map((n) => ` note: ${n}`)
518
+ ].join("\n")).join("\n");
519
+ }
520
+
521
+ // src/menu-walk-driver.ts
522
+ var DIRS = ["up", "down", "left", "right"];
523
+ var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
524
+ var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
525
+ function driverFor(page, via, pad) {
526
+ if (via === WALK_INPUTS.pad && pad !== null) {
527
+ return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east), activate: () => pad.press(gameInput.STANDARD_BUTTON.south) };
528
+ }
529
+ return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape"), activate: () => page.keyboard.press("Enter") };
530
+ }
531
+
508
532
  // src/menu-walk-listeners.ts
509
533
  var POINTER_EVENTS = ["click", "pointerdown", "pointerup"];
510
534
  var NO_CDP_NOTE = "CDP unavailable (not Chromium): click/pointer listeners added with addEventListener were not checked; only [onclick] and handler properties were";
@@ -584,33 +608,11 @@ function rootOpen(rootAttr) {
584
608
  return r !== null && r.getClientRects().length > 0 && r.closest("[hidden]") === null;
585
609
  }
586
610
 
587
- // src/menu-walk-report.ts
588
- var WALK_INPUTS = { keys: "keys", pad: "pad" };
589
- var walkFailed = (r) => r.unreached.length > 0 || r.problems.length > 0;
590
- function renderWalk(results) {
591
- return results.map((r) => [
592
- `${r.screen} [${r.via}] reached ${r.reached}/${r.total}`,
593
- ...r.unreached.map((n) => ` unreached: ${n}`),
594
- ...r.problems.map((p) => ` problem: ${p}`),
595
- ...r.exempt.map((e) => ` exempt: ${e}`),
596
- ...r.notes.map((n) => ` note: ${n}`)
597
- ].join("\n")).join("\n");
598
- }
599
-
600
611
  // src/menu-walk.ts
601
612
  var WALK_ATTR = "data-walk-id";
602
613
  var ROOT_ATTR = "data-walk-root";
603
614
  var PROBE_ATTR = "data-walk-probe";
604
615
  var PRESSES_PER_CONTROL = 4;
605
- var DIRS = ["up", "down", "left", "right"];
606
- var KEYS = { up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight" };
607
- var PAD_BUTTONS = { up: gameInput.STANDARD_BUTTON.dpadUp, down: gameInput.STANDARD_BUTTON.dpadDown, left: gameInput.STANDARD_BUTTON.dpadLeft, right: gameInput.STANDARD_BUTTON.dpadRight };
608
- function driverFor(page, via, pad) {
609
- if (via === WALK_INPUTS.pad && pad !== null) {
610
- return { dir: (d) => pad.press(PAD_BUTTONS[d]), back: () => pad.press(gameInput.STANDARD_BUTTON.east) };
611
- }
612
- return { dir: (d) => page.keyboard.press(KEYS[d]), back: () => page.keyboard.press("Escape") };
613
- }
614
616
  var active = (page) => page.evaluate(activeWalkId, WALK_ATTR);
615
617
  var focusId = (page, id) => page.evaluate(focusWalkId, [WALK_ATTR, id]);
616
618
  async function bfs(page, driver, total) {
@@ -695,6 +697,184 @@ ${renderWalk(results)}`);
695
697
  }
696
698
  }
697
699
 
700
+ // src/menu-walk-graph.ts
701
+ var PRESSES_PER_ITEM = 16;
702
+ function shortestPath(edges, from, to) {
703
+ if (from === null) {
704
+ return null;
705
+ }
706
+ const prev = /* @__PURE__ */ new Map([[from, []]]);
707
+ const queue = [from];
708
+ while (queue.length > 0) {
709
+ const at2 = queue.shift();
710
+ const steps = prev.get(at2);
711
+ if (at2 === to) {
712
+ return steps;
713
+ }
714
+ for (const [d, next] of edges.get(at2) ?? []) {
715
+ if (next !== null && !prev.has(next)) {
716
+ prev.set(next, [...steps, d]);
717
+ queue.push(next);
718
+ }
719
+ }
720
+ }
721
+ return null;
722
+ }
723
+ function pendingDir(edges, node) {
724
+ const out = edges.get(node);
725
+ return out === void 0 ? void 0 : DIRS.find((x) => !out.has(x));
726
+ }
727
+ function nextUnexplored(edges, cur) {
728
+ const seen = new Set(cur === null ? [] : [cur]);
729
+ const queue = cur === null ? [] : [cur];
730
+ while (queue.length > 0) {
731
+ const at2 = queue.shift();
732
+ const d = pendingDir(edges, at2);
733
+ if (d !== void 0) {
734
+ return [at2, d];
735
+ }
736
+ for (const next of edges.get(at2)?.values() ?? []) {
737
+ if (next !== null && !seen.has(next)) {
738
+ seen.add(next);
739
+ queue.push(next);
740
+ }
741
+ }
742
+ }
743
+ for (const node of edges.keys()) {
744
+ const d = pendingDir(edges, node);
745
+ if (d !== void 0) {
746
+ return [node, d];
747
+ }
748
+ }
749
+ return null;
750
+ }
751
+ async function travel(m, edges, cur, node) {
752
+ let at2 = cur;
753
+ let steps = shortestPath(edges, at2, node);
754
+ if (steps === null) {
755
+ at2 = await m.reset();
756
+ steps = shortestPath(edges, at2, node) ?? [];
757
+ }
758
+ for (const d of steps) {
759
+ at2 = await m.press(d);
760
+ }
761
+ return at2;
762
+ }
763
+ async function exploreFocus(m, itemCount) {
764
+ const edges = /* @__PURE__ */ new Map();
765
+ let cur = await m.reset();
766
+ if (cur === null) {
767
+ cur = await m.press("down");
768
+ }
769
+ if (cur !== null) {
770
+ edges.set(cur, /* @__PURE__ */ new Map());
771
+ }
772
+ let budget = PRESSES_PER_ITEM * Math.max(itemCount, 1);
773
+ for (let next = nextUnexplored(edges, cur); next !== null && budget > 0; next = nextUnexplored(edges, cur)) {
774
+ const [node, d] = next;
775
+ const out = edges.get(node);
776
+ cur = await travel(m, edges, cur, node);
777
+ budget -= 1;
778
+ if (cur !== node) {
779
+ out.set(d, null);
780
+ continue;
781
+ }
782
+ cur = await m.press(d);
783
+ out.set(d, cur);
784
+ if (cur !== null && !edges.has(cur)) {
785
+ edges.set(cur, /* @__PURE__ */ new Map());
786
+ }
787
+ }
788
+ return { reached: new Set(edges.keys()), path: (from, to) => shortestPath(edges, from, to) };
789
+ }
790
+
791
+ // src/menu-walk-hook.ts
792
+ var HOOK_WALK_SIZES = [["phone", PHONE_SIZE], ["desktop", DESKTOP_SIZE]];
793
+ function readHook(name) {
794
+ const hook = window[name];
795
+ return hook === void 0 ? null : { screen: hook.screen(), items: hook.items(), focused: hook.focused() };
796
+ }
797
+ var read = (page) => page.evaluate(readHook, gameInput.MENU_WALK_HOOK);
798
+ async function reopen(w) {
799
+ await w.opts.open(w.page, w.screen.name);
800
+ return read(w.page);
801
+ }
802
+ function machine(w) {
803
+ return {
804
+ press: async (d) => {
805
+ await w.driver.dir(d);
806
+ return (await read(w.page))?.focused ?? null;
807
+ },
808
+ reset: async () => (await reopen(w))?.focused ?? null
809
+ };
810
+ }
811
+ async function activationProblem(w, graph, target) {
812
+ const steps = graph.path((await reopen(w))?.focused ?? null, target.item);
813
+ if (steps === null) {
814
+ return `cannot reach ${target.item} to activate it`;
815
+ }
816
+ for (const d of steps) {
817
+ await w.driver.dir(d);
818
+ }
819
+ await w.driver.activate();
820
+ const landed = (await read(w.page))?.screen;
821
+ const key = w.via === WALK_INPUTS.pad ? "A" : "Enter";
822
+ return landed === target.to ? null : `${key} on ${target.item} opens "${String(landed)}", expected "${target.to}"`;
823
+ }
824
+ async function actionProblems(w, graph) {
825
+ const problems = [];
826
+ const target = w.screen.activates;
827
+ const activation = target === void 0 ? null : await activationProblem(w, graph, target);
828
+ if (activation !== null) {
829
+ problems.push(activation);
830
+ }
831
+ if (w.screen.leaves !== false) {
832
+ await reopen(w);
833
+ await w.driver.back();
834
+ const key = w.via === WALK_INPUTS.pad ? "B" : "Escape";
835
+ if ((await read(w.page))?.screen === w.screen.name) {
836
+ problems.push(`${key} does not leave ${w.screen.name}`);
837
+ }
838
+ }
839
+ return problems;
840
+ }
841
+ async function walkHookScreen(w, size) {
842
+ const exempt = w.screen.exempt ?? [];
843
+ const base = { screen: `${w.screen.name} @${size}`, via: w.via, exempt: exempt.map((e) => `${e.item}: ${e.reason}`), notes: [] };
844
+ const first = await reopen(w);
845
+ if (first === null) {
846
+ return { ...base, reached: 0, total: 0, unreached: [], problems: [`window.${gameInput.MENU_WALK_HOOK} is not installed`] };
847
+ }
848
+ const problems = first.screen === w.screen.name ? [] : [`open landed on screen "${first.screen}"`];
849
+ const items = first.items.filter((i) => !exempt.some((e) => e.item === i));
850
+ const graph = await exploreFocus(machine(w), first.items.length);
851
+ const unreached = items.filter((i) => !graph.reached.has(i));
852
+ problems.push(...await actionProblems(w, graph));
853
+ return { ...base, reached: items.length - unreached.length, total: items.length, unreached, problems };
854
+ }
855
+ async function walkHookMenus(page, opts) {
856
+ const via = opts.via ?? [WALK_INPUTS.keys, WALK_INPUTS.pad];
857
+ const pad = via.includes(WALK_INPUTS.pad) ? await stubGamepad(page) : null;
858
+ const results = [];
859
+ for (const [label, size] of opts.sizes ?? HOOK_WALK_SIZES) {
860
+ await page.setViewportSize(size);
861
+ for (const s of opts.screens) {
862
+ const screen = typeof s === "string" ? { name: s } : s;
863
+ for (const v of via) {
864
+ results.push(await walkHookScreen({ page, opts, screen, driver: driverFor(page, v, pad), via: v }, label));
865
+ }
866
+ }
867
+ }
868
+ return results;
869
+ }
870
+ async function expectHookMenuWalkable(page, opts) {
871
+ const results = await walkHookMenus(page, opts);
872
+ if (results.some(walkFailed)) {
873
+ throw new Error(`Canvas menus not walkable by arrow keys / pad:
874
+ ${renderWalk(results)}`);
875
+ }
876
+ }
877
+
698
878
  exports.ANTI_ALIAS_TOLERANCE = ANTI_ALIAS_TOLERANCE;
699
879
  exports.CANVAS_TIMEOUT_MS = CANVAS_TIMEOUT_MS;
700
880
  exports.CONTROL_SELECTOR = CONTROL_SELECTOR;
@@ -704,6 +884,7 @@ exports.DESKTOP_SIZE = DESKTOP_SIZE;
704
884
  exports.EXACT = EXACT;
705
885
  exports.FIT_TIMEOUT_MS = FIT_TIMEOUT_MS;
706
886
  exports.GAME_SHELL_HEIGHT_VAR = GAME_SHELL_HEIGHT_VAR;
887
+ exports.HOOK_WALK_SIZES = HOOK_WALK_SIZES;
707
888
  exports.MAX_REPORTED = MAX_REPORTED;
708
889
  exports.MIN_TARGET_PX = MIN_TARGET_PX;
709
890
  exports.PHONE_DEVICE = PHONE_DEVICE;
@@ -724,6 +905,7 @@ exports.domControls = domControls;
724
905
  exports.expectCanvasHeight = expectCanvasHeight;
725
906
  exports.expectCanvasInside = expectCanvasInside;
726
907
  exports.expectFitTo = expectFitTo;
908
+ exports.expectHookMenuWalkable = expectHookMenuWalkable;
727
909
  exports.expectMenuWalkable = expectMenuWalkable;
728
910
  exports.expectNoHorizontalOverflow = expectNoHorizontalOverflow;
729
911
  exports.expectNoHorizontalOverflowAcrossRoutes = expectNoHorizontalOverflowAcrossRoutes;
@@ -749,6 +931,7 @@ exports.summariseOverflow = summariseOverflow;
749
931
  exports.summariseTouchTargets = summariseTouchTargets;
750
932
  exports.toOverflowReading = toOverflowReading;
751
933
  exports.walkFailed = walkFailed;
934
+ exports.walkHookMenus = walkHookMenus;
752
935
  exports.walkMenus = walkMenus;
753
936
  //# sourceMappingURL=index.js.map
754
937
  //# sourceMappingURL=index.js.map