@booki-aui/readiness 0.2.4 → 0.2.5

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,5 +1,11 @@
1
1
  # @booki/readiness
2
2
 
3
+ ## 0.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#171](https://github.com/Walgermo/booki/pull/171) [`99d0d1c`](https://github.com/Walgermo/booki/commit/99d0d1c582b19048f88c2c2929b62825b2e9cc8b) Thanks [@Walgermo](https://github.com/Walgermo)! - `IconButton`: an icon button named by what it does. `label` is required ("Delete line 2"); it is the button's accessible name and tooltip, so an agent presses it by those words and a screen reader says them, and the icon is hidden. Pass any icon, such as `<TrashIcon />` from `@booki-aui/icons/react`; `showLabel` adds the label as visible text. It is ui-sdk's Button underneath, so `data-agent-confirm` and pending states work as on any button. Readiness now calls a nameless icon-only button that and points to `IconButton`, and flags a Booki icon shown at a size other than 16 or 20 px (minor, 1 point).
8
+
3
9
  ## 0.2.4
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -211,8 +211,9 @@ Each check names the Agent Contract section it enforces.
211
211
  | Fields that share one name | §3.1, §4.1 | Two or more fields of one role with the same name (one finding per group): the agent has to count. | 2 / 8 |
212
212
  | Field missing from the bridge | §3.1, §4.1 | On a page whose bridge has a snapshot: a named field a person can use (textbox, searchbox, combobox, listbox, spinbutton, checkbox, radio group, switch, slider) that no bridge entry covers, so an agent on the bridge cannot operate it. A field is covered when its name equals an entry's `label`, or when it sits inside the element of a bridge component: ui-sdk marks a component's root with `data-slot="<component>"` and its other parts with `data-slot="<component>-<part>"`, so the outermost such element of each kind counts. When the page has more of those elements than the snapshot has entries of that kind, only one named by an entry's label counts. A radio is covered by its group's name and reported once, as the group. Disabled fields, fields inside `data-agent-hidden` and the hidden inputs above are skipped, and the check does not run when the snapshot was cut short (a `more` entry). | 5 / 30 |
213
213
  | Focusable element that is not a control | §3.1, §4.1 | An element with `tabindex` ≥ 0 that the tree calls a cell or plain text, such as a grid cell that opens an editor on click. | 3 / 12 |
214
- | Button without a name | §3.1, §4.1 | A button whose name is empty. | 3 / 12 |
214
+ | Button without a name | §3.1, §4.1 | A button whose name is empty. One that shows only an icon (an SVG, an image or an icon font) is called an icon-only button, and the report points to `IconButton` from `@booki-aui/react`, whose `label` is required. | 3 / 12 |
215
215
  | Button named by an icon font | §3.1, §4.1 | A button whose name is an icon ligature (`close`, `content_copy`, `more_vert`, any snake_case word), or any single lowercase word drawn in an icon font. | 2 / 10 |
216
+ | Icon at a size it is not drawn for | §3.1 | A Booki icon (`svg[data-icon]` from `@booki-aui/icons`) shown at a size other than 16 or 20 px, where its lines blur. It changes nothing an agent reads. | 1 / 3 |
216
217
  | Figures only in pixels | §3.3 | A canvas or SVG chart, visible to the agent, whose name, description, fallback content and the table in its figure hold fewer than two numbers. Icons (small, inside a button or link, or fewer than three shapes) and `aria-hidden` charts are skipped. | 10 / 30 |
217
218
  | Irreversible button without a gate | §5.2 | A button or link that posts, pays, sends, approves, creates, submits, releases or signs (Bokfør, Opprett, Godkjenn, Betal, Send, Attester, Signer, Overfør, Post, Pay, Approve, Submit, Release, Sign off, …) with no `data-agent-confirm` on it or an ancestor, and no `confirm` on its bridge button. | 10 / 20 |
218
219
  | Secret readable by the agent | §3.5 | A Norwegian account number (mod 11), an IBAN (mod 97), a KID next to the word KID (mod 10 or 11), a US routing number next to "routing" (ABA) or a card number next to "card"/"kort" (Luhn) in the accessibility snapshot or the bridge's snapshot. Only numbers with valid check digits count, so amounts, dates and invoice numbers do not. A value inside `data-agent-secret` on a page with a bridge is redacted by the bridge and not reported. | 8 / 16 |
@@ -112,6 +112,17 @@ var RULES = {
112
112
  points: 2,
113
113
  cap: 10
114
114
  },
115
+ "icon-size": {
116
+ id: "icon-size",
117
+ title: "Icon at a size it is not drawn for",
118
+ contract: "\xA73.1 (presentation)",
119
+ severity: "minor",
120
+ why: "Booki's icons are drawn for 16 and 20 px. In between, their lines fall between pixels and blur, so a status icon beside a figure reads as a smudge. It does not change what an agent reads, which is why it costs little.",
121
+ fix: "Show the icon at size={16} or size={20}, and let the button or row around it take the space.",
122
+ booki: "size={16 | 20} on any @booki-aui/icons component",
123
+ points: 1,
124
+ cap: 3
125
+ },
115
126
  "chart-pixels-only": {
116
127
  id: "chart-pixels-only",
117
128
  title: "Figures only in pixels",
@@ -351,6 +362,23 @@ function describeElement(element2) {
351
362
  );
352
363
  });
353
364
  };
365
+ const glyph = (el) => {
366
+ const family = getComputedStyle(el).fontFamily;
367
+ const classes = typeof el.className === "string" ? el.className : "";
368
+ return iconPattern.test(family) || /(^|\s)(material-(icons|symbols)[\w-]*|icon[\w-]*|[\w-]+-icon|fa|fa-[\w-]+|glyphicon[\w-]*)(\s|$)/i.test(classes);
369
+ };
370
+ const labelText = (el) => {
371
+ let text = "";
372
+ for (const node of el.childNodes) {
373
+ if (node.nodeType === 3) text += node.textContent ?? "";
374
+ else if (node.nodeType === 1) {
375
+ const child = node;
376
+ if (child.getAttribute("aria-hidden") === "true" || glyph(child)) continue;
377
+ text += labelText(child);
378
+ }
379
+ }
380
+ return text;
381
+ };
354
382
  const html = (el) => {
355
383
  const copy = el.cloneNode(true);
356
384
  const text = copy.outerHTML.replace(/\s+/g, " ");
@@ -382,6 +410,7 @@ function describeElement(element2) {
382
410
  confirm: confirmHost ? confirmHost.getAttribute("data-agent-confirm") || "(marked)" : null,
383
411
  secret: element2.closest("[data-agent-secret]") !== null,
384
412
  iconFont: usesIconFont(element2),
413
+ iconOnly: !clean(labelText(element2)) && (element2.querySelector("svg, img") !== null || usesIconFont(element2)),
385
414
  disabled: element2.disabled === true || element2.getAttribute("aria-disabled") === "true",
386
415
  hidden: hiddenFromPeople(element2)
387
416
  };
@@ -522,6 +551,18 @@ function bridgeCoverage(element2, entries) {
522
551
  group
523
552
  };
524
553
  }
554
+ function findOffSizeIcons() {
555
+ const drawn = [16, 20];
556
+ const out = [];
557
+ for (const svg of document.querySelectorAll("svg[data-icon]")) {
558
+ const box = svg.getBoundingClientRect();
559
+ if (box.width <= 1 || box.height <= 1) continue;
560
+ const size = Math.round(box.width * 10) / 10;
561
+ if (drawn.includes(size)) continue;
562
+ out.push({ name: svg.getAttribute("data-icon") ?? "", size, html: svg.outerHTML.slice(0, 160) });
563
+ }
564
+ return out;
565
+ }
525
566
  function findFocusableNonControls() {
526
567
  const native = "a[href], button, input, select, textarea, summary, details, iframe, audio, video, [contenteditable=''], [contenteditable=true]";
527
568
  const neutral = /* @__PURE__ */ new Set([
@@ -606,6 +647,7 @@ var DESCRIBE = inPage(describeElement);
606
647
  var READ_BRIDGE = inPage(readBridge);
607
648
  var FIND_FOCUSABLE = inPage(findFocusableNonControls);
608
649
  var FIND_CHARTS = inPage(findCharts);
650
+ var FIND_OFF_SIZE_ICONS = inPage(findOffSizeIcons);
609
651
  var ONLY_IN_SECRETS = inPage(onlyInSecrets);
610
652
  var BRIDGE_COVERAGE = inPage(bridgeCoverage);
611
653
  var BROKEN_NAME = /\[object \w+\]|\bundefined\b|\bnull\b|\bNaN\b/;
@@ -850,7 +892,12 @@ async function check(page, url = page.url()) {
850
892
  const name = node.name.trim();
851
893
  if (node.role === "button" && !name) {
852
894
  const info = await describe(page, node);
853
- findings.push({ rule: "button-unnamed", message: "A button with no name.", element: element(node, info) });
895
+ findings.push({
896
+ rule: "button-unnamed",
897
+ message: info?.iconOnly ? "An icon-only button with no name." : "A button with no name.",
898
+ element: element(node, info),
899
+ booki: info?.iconOnly ? 'IconButton from @booki-aui/react: label is required ("Delete line 2")' : void 0
900
+ });
854
901
  continue;
855
902
  }
856
903
  if (node.role !== "link") {
@@ -878,6 +925,13 @@ async function check(page, url = page.url()) {
878
925
  }
879
926
  }
880
927
  }
928
+ for (const icon of await page.evaluate(FIND_OFF_SIZE_ICONS)) {
929
+ findings.push({
930
+ rule: "icon-size",
931
+ message: `The "${icon.name}" icon is shown at ${icon.size} px; it is drawn for 16 and 20.`,
932
+ element: { role: "img", name: icon.name, html: icon.html }
933
+ });
934
+ }
881
935
  const charts = await page.evaluate(FIND_CHARTS);
882
936
  const chartLocator = page.locator("canvas, svg");
883
937
  for (const chart of charts) {
@@ -1019,8 +1073,10 @@ function toConsole(report) {
1019
1073
  out.push(
1020
1074
  `${sevMark(rule.severity)} ${bold(rule.title)} ${dim(`(${rule.contract}) \u2212${d.points}`)} \xD7${list.length}`
1021
1075
  );
1022
- for (const f of list.slice(0, 6))
1076
+ for (const f of list.slice(0, 6)) {
1023
1077
  out.push(` ${f.message}${f.element?.selector ? dim(` ${f.element.selector}`) : ""}`);
1078
+ if (f.booki && f.booki !== rule.booki) out.push(` ${dim("Booki:")} ${f.booki}`);
1079
+ }
1024
1080
  if (list.length > 6) out.push(dim(` \u2026 and ${list.length - 6} more`));
1025
1081
  out.push(` ${dim("Fix:")} ${rule.fix}`);
1026
1082
  if (rule.booki) out.push(` ${dim("Booki:")} ${rule.booki}`);
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  toConsole,
5
5
  toHtml,
6
6
  toJson
7
- } from "./chunk-ZQPEUBPL.js";
7
+ } from "./chunk-SCZED25V.js";
8
8
  import "./chunk-PRRNS5HS.js";
9
9
 
10
10
  // src/cli.ts
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ type ElementInfo = {
18
18
  secret: boolean;
19
19
  /** The element or a descendant uses an icon font, by family or class. */
20
20
  iconFont: boolean;
21
+ /** The element shows only an icon (an svg, img or icon font) and no text of its own. */
22
+ iconOnly: boolean;
21
23
  disabled: boolean;
22
24
  /**
23
25
  * Out of reach of a person and an agent: aria-hidden or inert on it or an
@@ -32,7 +34,7 @@ type ElementInfo = {
32
34
  * enforces (spec/agent-contract.md), why it matters to an agent, the fix, and
33
35
  * how much it can take off the score.
34
36
  */
35
- type RuleId = "bridge-missing" | "bridge-unnamed-control" | "bridge-person-action" | "field-unnamed" | "field-broken-name" | "field-ambiguous" | "field-not-on-bridge" | "focusable-without-role" | "button-unnamed" | "button-icon-name" | "chart-pixels-only" | "irreversible-ungated" | "secret-visible" | "snapshot-size";
37
+ type RuleId = "bridge-missing" | "bridge-unnamed-control" | "bridge-person-action" | "field-unnamed" | "field-broken-name" | "field-ambiguous" | "field-not-on-bridge" | "focusable-without-role" | "button-unnamed" | "button-icon-name" | "icon-size" | "chart-pixels-only" | "irreversible-ungated" | "secret-visible" | "snapshot-size";
36
38
  type Severity = "critical" | "serious" | "moderate" | "minor";
37
39
  type Rule = {
38
40
  id: RuleId;
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  toConsole,
14
14
  toHtml,
15
15
  toJson
16
- } from "./chunk-ZQPEUBPL.js";
16
+ } from "./chunk-SCZED25V.js";
17
17
  import {
18
18
  PERSON_ACTION,
19
19
  findSecrets,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@booki-aui/readiness",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Agent readiness check for accounting screens: what stops an AI agent on a page, scored 0-100 against the Agent Contract, with fixes.",
5
5
  "type": "module",
6
6
  "license": "MIT",