@krizaka/page-audit 0.6.0 → 0.7.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/README.md CHANGED
@@ -25,7 +25,7 @@ Opt-in through `checks` (nothing changes for a repo that does not ask): `status`
25
25
  (the signed-in frame, `[data-app-frame-slot]`, forces a scroll), `minAction` (a button-styled action under N px), `boxes` (a landmark
26
26
  wider than its box), `landmarks` (`"public"` one footer naming Krizaka and a nav, `"app"`, `"auth"`), `pictures`, `emptyControls`,
27
27
  `hardColors`, `maps` (an empty map, akinaza#488: a GL / Leaflet / `[data-kz-map]` box under 120 px on a side, a GL map with no canvas,
28
- a Leaflet map with no loaded tile; `maps: { required: true }` also fails a page that should draw one but has none). Console noise the app tolerates: `ignoreConsole: [/…/]` (`[]` counts every error); `attempts` retries a route.
28
+ a Leaflet map with no loaded tile; `maps: { required: true }` also fails a page that should draw one but has none), `controlOverlaps` (two interactive elements that share pixels on screen, one not inside the other — akinaza#214: the composer's title over a row). Console noise the app tolerates: `ignoreConsole: [/…/]` (`[]` counts every error); `attempts` retries a route.
29
29
 
30
30
  ```js
31
31
  const routes = await routesFromSitemap(base, { first: ["/", "/docs"], limit: 14 }); // a crawl as the route source (null: nothing answers)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krizaka/page-audit",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "The page audit of every Krizaka app, in one place: HTTP status, empty main, horizontal overflow, a card out of its panel, sections covering each other, a column cut off, top chrome overlaps, unnamed buttons, empty headings. Runs in a real browser (Playwright) over a route list, viewports and themes, with View Transitions neutralised and a self-test on its own fixtures.",
5
5
  "keywords": [
6
6
  "krizaka",
@@ -65,7 +65,7 @@
65
65
  "eslint": "^9.39.0",
66
66
  "playwright-core": "^1.55.0",
67
67
  "vitest": "^4.1.11",
68
- "@krizaka/config": "^0.18.0"
68
+ "@krizaka/config": "^0.19.0"
69
69
  },
70
70
  "engines": {
71
71
  "node": ">=22"
package/src/fixtures.mjs CHANGED
@@ -76,3 +76,12 @@ export const MAP_NO_CANVAS = page(
76
76
  );
77
77
  /** A map that is not drawn (display none: a closed tab, a small screen): nothing to measure. */
78
78
  export const MAP_HIDDEN = page(`<section><div class="maplibregl-map" style="display:none"></div></section>`);
79
+
80
+ /** Two controls on top of each other: a title button over a row's button (akinaza#214, the composer's « Style » over « Réservation »). */
81
+ export const CONTROLS_OVERLAP = page(
82
+ `<button style="display:block;width:200px;height:40px">Réservation</button><button style="display:block;width:200px;height:40px;margin-top:-20px;position:relative">Style</button>`,
83
+ );
84
+ /** Controls that sit side by side, a control inside a label, a hidden checkbox and a control scrolled out of its list: none overlaps. */
85
+ export const CONTROLS_FINE = page(
86
+ `<div style="display:flex;gap:8px"><button style="width:100px;height:40px">A</button><button style="width:100px;height:40px">B</button></div><label style="display:block"><input type="checkbox"> Remember</label><div style="height:60px;overflow:auto"><button style="display:block;width:100px;height:40px">1</button><button style="display:block;width:100px;height:40px">2</button><button style="display:block;width:100px;height:40px">3</button></div><button style="display:block;width:100px;height:40px;margin-top:8px">After</button>`,
87
+ );
package/src/index.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface ProblemChecks {
21
21
  hardColors?: boolean;
22
22
  /** Empty maps (a GL / Leaflet / `[data-kz-map]` box under 120 px, no canvas, no loaded tile); `{ min, required }` to tune, `required` fails a page with no map. */
23
23
  maps?: boolean | { min?: number; required?: boolean };
24
+ /** Two interactive elements (buttons, links, inputs, radios…) that share pixels on screen, one not inside the other: one of them cannot be clicked. The box is cut by clipping and scrolling ancestors. */
25
+ controlOverlaps?: boolean;
24
26
  }
25
27
  export function problemsOf(where: string, result: Record<string, unknown>, checks?: ProblemChecks): string[];
26
28
  export function auditOptions<T extends object>(options?: T): T & { reducedMotion: "reduce" };
@@ -117,6 +117,42 @@ function spillOf(panels) {
117
117
  return { overflowing, spill };
118
118
  }
119
119
 
120
+ /** What is seen of a control: its box cut by every clipping or scrolling ancestor (a control scrolled out of its list is not on screen). */
121
+ function seenBox(el) {
122
+ const r = el.getBoundingClientRect();
123
+ let box = { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
124
+ for (let n = el.parentElement; n && n !== document.body; n = n.parentElement) {
125
+ const st = getComputedStyle(n);
126
+ if (st.overflowX === "visible" && st.overflowY === "visible") continue;
127
+ const c = n.getBoundingClientRect();
128
+ box = {
129
+ left: Math.max(box.left, st.overflowX === "visible" ? box.left : c.left),
130
+ right: Math.min(box.right, st.overflowX === "visible" ? box.right : c.right),
131
+ top: Math.max(box.top, st.overflowY === "visible" ? box.top : c.top),
132
+ bottom: Math.min(box.bottom, st.overflowY === "visible" ? box.bottom : c.bottom),
133
+ };
134
+ }
135
+ return box;
136
+ }
137
+
138
+ /** `controlOverlaps`: two interactive elements, neither inside the other, that share pixels on screen (a header over a row, a radio over its card's text): one of them cannot be clicked. */
139
+ function controlOverlapsOf() {
140
+ const controls =
141
+ 'button, a[href], input:not([type="hidden"]), select, textarea, summary, [role="button"], [role="radio"], [role="checkbox"], [role="switch"], [role="tab"], [role="menuitem"], [role="link"], [role="combobox"]';
142
+ const drawn = [...document.querySelectorAll(controls)]
143
+ .filter(
144
+ (el) => !clipped(el) && getComputedStyle(el).visibility !== "hidden" && getComputedStyle(el).display !== "none",
145
+ )
146
+ .map((el) => ({ el, box: seenBox(el) }))
147
+ .filter(({ box }) => box.right - box.left > 4 && box.bottom - box.top > 4);
148
+ const overlaps = [];
149
+ drawn.forEach((a, i) => {
150
+ for (const b of drawn.slice(i + 1))
151
+ if (apart(a.el, b.el) && meets(a.box, b.box)) overlaps.push(nameOf(a.el) + " over " + nameOf(b.el));
152
+ });
153
+ return overlaps;
154
+ }
155
+
120
156
  /** `overlaps`: two sections that are not nested and cover each other, or what ran out of its panel and lands on another section (the card covering « Dernières vérifications »). */
121
157
  function overlapsOf(panels, spill) {
122
158
  const overlaps = [];
@@ -389,6 +425,7 @@ function measurePage() {
389
425
  overlaps: overlapsOf(panels, spill).slice(0, 3),
390
426
  cutColumns: cutColumnsOf(),
391
427
  chromeOverlaps: chromeOverlapsOf(doc).slice(0, 3),
428
+ controlOverlaps: controlOverlapsOf().slice(0, 5),
392
429
  clips: clipsOf(),
393
430
  emptyHeadings: emptyHeadingsOf(),
394
431
  unlabelledFiles: unlabelledFilesOf(),
@@ -424,6 +461,8 @@ const PROBES = [
424
461
  notDrawn,
425
462
  runsOut,
426
463
  spillOf,
464
+ seenBox,
465
+ controlOverlapsOf,
427
466
  overlapsOf,
428
467
  cutBy,
429
468
  cutColumnsOf,
@@ -461,41 +500,51 @@ function accessibilityProblems(where, result, fileLabels) {
461
500
  return problems;
462
501
  }
463
502
 
503
+ /**
504
+ * The checks switched on by a flag of `problemsOf` (a flag that is off produces nothing). A table keeps the function short: each
505
+ * entry reads the page's result and says what the flag asks for.
506
+ */
507
+ const FLAGGED_CHECKS = [
508
+ ["emptyMain", (where, result) => (result.emptyMain ? [`${where}: empty <main>`] : [])],
509
+ ["frame", (where, result) => frameProblems(where, result.frame)],
510
+ ["minAction", (where, result, minAction) => actionProblems(where, result.actions ?? [], minAction)],
511
+ ["boxes", (where, result) => boxProblems(where, result.boxes ?? [])],
512
+ ["landmarks", (where, result, landmarks) => landmarkProblems(where, result.landmarks, landmarks)],
513
+ [
514
+ "pictures",
515
+ (where, result) =>
516
+ result.brokenPictures?.length ? [`${where}: broken picture ${result.brokenPictures.join(", ")}`] : [],
517
+ ],
518
+ ["emptyControls", (where, result) => (result.emptyControls ?? []).map((c) => `${where}: ${c}`)],
519
+ [
520
+ "hardColors",
521
+ (where, result) =>
522
+ result.hardColors
523
+ ? [`${where}: ${result.hardColors} element(s) with a hard-coded colour in an inline style`]
524
+ : [],
525
+ ],
526
+ ["maps", (where, result, maps) => mapProblems(where, result.maps ?? [], maps)],
527
+ [
528
+ "controlOverlaps",
529
+ (where, result) =>
530
+ result.controlOverlaps?.length
531
+ ? [`${where}: controls overlap, one cannot be clicked (${result.controlOverlaps.join(", ")})`]
532
+ : [],
533
+ ],
534
+ ];
535
+
536
+ function flaggedProblems(where, result, flags) {
537
+ return FLAGGED_CHECKS.flatMap(([flag, check]) => (flags[flag] ? check(where, result, flags[flag]) : []));
538
+ }
539
+
464
540
  export function problemsOf(
465
541
  where,
466
542
  result,
467
- {
468
- errors = [],
469
- h1 = false,
470
- headerAction = false,
471
- fileLabels = false,
472
- status,
473
- emptyMain = false,
474
- frame = false,
475
- minAction,
476
- boxes = false,
477
- landmarks,
478
- pictures = false,
479
- emptyControls = false,
480
- hardColors = false,
481
- maps = false,
482
- } = {},
543
+ { errors = [], h1 = false, headerAction = false, fileLabels = false, status, ...flags } = {},
483
544
  ) {
484
545
  return [
485
546
  ...statusProblems(where, status),
486
- ...(emptyMain && result.emptyMain ? [`${where}: empty <main>`] : []),
487
- ...(frame ? frameProblems(where, result.frame) : []),
488
- ...(minAction ? actionProblems(where, result.actions ?? [], minAction) : []),
489
- ...(boxes ? boxProblems(where, result.boxes ?? []) : []),
490
- ...(landmarks ? landmarkProblems(where, result.landmarks, landmarks) : []),
491
- ...(pictures && result.brokenPictures?.length
492
- ? [`${where}: broken picture ${result.brokenPictures.join(", ")}`]
493
- : []),
494
- ...(emptyControls ? (result.emptyControls ?? []).map((c) => `${where}: ${c}`) : []),
495
- ...(hardColors && result.hardColors
496
- ? [`${where}: ${result.hardColors} element(s) with a hard-coded colour in an inline style`]
497
- : []),
498
- ...(maps ? mapProblems(where, result.maps ?? [], maps) : []),
547
+ ...flaggedProblems(where, result, flags),
499
548
  ...errorsOf(where, errors),
500
549
  ...layoutProblems(where, result),
501
550
  ...(h1 ? namingProblems(where, result) : []),
package/src/self-test.mjs CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  CHROME_BAD,
8
8
  CHROME_FINE,
9
9
  COLUMN_CUT,
10
+ CONTROLS_FINE,
11
+ CONTROLS_OVERLAP,
10
12
  EMPTY_MAIN,
11
13
  FINE,
12
14
  FOLDED_SECTION,
@@ -42,6 +44,12 @@ const EXPECT = [
42
44
  ["a map with no canvas", MAP_NO_CANVAS, /has no canvas/, { maps: true }],
43
45
  ["no map where one is required", FINE, /no map on the page/, { maps: { required: true } }],
44
46
  ["two page footers and no nav", CHROME_BAD, /2 page footers/, { landmarks: "public" }],
47
+ [
48
+ "two controls on top of each other",
49
+ CONTROLS_OVERLAP,
50
+ /controls overlap, one cannot be clicked/,
51
+ { controlOverlaps: true },
52
+ ],
45
53
  ["no nav landmark", CHROME_BAD, /no <nav> landmark/, { landmarks: "app" }],
46
54
  ];
47
55
  const FINES = [
@@ -61,11 +69,13 @@ const ALL = {
61
69
  hardColors: true,
62
70
  landmarks: "public",
63
71
  maps: true,
72
+ controlOverlaps: true,
64
73
  };
65
74
  const FINES_STRICT = [
66
75
  ["a frame that fits its screen", FRAME_FITS, { frame: true, emptyMain: false }],
67
76
  ["the family chrome", CHROME_FINE, ALL],
68
77
  ["maps with a size and something drawn", MAP_FINE, { maps: true }],
78
+ ["controls side by side, in a label, in a scroller", CONTROLS_FINE, { controlOverlaps: true }],
69
79
  ["a map that is not drawn (display none)", MAP_HIDDEN, { maps: true }],
70
80
  ];
71
81