@a.incantalupo/web-tools 0.0.0-stage → 0.1.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.
Files changed (50) hide show
  1. package/README.md +45 -2
  2. package/dist/audit/cli.d.ts +1 -0
  3. package/dist/audit/cli.js +238 -0
  4. package/dist/audit/crux.d.ts +6 -0
  5. package/dist/audit/crux.js +29 -0
  6. package/dist/audit/fetch.d.ts +17 -0
  7. package/dist/audit/fetch.js +51 -0
  8. package/dist/audit/findings.d.ts +9 -0
  9. package/dist/audit/findings.js +514 -0
  10. package/dist/audit/index.d.ts +6 -0
  11. package/dist/audit/index.js +3 -0
  12. package/dist/audit/lighthouse.d.ts +2 -0
  13. package/dist/audit/lighthouse.js +84 -0
  14. package/dist/audit/page.d.ts +10 -0
  15. package/dist/audit/page.js +156 -0
  16. package/dist/audit/profile.d.ts +11 -0
  17. package/dist/audit/profile.js +21 -0
  18. package/dist/audit/render.d.ts +8 -0
  19. package/dist/audit/render.js +63 -0
  20. package/dist/audit/rerender.d.ts +1 -0
  21. package/dist/audit/rerender.js +55 -0
  22. package/dist/audit/reviews.d.ts +2 -0
  23. package/dist/audit/reviews.js +36 -0
  24. package/dist/audit/scores.d.ts +3 -0
  25. package/dist/audit/scores.js +51 -0
  26. package/dist/audit/site.d.ts +19 -0
  27. package/dist/audit/site.js +78 -0
  28. package/dist/audit/summary.d.ts +2 -0
  29. package/dist/audit/summary.js +59 -0
  30. package/dist/audit/types.d.ts +132 -0
  31. package/dist/audit/types.js +1 -0
  32. package/dist/browser/cli.d.ts +1 -0
  33. package/dist/browser/cli.js +11 -0
  34. package/dist/browser/index.d.ts +15 -0
  35. package/dist/browser/index.js +63 -0
  36. package/dist/cli.d.ts +2 -0
  37. package/dist/cli.js +34 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +4 -0
  40. package/dist/refs/cli.d.ts +1 -0
  41. package/dist/refs/cli.js +193 -0
  42. package/dist/refs/glyphs.d.ts +1 -0
  43. package/dist/refs/glyphs.js +101 -0
  44. package/dist/refs/images.d.ts +1 -0
  45. package/dist/refs/images.js +163 -0
  46. package/dist/refs/snapshot.d.ts +1 -0
  47. package/dist/refs/snapshot.js +243 -0
  48. package/dist/refs/text.d.ts +1 -0
  49. package/dist/refs/text.js +487 -0
  50. package/package.json +34 -5
@@ -0,0 +1,487 @@
1
+ // Can everyone read this page? The words (reading ease, long sentences), how big and how
2
+ // dark the text is, whether the fields and the things you tap are large and visible
3
+ // enough. Rules and reasons: web-stack-kb, stack-writing-readable-accessible-ui.
4
+ //
5
+ // Usage: stack-tools text <url...> [--verbose] [--login <email>]
6
+ //
7
+ // --login signs in at /admin/login of the first URL's site first (password from
8
+ // CHECK_PASSWORD), so admin pages can be measured. Use a login on the dev database.
9
+ //
10
+ // Each page is opened on a phone (390 px) and a desktop (1440 px), plus once at 320 px
11
+ // for sideways scroll.
12
+ //
13
+ // Fails (exit 1) on the floors: text under 4.5:1 on a plain background (3:1 from 24 px,
14
+ // or 18.66 px bold), a target under 24 px, a field under 16 px (an iPhone zooms the page
15
+ // on focus), sideways scroll at 320 px.
16
+ // Warns on the rules we set ourselves: reading ease under 60 (Gulpease), a sentence over
17
+ // 25 words, text under 16 px, small text under 7:1, text on a bright part of a photo,
18
+ // a field edge under 3:1, a target under 44 px on the phone, lines over 80 characters.
19
+ //
20
+ // Text inside an element marked `data-quoted` (a customer's review, the client's own
21
+ // description) is someone else's writing: its words are not measured.
22
+ import { chromium } from "playwright-core";
23
+ import { homedir } from "node:os";
24
+ import { join } from "node:path";
25
+ import { parseArgs } from "node:util";
26
+ const { values, positionals: urls } = parseArgs({
27
+ allowPositionals: true,
28
+ options: {
29
+ verbose: { type: "boolean", default: false },
30
+ login: { type: "string" },
31
+ },
32
+ });
33
+ if (!urls.length) {
34
+ console.error("Usage: stack-tools text <url...> [--verbose] [--login <email>]");
35
+ process.exit(1);
36
+ }
37
+ const screens = {
38
+ "phone 390": {
39
+ viewport: { width: 390, height: 844 },
40
+ deviceScaleFactor: 1,
41
+ isMobile: true,
42
+ hasTouch: true,
43
+ },
44
+ "desktop 1440": {
45
+ viewport: { width: 1440, height: 900 },
46
+ deviceScaleFactor: 1,
47
+ },
48
+ };
49
+ /** Runs in the page. */
50
+ function measure() {
51
+ const canvas = document.createElement("canvas");
52
+ canvas.width = canvas.height = 1;
53
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
54
+ const parsed = new Map();
55
+ // Any CSS colour (oklch, color-mix...) to r, g, b, alpha: let the canvas do it.
56
+ const rgba = (colour) => {
57
+ let v = parsed.get(colour);
58
+ if (!v) {
59
+ ctx.clearRect(0, 0, 1, 1);
60
+ ctx.fillStyle = "#000";
61
+ ctx.fillStyle = colour;
62
+ ctx.fillRect(0, 0, 1, 1);
63
+ const d = ctx.getImageData(0, 0, 1, 1).data;
64
+ v = [d[0], d[1], d[2], d[3] / 255];
65
+ parsed.set(colour, v);
66
+ }
67
+ return v;
68
+ };
69
+ const over = (top, under) => [
70
+ ...[0, 1, 2].map((i) => top[i] * top[3] + under[i] * (1 - top[3])),
71
+ 1,
72
+ ];
73
+ const lum = ([r, g, b]) => {
74
+ const f = (x) => (x /= 255) <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
75
+ return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
76
+ };
77
+ const ratio = (a, b) => {
78
+ const [hi, lo] = [lum(a), lum(b)].sort((x, y) => y - x);
79
+ return (hi + 0.05) / (lo + 0.05);
80
+ };
81
+ const visible = (el) => {
82
+ const r = el.getBoundingClientRect();
83
+ if (r.width < 1 || r.height < 1)
84
+ return false;
85
+ if (r.right < 0 || r.left > innerWidth + 5)
86
+ return false;
87
+ for (let e = el; e; e = e.parentElement) {
88
+ const s = getComputedStyle(e);
89
+ if (s.visibility === "hidden" || s.display === "none")
90
+ return false;
91
+ if (Number(s.opacity) < 0.05)
92
+ return false;
93
+ if (e.getAttribute("aria-hidden") === "true")
94
+ return false;
95
+ }
96
+ return true;
97
+ };
98
+ // What is behind an element: the plain colours of its ancestors, composed. A background
99
+ // image, or a positioned photo filling an ancestor, means the pixels must be read.
100
+ const backdrop = (el) => {
101
+ const layers = [];
102
+ let image = false;
103
+ for (let e = el; e; e = e.parentElement) {
104
+ const s = getComputedStyle(e);
105
+ if (s.backgroundImage !== "none")
106
+ image = true;
107
+ if (e !== el) {
108
+ const photo = e.querySelector(":scope > img, :scope > picture > img, :scope > video");
109
+ if (photo && getComputedStyle(photo).position === "absolute")
110
+ image = true;
111
+ }
112
+ const c = rgba(s.backgroundColor);
113
+ if (c[3] > 0)
114
+ layers.push(c);
115
+ if (c[3] >= 0.999)
116
+ break;
117
+ }
118
+ let bg = [255, 255, 255, 1];
119
+ for (const layer of layers.reverse())
120
+ bg = over(layer, bg);
121
+ return { bg, image };
122
+ };
123
+ const texts = [];
124
+ const byElement = new Map();
125
+ const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
126
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
127
+ const text = node.data.replace(/\s+/g, " ").trim();
128
+ const el = node.parentElement;
129
+ if (!text || !el || el.closest("svg, script, style, noscript, option"))
130
+ continue;
131
+ if (!visible(el))
132
+ continue;
133
+ const seen = byElement.get(el);
134
+ if (seen) {
135
+ seen.text += ` ${text}`;
136
+ seen.chars += text.length;
137
+ continue;
138
+ }
139
+ const s = getComputedStyle(el);
140
+ const size = parseFloat(s.fontSize);
141
+ const { bg, image } = backdrop(el);
142
+ const fg = over(rgba(s.color), bg);
143
+ const range = document.createRange();
144
+ range.selectNodeContents(el);
145
+ const r = range.getBoundingClientRect();
146
+ const row = {
147
+ text,
148
+ chars: text.length,
149
+ size,
150
+ large: size >= 24 || (size >= 18.66 && Number(s.fontWeight) >= 700),
151
+ ratio: ratio(fg, bg),
152
+ onImage: image,
153
+ box: [r.x, r.y + scrollY, r.width, r.height],
154
+ lum: lum(rgba(s.color)),
155
+ };
156
+ if (image)
157
+ el.setAttribute("data-check-on-image", "");
158
+ byElement.set(el, row);
159
+ texts.push(row);
160
+ }
161
+ // How well a field stands out from what is around it: by its own edge or fill, or by
162
+ // those of the box that holds it (a search bar: borderless fields inside one outlined
163
+ // pill). A ring is a box shadow with no offset and no blur.
164
+ const edgeOf = (field) => {
165
+ let best = 1;
166
+ let el = field;
167
+ for (let depth = 0; el?.parentElement && depth < 3; depth++) {
168
+ const s = getComputedStyle(el);
169
+ const { bg } = backdrop(el.parentElement);
170
+ const fill = over(rgba(s.backgroundColor), bg);
171
+ best = Math.max(best, ratio(fill, bg));
172
+ if (parseFloat(s.borderTopWidth) > 0)
173
+ best = Math.max(best, ratio(over(rgba(s.borderTopColor), bg), bg));
174
+ for (const [, colour, spread] of s.boxShadow.matchAll(/([a-z]+\([^)]*\))\s+0px\s+0px\s+0px\s+([\d.]+)px/g))
175
+ if (Number(spread) > 0)
176
+ best = Math.max(best, ratio(over(rgba(colour), bg), bg));
177
+ el = el.parentElement;
178
+ }
179
+ return best;
180
+ };
181
+ const targets = [];
182
+ const fields = [];
183
+ for (const el of document.querySelectorAll("a[href], button, input:not([type=hidden]), select, textarea, summary, [role=button]")) {
184
+ if (!visible(el))
185
+ continue;
186
+ const s = getComputedStyle(el);
187
+ const type = el.getAttribute("type");
188
+ const tick = type === "checkbox" || type === "radio";
189
+ // A link inside a sentence is as tall as its line: the rules leave it out.
190
+ if (el.tagName === "A" &&
191
+ s.display === "inline" &&
192
+ el.closest("p, li, dd, label"))
193
+ continue;
194
+ // A tick box is tapped through its label.
195
+ const box = ((tick && el.closest("label")) || el).getBoundingClientRect();
196
+ const what = (el.innerText ||
197
+ el.getAttribute("aria-label") ||
198
+ el.getAttribute("placeholder") ||
199
+ el.getAttribute("name") ||
200
+ el.tagName.toLowerCase())
201
+ .replace(/\s+/g, " ")
202
+ .trim()
203
+ .slice(0, 28);
204
+ targets.push({ what, w: Math.round(box.width), h: Math.round(box.height) });
205
+ if (/^(INPUT|SELECT|TEXTAREA)$/.test(el.tagName))
206
+ fields.push({
207
+ what,
208
+ // A tick box has no text of its own.
209
+ size: tick ? 16 : parseFloat(s.fontSize),
210
+ edge: edgeOf(el),
211
+ });
212
+ }
213
+ const lines = [];
214
+ for (const p of document.querySelectorAll("p, li, dd")) {
215
+ if (!visible(p))
216
+ continue;
217
+ const text = p.innerText.replace(/\s+/g, " ").trim();
218
+ const s = getComputedStyle(p);
219
+ const size = parseFloat(s.fontSize);
220
+ const height = s.lineHeight === "normal" ? size * 1.2 : parseFloat(s.lineHeight);
221
+ const count = Math.round(p.getBoundingClientRect().height / height);
222
+ if (text.length < 90 || count < 2)
223
+ continue;
224
+ // Characters that fit in one line: the box's width over the text's average letter
225
+ // width (measured, not counted from the lines: the last line is rarely full).
226
+ ctx.font = `${s.fontWeight} ${s.fontSize} ${s.fontFamily}`;
227
+ const letter = ctx.measureText(text).width / text.length;
228
+ const width = p.clientWidth - parseFloat(s.paddingLeft) - parseFloat(s.paddingRight);
229
+ lines.push({
230
+ chars: Math.round(width / letter),
231
+ text: text.slice(0, 40),
232
+ });
233
+ }
234
+ // Text blocks: text runs split wherever a non-inline element starts or ends.
235
+ const blocks = [];
236
+ let quoted = 0;
237
+ let run = "";
238
+ const flush = () => {
239
+ const t = run.replace(/\s+/g, " ").trim();
240
+ if (t)
241
+ blocks.push(t);
242
+ run = "";
243
+ };
244
+ const walk = (el) => {
245
+ for (const child of el.childNodes) {
246
+ if (child.nodeType === Node.TEXT_NODE)
247
+ run += child.textContent;
248
+ if (!(child instanceof Element))
249
+ continue;
250
+ if (child.closest("svg, script, style, noscript, select"))
251
+ continue;
252
+ if (child.tagName === "BR") {
253
+ run += " ";
254
+ continue;
255
+ }
256
+ if (child.hasAttribute("data-quoted")) {
257
+ quoted++;
258
+ flush();
259
+ continue;
260
+ }
261
+ // Not `visible()`: a wrapper with `display: contents` has no box of its own.
262
+ const style = getComputedStyle(child);
263
+ if (style.display === "none" ||
264
+ style.visibility === "hidden" ||
265
+ child.getAttribute("aria-hidden") === "true")
266
+ continue;
267
+ const inline = style.display.startsWith("inline");
268
+ if (!inline)
269
+ flush();
270
+ walk(child);
271
+ if (!inline)
272
+ flush();
273
+ }
274
+ };
275
+ walk(document.body);
276
+ flush();
277
+ return {
278
+ texts,
279
+ targets,
280
+ fields,
281
+ lines,
282
+ blocks: [...new Set(blocks)],
283
+ quoted,
284
+ overflow: document.documentElement.scrollWidth - innerWidth,
285
+ };
286
+ }
287
+ // --- The words (Italian) ---
288
+ const words = (s) => s.match(/[\p{L}\p{N}][\p{L}\p{N}'’.-]*[\p{L}\p{N}]|[\p{L}\p{N}]/gu) ?? [];
289
+ const letters = (s) => (s.match(/\p{L}/gu) ?? []).length;
290
+ const sentences = (s) => s
291
+ .split(/(?<=[.!?…])\s+(?=[\p{Lu}"«“(])/u)
292
+ .map((x) => x.trim())
293
+ .filter(Boolean);
294
+ /** Gulpease (Lucisano and Piemontese, 1988): 0-100, higher is easier; under 60 is hard
295
+ * for a reader with the licenza media. */
296
+ const gulpease = (text, sentenceCount) => {
297
+ const w = words(text).length;
298
+ if (!w)
299
+ return null;
300
+ const g = 89 + (300 * sentenceCount - 10 * letters(text)) / w;
301
+ return Math.max(0, Math.min(100, g));
302
+ };
303
+ /** Only blocks of 8 words or more: a page's labels ("Benzina", "2019") each count as a
304
+ * sentence and push the index to 100. */
305
+ function prose(blocks) {
306
+ const all = blocks.filter((b) => words(b).length >= 8).flatMap(sentences);
307
+ return {
308
+ score: gulpease(all.join(" "), all.length),
309
+ sentences: all.length,
310
+ long: all
311
+ .map((s) => ({ s, n: words(s).length }))
312
+ .filter((x) => x.n > 25)
313
+ .sort((a, b) => b.n - a.n),
314
+ };
315
+ }
316
+ // --- Text on a photo ---
317
+ /** Contrast of each such text against the brightest tenth of what is behind it (for
318
+ * light text; the darkest tenth for dark text). The text is hidden first. */
319
+ async function onPhotos(page, reader, texts) {
320
+ const found = [];
321
+ const rows = texts.filter((t) => t.onImage && t.box[2] >= 2 && t.box[3] >= 2);
322
+ if (!rows.length)
323
+ return found;
324
+ await page.addStyleTag({
325
+ content: "[data-check-on-image]{color:transparent!important;text-shadow:none!important}",
326
+ });
327
+ for (const text of rows) {
328
+ const [x, y, width, height] = text.box;
329
+ const png = await page.screenshot({
330
+ clip: { x, y, width, height },
331
+ fullPage: true,
332
+ });
333
+ const behind = await reader.evaluate(async ([data, light]) => {
334
+ const img = new Image();
335
+ img.src = `data:image/png;base64,${data}`;
336
+ await img.decode();
337
+ const c = document.createElement("canvas");
338
+ c.width = img.width;
339
+ c.height = img.height;
340
+ const g = c.getContext("2d");
341
+ g.drawImage(img, 0, 0);
342
+ const d = g.getImageData(0, 0, c.width, c.height).data;
343
+ const f = (v) => (v /= 255) <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
344
+ const all = [];
345
+ for (let i = 0; i < d.length; i += 4)
346
+ all.push(0.2126 * f(d[i]) + 0.7152 * f(d[i + 1]) + 0.0722 * f(d[i + 2]));
347
+ all.sort((a, b) => a - b);
348
+ return all[Math.floor((light ? 0.9 : 0.1) * (all.length - 1))];
349
+ }, [png.toString("base64"), text.lum > 0.4]);
350
+ const [hi, lo] = [text.lum, behind].sort((a, b) => b - a);
351
+ found.push({ text, ratio: (hi + 0.05) / (lo + 0.05) });
352
+ }
353
+ return found;
354
+ }
355
+ // --- Run ---
356
+ const browser = await chromium.launch({
357
+ executablePath: process.env.CHROME_PATH ??
358
+ join(homedir(), ".cache/ms-playwright/chromium-1194/chrome-linux/chrome"),
359
+ });
360
+ let failures = 0;
361
+ let warnings = 0;
362
+ const pad = "".padEnd(15);
363
+ const short = (s, n = 44) => (s.length > n ? `${s.slice(0, n)}…` : s);
364
+ const list = (rows, show, n = 3) => rows
365
+ .slice(0, values.verbose ? 50 : n)
366
+ .map(show)
367
+ .join(", ") +
368
+ (rows.length > n && !values.verbose ? ` (+${rows.length - n})` : "");
369
+ // A signed-in session, shared by every page opened after it.
370
+ let signedIn;
371
+ if (values.login) {
372
+ const password = process.env.CHECK_PASSWORD;
373
+ if (!password) {
374
+ console.error("--login needs the password in CHECK_PASSWORD");
375
+ process.exit(1);
376
+ }
377
+ const context = await browser.newContext();
378
+ const page = await context.newPage();
379
+ await page.goto(new URL("/admin/login", urls[0]).href);
380
+ await page.fill("input[name=email]", values.login);
381
+ await page.fill("input[name=password]", password);
382
+ await Promise.all([
383
+ page.waitForURL((u) => !u.pathname.startsWith("/admin/login"), {
384
+ timeout: 15_000,
385
+ }),
386
+ page.click("form button"),
387
+ ]).catch(() => {
388
+ console.error("Sign-in failed: check the email and CHECK_PASSWORD");
389
+ process.exit(1);
390
+ });
391
+ signedIn = await context.storageState();
392
+ await context.close();
393
+ }
394
+ async function open(url, options) {
395
+ const context = await browser.newContext({
396
+ ...options,
397
+ reducedMotion: "reduce",
398
+ storageState: signedIn,
399
+ });
400
+ const page = await context.newPage();
401
+ // A check is not a visit: keep it out of the site's own analytics.
402
+ await page.route("**/api/t", (route) => route.abort());
403
+ await page.goto(url, { waitUntil: "networkidle" });
404
+ // Scroll through, so what appears on scroll is in its final state.
405
+ await page.evaluate(async () => {
406
+ for (let y = 0; y < document.body.scrollHeight; y += 600) {
407
+ scrollTo(0, y);
408
+ await new Promise((r) => setTimeout(r, 60));
409
+ }
410
+ scrollTo(0, 0);
411
+ await new Promise((r) => setTimeout(r, 200));
412
+ });
413
+ return { context, page };
414
+ }
415
+ for (const url of urls) {
416
+ console.log(`\n${url}`);
417
+ let first = true;
418
+ for (const [name, options] of Object.entries(screens)) {
419
+ const phone = name.startsWith("phone");
420
+ const { context, page } = await open(url, options);
421
+ const m = await page.evaluate(measure);
422
+ const photos = await onPhotos(page, await context.newPage(), m.texts);
423
+ await context.close();
424
+ const fail = (note) => (failures++, `FAIL ${note}`);
425
+ const warn = (note) => (warnings++, `warn ${note}`);
426
+ const notes = [];
427
+ if (first) {
428
+ first = false;
429
+ const p = prose(m.blocks);
430
+ const score = p.score == null ? "no prose" : `reading ease ${Math.round(p.score)}`;
431
+ console.log(` ${"words".padEnd(15)}${score} on ${p.sentences} sentence(s)${m.quoted ? `, ${m.quoted} quoted block(s) left out` : ""}`);
432
+ if (p.score != null && p.score < 60)
433
+ console.log(` ${pad}${warn("reading ease under 60 (hard with the licenza media)")}`);
434
+ if (p.long.length)
435
+ console.log(` ${pad}${warn(`${p.long.length} sentence(s) over 25 words: ${list(p.long, (x) => `${x.n} "${short(x.s)}"`, 2)}`)}`);
436
+ }
437
+ const total = m.texts.reduce((a, t) => a + t.chars, 0) || 1;
438
+ const share = (rows) => Math.round((100 * rows.reduce((a, t) => a + t.chars, 0)) / total);
439
+ const small = m.texts.filter((t) => t.size < 16);
440
+ const plain = m.texts.filter((t) => !t.onImage);
441
+ const low = plain.filter((t) => t.ratio < (t.large ? 3 : 4.5));
442
+ const pale = plain.filter((t) => t.size < 16 && t.ratio >= 4.5 && t.ratio < 7);
443
+ const lowPhoto = photos.filter((p) => p.ratio < (p.text.large ? 3 : 4.5));
444
+ if (low.length)
445
+ notes.push(fail(`${low.length} text(s) under 4.5:1: ${list(low, (t) => `${t.ratio.toFixed(1)} "${short(t.text, 24)}"`)}`));
446
+ if (small.length)
447
+ notes.push(warn(`${share(small)}% of the text under 16 px (${share(m.texts.filter((t) => t.size < 14))}% under 14 px)`));
448
+ if (pale.length)
449
+ notes.push(warn(`${pale.length} small text(s) under 7:1: ${list(pale, (t) => `${t.ratio.toFixed(1)} "${short(t.text, 24)}"`, 2)}`));
450
+ if (lowPhoto.length)
451
+ notes.push(warn(`text on a bright part of a photo: ${list(lowPhoto, (p) => `${p.ratio.toFixed(1)} "${short(p.text.text, 24)}"`)}`));
452
+ const smallFields = m.fields.filter((f) => f.size < 16);
453
+ const faint = m.fields.filter((f) => f.edge < 3);
454
+ if (smallFields.length)
455
+ notes.push(fail(`${smallFields.length} field(s) under 16 px: ${list(smallFields, (f) => `"${f.what}" ${f.size} px`)}`));
456
+ if (faint.length)
457
+ notes.push(warn(`${faint.length} field(s) with an edge under 3:1: ${list(faint, (f) => `${f.edge.toFixed(2)} "${f.what}"`, 2)}`));
458
+ const tiny = m.targets.filter((t) => t.w < 24 || t.h < 24);
459
+ const under = m.targets.filter((t) => (t.w < 44 || t.h < 44) && !tiny.includes(t));
460
+ const size = (t) => `"${t.what}" ${t.w}×${t.h}`;
461
+ if (tiny.length)
462
+ notes.push(fail(`${tiny.length} target(s) under 24 px: ${list(tiny, size)}`));
463
+ if (phone && under.length)
464
+ notes.push(warn(`${under.length} target(s) under 44 px: ${list(under, size)}`));
465
+ const wide = m.lines.filter((l) => l.chars > 80);
466
+ if (wide.length)
467
+ notes.push(warn(`${wide.length} paragraph(s) over 80 characters a line: ${list(wide, (l) => `${l.chars} "${l.text}"`, 2)}`));
468
+ console.log(` ${name.padEnd(15)}${m.texts.length} texts, ${m.fields.length} field(s), ${m.targets.length} target(s)${notes.length ? "" : ": nothing to report"}`);
469
+ for (const note of notes)
470
+ console.log(` ${pad}${note}`);
471
+ }
472
+ const { context, page } = await open(url, {
473
+ viewport: { width: 320, height: 640 },
474
+ isMobile: true,
475
+ hasTouch: true,
476
+ });
477
+ const overflow = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth);
478
+ await context.close();
479
+ if (overflow > 1) {
480
+ failures++;
481
+ console.log(` ${"narrow 320".padEnd(15)}FAIL scrolls sideways by ${overflow} px`);
482
+ }
483
+ }
484
+ await browser.close();
485
+ console.log(`\n${failures} failure(s), ${warnings} warning(s) on ${urls.length} page(s).`);
486
+ if (failures)
487
+ process.exitCode = 1;
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
- "name": "@a.incantalupo/web-tools",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@a.incantalupo/web-tools",
3
+ "version": "0.1.0",
4
+ "description": "Checks and captures for any website: readability and contrast, screenshots, style snapshots and diffs, glyph and image checks, a site audit with niche profiles, your own signed-in browser (web-stack-kb).",
5
+ "type": "module",
6
+ "bin": {
7
+ "stack-tools": "dist/cli.js"
8
+ },
9
+ "exports": {
10
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
11
+ "./audit": { "types": "./dist/audit/index.d.ts", "default": "./dist/audit/index.js" }
12
+ },
13
+ "files": ["dist", "README.md"],
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Alessandro-Incantalupo/web-stack-kb.git",
18
+ "directory": "tools/web-tools"
19
+ },
20
+ "scripts": {
21
+ "build": "rm -rf dist && tsc -p tsconfig.json && chmod +x dist/cli.js",
22
+ "check": "tsc -p tsconfig.json --noEmit",
23
+ "prepublishOnly": "pnpm build"
24
+ },
25
+ "dependencies": {
26
+ "cheerio": "^1.1.0",
27
+ "chrome-launcher": "^1.2.0",
28
+ "lighthouse": "^12.8.0",
29
+ "playwright-core": "1.56.1"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^24",
33
+ "typescript": "^6.0.3"
34
+ }
35
+ }