@dloizides/game-e2e 1.4.1 → 1.5.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/dist/index.mjs CHANGED
@@ -901,6 +901,118 @@ ${renderWalk(results)}`);
901
901
  }
902
902
  }
903
903
 
904
- export { ANTI_ALIAS_TOLERANCE, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, EXACT, FIT_TIMEOUT_MS, GAME_SHELL_HEIGHT_VAR, HOOK_WALK_SIZES, MAX_REPORTED, MIN_TARGET_PX, PHONE_DEVICE, PHONE_SIZE, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, WALK_INPUTS, 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 };
904
+ // src/text-fit-report.ts
905
+ var TEXT_FIT_TOLERANCE_PX = 1;
906
+ function ownOverflow(r, tol) {
907
+ if (r.inline) {
908
+ return null;
909
+ }
910
+ const wide = r.scrollWidth - r.clientWidth;
911
+ const tall = r.scrollHeight - r.clientHeight;
912
+ if (wide > tol) {
913
+ return { name: r.name, text: r.text, why: "text wider than its box", px: wide };
914
+ }
915
+ if (tall > tol) {
916
+ return { name: r.name, text: r.text, why: "text taller than its box", px: tall };
917
+ }
918
+ return null;
919
+ }
920
+ function spill(r, tol) {
921
+ const px = Math.max(r.parentLeft - r.left, r.parentTop - r.top, r.right - r.parentRight, r.bottom - r.parentBottom);
922
+ return px > tol ? { name: r.name, text: r.text, why: "spills out of its parent", px: Math.round(px) } : null;
923
+ }
924
+ function textFitFindings(r, tol = TEXT_FIT_TOLERANCE_PX) {
925
+ return [ownOverflow(r, tol), spill(r, tol)].filter((f) => f !== null);
926
+ }
927
+ var renderFinding = (f) => `
928
+ ${f.name} "${f.text}": ${f.why} by ${String(f.px)}px`;
929
+ function summariseTextFit(states, where, tol = TEXT_FIT_TOLERANCE_PX) {
930
+ if (states.length === 0) {
931
+ return { problems: 1, message: `${where}: no UI state was measured at all` };
932
+ }
933
+ let problems = 0;
934
+ const lines = states.map((s) => {
935
+ if (s.readings.length === 0) {
936
+ problems += 1;
937
+ return `
938
+ ${s.state}: BLIND - no visible text element matched`;
939
+ }
940
+ const found = s.readings.flatMap((r) => textFitFindings(r, tol));
941
+ problems += found.length;
942
+ const head = found.length > 0 ? `${String(found.length)} overflow(s)` : "ok";
943
+ return `
944
+ ${s.state}: ${head} over ${String(s.readings.length)} text element(s)${found.map(renderFinding).join("")}`;
945
+ });
946
+ return { problems, message: `${where}: ${String(states.length)} state(s), ${String(problems)} problem(s)${lines.join("")}` };
947
+ }
948
+ var TEXT_FIT_SELECTOR = "body *";
949
+ async function readTextBoxes(page, selector = TEXT_FIT_SELECTOR) {
950
+ return page.evaluate((sel) => {
951
+ const display = (el) => getComputedStyle(el).display;
952
+ const ownText = (el) => [...el.childNodes].filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join("").trim();
953
+ const shown = (el) => {
954
+ const r = el.getBoundingClientRect();
955
+ return r.width > 0 && r.height > 0 && getComputedStyle(el).visibility !== "hidden" && el.closest('[aria-hidden="true"]') === null;
956
+ };
957
+ const scrolls = (el) => /auto|scroll/.test(getComputedStyle(el).overflowX + getComputedStyle(el).overflowY);
958
+ const container = (el) => {
959
+ let p = el.parentElement;
960
+ while (p && (display(p) === "inline" || display(p) === "contents")) {
961
+ p = p.parentElement;
962
+ }
963
+ return p;
964
+ };
965
+ const label = (el) => {
966
+ const id = el.id !== "" ? `#${el.id}` : "";
967
+ const cls = typeof el.className === "string" && el.className.trim() !== "" ? `.${el.className.trim().split(/\s+/).join(".")}` : "";
968
+ return `${el.tagName.toLowerCase()}${id}${cls}`;
969
+ };
970
+ const els = [...document.querySelectorAll(sel)].filter((el) => !(el instanceof SVGElement) && ownText(el) !== "" && shown(el));
971
+ return els.flatMap((el) => {
972
+ const parent = container(el);
973
+ if (!parent || parent === document.body || parent === document.documentElement || scrolls(parent)) {
974
+ return [];
975
+ }
976
+ const r = el.getBoundingClientRect();
977
+ const p = parent.getBoundingClientRect();
978
+ return [{
979
+ name: label(el),
980
+ text: ownText(el).slice(0, 40),
981
+ inline: display(el) === "inline",
982
+ clientWidth: el.clientWidth,
983
+ clientHeight: el.clientHeight,
984
+ scrollWidth: el.scrollWidth,
985
+ scrollHeight: el.scrollHeight,
986
+ left: r.left,
987
+ top: r.top,
988
+ right: r.right,
989
+ bottom: r.bottom,
990
+ parentLeft: p.left,
991
+ parentTop: p.top,
992
+ parentRight: p.right,
993
+ parentBottom: p.bottom
994
+ }];
995
+ });
996
+ }, selector);
997
+ }
998
+ async function measureTextFit(page, selector = TEXT_FIT_SELECTOR, states) {
999
+ if (!states || states.length === 0) {
1000
+ return [{ state: "current", readings: await readTextBoxes(page, selector) }];
1001
+ }
1002
+ const out = [];
1003
+ for (const s of states) {
1004
+ await s.enter(page);
1005
+ out.push({ state: s.name, readings: await readTextBoxes(page, selector) });
1006
+ }
1007
+ return out;
1008
+ }
1009
+ async function expectTextFits(page, selector = TEXT_FIT_SELECTOR, options = {}) {
1010
+ const measured = await measureTextFit(page, selector, options.states);
1011
+ const summary = summariseTextFit(measured, options.where ?? selector, options.tolerancePx ?? TEXT_FIT_TOLERANCE_PX);
1012
+ expect(summary.problems, summary.message).toBe(0);
1013
+ return measured;
1014
+ }
1015
+
1016
+ export { ANTI_ALIAS_TOLERANCE, CANVAS_TIMEOUT_MS, CONTROL_SELECTOR, DEFAULT_CANVAS_SELECTOR, DESKTOP_DEVICE, DESKTOP_SIZE, EXACT, FIT_TIMEOUT_MS, GAME_SHELL_HEIGHT_VAR, HOOK_WALK_SIZES, MAX_REPORTED, MIN_TARGET_PX, PHONE_DEVICE, PHONE_SIZE, RELAYOUT_TIMEOUT_MS, STUB_FRAMES, TEXT_FIT_SELECTOR, TEXT_FIT_TOLERANCE_PX, WALK_INPUTS, armVisibleHeight, auditRoute, auditTouchTargets, canvasBoxToPage, controlName, countDiff, desktop, deviceDescriptor, diffPngs, domControls, expectCanvasHeight, expectCanvasInside, expectFitTo, expectHookMenuWalkable, expectMenuWalkable, expectNoHorizontalOverflow, expectNoHorizontalOverflowAcrossRoutes, expectTextFits, expectTouchTargets, expectTouchTargetsAcrossRoutes, findOverlaps, findOverlapsWithin, gameProjects, horizontalOverflowPx, measureHorizontalOverflow, measureTextFit, overlaps, phone, readHorizontalOverflow, readTextBoxes, regionDiff, renderFindings, renderOverflow, renderRouteAudit, renderWalk, routeProblems, shrinkVisibleHeight, stubGamepad, summariseOverflow, summariseTextFit, summariseTouchTargets, textFitFindings, toOverflowReading, walkFailed, walkHookMenus, walkMenus };
905
1017
  //# sourceMappingURL=index.mjs.map
906
1018
  //# sourceMappingURL=index.mjs.map