@a.incantalupo/web-tools 0.1.0 → 0.2.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 +6 -10
- package/dist/browser/index.js +3 -7
- package/dist/cli.js +1 -1
- package/dist/refs/cli.js +1 -1
- package/dist/refs/text.js +249 -8
- package/package.json +2 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @a.incantalupo/web-tools
|
|
2
2
|
|
|
3
|
-
Checks and captures for any website, as one command: `stack-tools`.
|
|
3
|
+
Checks and captures for any website, as one command: `stack-tools`.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
stack-tools # the list of commands
|
|
@@ -8,7 +8,7 @@ stack-tools browser [url] # your own Chromium window: sign in by hand, to
|
|
|
8
8
|
stack-tools refs <url...> [--full] [--mine] [--out dir | --out-root dir] # desktop + mobile screenshots -> ./design-refs/<date>
|
|
9
9
|
stack-tools snap <dir> <url...> # computed styles + screenshots of pages, in every theme
|
|
10
10
|
stack-tools diff <before> <after>
|
|
11
|
-
stack-tools text <url...> [--verbose] [--login <email>] # reading ease (Gulpease), text size, contrast, fields, tap targets
|
|
11
|
+
stack-tools text <url...> [--verbose] [--login <email>] # reading ease (Gulpease), text size, contrast, fields, tap targets, sideways scroll at 320 px, the phone with text at 130-200%
|
|
12
12
|
stack-tools glyphs <url...> # characters the page fonts don't cover
|
|
13
13
|
stack-tools images <url...> # which image file each slot downloads (3x phone, 2x laptop, 1x monitor)
|
|
14
14
|
stack-tools audit <url> [--profile file.ts] [--render] [--teaser] [--reviews a.json...] [--preview] [--header 'Name: value'] [--keys .env] [--out dir | --out-root dir]
|
|
@@ -19,9 +19,9 @@ Outputs go where you run the command (`./design-refs`, `./site-eval/<host>/<date
|
|
|
19
19
|
|
|
20
20
|
## Setup
|
|
21
21
|
|
|
22
|
-
- In a project: `pnpm add -D @a.incantalupo/web-tools`, then scripts like `"check:text": "stack-tools text"`.
|
|
23
|
-
- Chromium: the tools use Playwright's (`CHROME_PATH`, default `~/.cache/ms-playwright/chromium-1194/chrome-linux/chrome`).
|
|
24
|
-
- `stack-tools browser` keeps its profile in `~/.cache/stack-tools/chrome-profile` (
|
|
22
|
+
- In a project: `pnpm add -D @a.incantalupo/web-tools`, then scripts like `"check:text": "stack-tools text"`.
|
|
23
|
+
- Chromium: the tools use Playwright's (`CHROME_PATH`, default `~/.cache/ms-playwright/chromium-1194/chrome-linux/chrome`). Install it with `pnpm dlx playwright@1.56.1 install chromium`.
|
|
24
|
+
- `stack-tools browser` keeps its profile in `~/.cache/stack-tools/chrome-profile` (`MY_CHROME_PROFILE` to change it) and listens on `127.0.0.1:9222` only (`MY_CHROME_PORT`).
|
|
25
25
|
|
|
26
26
|
## The audit and its profiles
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ Outputs go where you run the command (`./design-refs`, `./site-eval/<host>/<date
|
|
|
30
30
|
A **profile** adapts it to a niche and writes that niche's reports. It lives in the project that sells to the niche, so its wording and sales notes stay private:
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
//
|
|
33
|
+
// niches/dealer/profile.ts in your own (private) repo
|
|
34
34
|
import type { AuditProfile } from '@a.incantalupo/web-tools/audit';
|
|
35
35
|
export default {
|
|
36
36
|
name: 'dealer',
|
|
@@ -40,7 +40,3 @@ export default {
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
`@a.incantalupo/web-tools/audit` exports the result types, `computeScores`, `buildFindings`, `renderSummary`. The package root exports the own-browser connection (`connectMyChrome`, `openMyChrome`, `isOpen`) and the polite fetch helpers (`timedFetch`, `tryFetch`, `mapLimit`) for a project's own scrapers.
|
|
43
|
-
|
|
44
|
-
## Releasing
|
|
45
|
-
|
|
46
|
-
Bump `version`, add a line to the KB's `CHANGELOG.md`, commit, then `npm publish --access public` here (it builds first; npm asks for the passkey). Renovate brings it to every project.
|
package/dist/browser/index.js
CHANGED
|
@@ -5,17 +5,13 @@
|
|
|
5
5
|
// It is started as a plain program, not by Playwright, so it has no automation
|
|
6
6
|
// flags and no "controlled by automated test software" bar; the tools attach over
|
|
7
7
|
// the DevTools protocol on 127.0.0.1 only. Nothing here disguises the browser:
|
|
8
|
-
// a site that still refuses it is respected
|
|
8
|
+
// a site that still refuses it is respected.
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
|
-
import { existsSync } from "node:fs";
|
|
11
10
|
import { homedir } from "node:os";
|
|
12
11
|
import { join } from "node:path";
|
|
13
12
|
import { chromium } from "playwright-core";
|
|
14
|
-
// The profile keeps your sign-ins.
|
|
15
|
-
|
|
16
|
-
const legacyProfile = join(homedir(), ".cache/dealer-platform/chrome-profile");
|
|
17
|
-
export const PROFILE = process.env.MY_CHROME_PROFILE ??
|
|
18
|
-
(existsSync(legacyProfile) ? legacyProfile : join(homedir(), ".cache/stack-tools/chrome-profile"));
|
|
13
|
+
// The profile keeps your sign-ins.
|
|
14
|
+
export const PROFILE = process.env.MY_CHROME_PROFILE ?? join(homedir(), ".cache/stack-tools/chrome-profile");
|
|
19
15
|
export const PORT = Number(process.env.MY_CHROME_PORT ?? 9222);
|
|
20
16
|
export const executablePath = process.env.CHROME_PATH ??
|
|
21
17
|
join(homedir(), ".cache/ms-playwright/chromium-1194/chrome-linux/chrome");
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ const commands = {
|
|
|
14
14
|
refs: { file: "./refs/cli.js", about: "desktop + mobile screenshots of sites: <url...> [--full] [--mine] [--out dir | --out-root dir]" },
|
|
15
15
|
snap: { file: "./refs/snapshot.js", keepName: true, about: "computed styles + screenshots of pages: <dir> <url...>" },
|
|
16
16
|
diff: { file: "./refs/snapshot.js", keepName: true, about: "what changed between two snaps: <before> <after>" },
|
|
17
|
-
text: { file: "./refs/text.js", about: "readability, text size, contrast, fields, tap targets
|
|
17
|
+
text: { file: "./refs/text.js", about: "readability, text size, contrast, fields, tap targets, text at 200%: <url...> [--verbose] [--login email]" },
|
|
18
18
|
glyphs: { file: "./refs/glyphs.js", about: "characters the page fonts do not cover: <url...>" },
|
|
19
19
|
images: { file: "./refs/images.js", about: "which image file each slot downloads, weights, lazy LCP: <url...>" },
|
|
20
20
|
audit: { file: "./audit/cli.js", about: "audit a site (SEO, AI visibility, speed, contacts): <url> [--profile file.ts] [--render] [--teaser]" },
|
package/dist/refs/cli.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Cloudflare challenge). We report that and move on; we don't try to get past
|
|
8
8
|
// it. With --mine the shots are taken in a new tab of Alessandro's own Chrome
|
|
9
9
|
// (`stack-tools browser`), as he would see the page; a site that still
|
|
10
|
-
// refuses is captured by hand
|
|
10
|
+
// refuses is captured by hand.
|
|
11
11
|
import { connectMyChrome } from "../browser/index.js";
|
|
12
12
|
import { chromium } from "playwright-core";
|
|
13
13
|
import { mkdir, writeFile } from "node:fs/promises";
|
package/dist/refs/text.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Can everyone read this page? The words (reading ease, long sentences), how big and how
|
|
2
2
|
// dark the text is, whether the fields and the things you tap are large and visible
|
|
3
|
-
// enough.
|
|
3
|
+
// enough (WCAG 2.2 AA, plus a stricter bar for small text).
|
|
4
4
|
//
|
|
5
5
|
// Usage: stack-tools text <url...> [--verbose] [--login <email>]
|
|
6
6
|
//
|
|
7
7
|
// --login signs in at /admin/login of the first URL's site first (password from
|
|
8
8
|
// CHECK_PASSWORD), so admin pages can be measured. Use a login on the dev database.
|
|
9
9
|
//
|
|
10
|
-
// Each page is opened on a phone (390 px) and a desktop (1440 px),
|
|
11
|
-
//
|
|
10
|
+
// Each page is opened on a phone (390 px) and a desktop (1440 px), once at 320 px for
|
|
11
|
+
// sideways scroll, and once on the phone with the reader's text size raised to 130, 150
|
|
12
|
+
// and 200% (the browser's default font size, as a phone's text setting does to a page
|
|
13
|
+
// with <meta name="text-scale" content="scale">, and as Chrome's own text size does).
|
|
12
14
|
//
|
|
13
15
|
// Fails (exit 1) on the floors: text under 4.5:1 on a plain background (3:1 from 24 px,
|
|
14
16
|
// 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.
|
|
17
|
+
// on focus), sideways scroll at 320 px; with text at 200% (WCAG 1.4.4): text cut off by
|
|
18
|
+
// a box that doesn't grow, sideways scroll on the phone.
|
|
16
19
|
// Warns on the rules we set ourselves: reading ease under 60 (Gulpease), a sentence over
|
|
17
20
|
// 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
|
|
21
|
+
// a field edge under 3:1, a target under 44 px on the phone, lines over 80 characters;
|
|
22
|
+
// with text at 200%: texts that start to overlap, text shortened with "…" or a line
|
|
23
|
+
// clamp, text that keeps its size (px), no text-scale meta.
|
|
19
24
|
//
|
|
20
25
|
// Text inside an element marked `data-quoted` (a customer's review, the client's own
|
|
21
26
|
// description) is someone else's writing: its words are not measured.
|
|
@@ -82,7 +87,10 @@ function measure() {
|
|
|
82
87
|
const r = el.getBoundingClientRect();
|
|
83
88
|
if (r.width < 1 || r.height < 1)
|
|
84
89
|
return false;
|
|
85
|
-
if (r.right < 0 || r.left >
|
|
90
|
+
if (r.right < 0 || r.left > document.documentElement.clientWidth + 5)
|
|
91
|
+
return false;
|
|
92
|
+
// Skipped by the browser (a closed <details>' answer, content-visibility: hidden).
|
|
93
|
+
if (!el.checkVisibility())
|
|
86
94
|
return false;
|
|
87
95
|
for (let e = el; e; e = e.parentElement) {
|
|
88
96
|
const s = getComputedStyle(e);
|
|
@@ -281,9 +289,190 @@ function measure() {
|
|
|
281
289
|
lines,
|
|
282
290
|
blocks: [...new Set(blocks)],
|
|
283
291
|
quoted,
|
|
284
|
-
overflow: document.documentElement.scrollWidth -
|
|
292
|
+
overflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/** Runs in the page. The first call picks the text elements; later calls measure the
|
|
296
|
+
* same ones, after the text size has changed. */
|
|
297
|
+
function probe(first) {
|
|
298
|
+
const w = window;
|
|
299
|
+
const visible = (el) => {
|
|
300
|
+
const r = el.getBoundingClientRect();
|
|
301
|
+
if (r.width < 1 || r.height < 1)
|
|
302
|
+
return false;
|
|
303
|
+
if (r.right < 0 || r.left > document.documentElement.clientWidth + 5)
|
|
304
|
+
return false;
|
|
305
|
+
// Skipped by the browser (a closed <details>' answer, content-visibility: hidden).
|
|
306
|
+
if (!el.checkVisibility())
|
|
307
|
+
return false;
|
|
308
|
+
for (let e = el; e; e = e.parentElement) {
|
|
309
|
+
const s = getComputedStyle(e);
|
|
310
|
+
if (s.visibility === "hidden" || s.display === "none")
|
|
311
|
+
return false;
|
|
312
|
+
if (Number(s.opacity) < 0.05)
|
|
313
|
+
return false;
|
|
314
|
+
if (e.getAttribute("aria-hidden") === "true")
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
return true;
|
|
318
|
+
};
|
|
319
|
+
if (first || !w.__bigText) {
|
|
320
|
+
const els = new Set();
|
|
321
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
322
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
323
|
+
const el = node.parentElement;
|
|
324
|
+
if (!node.textContent?.trim() || !el)
|
|
325
|
+
continue;
|
|
326
|
+
if (el.closest("svg, script, style, noscript, option"))
|
|
327
|
+
continue;
|
|
328
|
+
if (!els.has(el) && visible(el))
|
|
329
|
+
els.add(el);
|
|
330
|
+
}
|
|
331
|
+
w.__bigText = [...els];
|
|
332
|
+
}
|
|
333
|
+
const clips = (v) => v === "hidden" || v === "clip";
|
|
334
|
+
// innerText is empty for some rendered text (inside a closed <details>...): fall back.
|
|
335
|
+
const textOf = (el) => (el.innerText?.trim() || el.textContent || "")
|
|
336
|
+
.replace(/\s+/g, " ")
|
|
337
|
+
.trim();
|
|
338
|
+
const rows = w.__bigText.map((el) => {
|
|
339
|
+
const lines = [];
|
|
340
|
+
const range = document.createRange();
|
|
341
|
+
for (const node of el.childNodes) {
|
|
342
|
+
if (node.nodeType !== Node.TEXT_NODE || !node.textContent?.trim())
|
|
343
|
+
continue;
|
|
344
|
+
range.selectNodeContents(node);
|
|
345
|
+
for (const r of range.getClientRects())
|
|
346
|
+
if (r.width >= 1 && r.height >= 1)
|
|
347
|
+
lines.push([r.x, r.y + scrollY, r.width, r.height]);
|
|
348
|
+
}
|
|
349
|
+
let clip = 0;
|
|
350
|
+
if (lines.length) {
|
|
351
|
+
const top = Math.min(...lines.map((l) => l[1] - scrollY));
|
|
352
|
+
const bottom = Math.max(...lines.map((l) => l[1] - scrollY + l[3]));
|
|
353
|
+
const left = Math.min(...lines.map((l) => l[0]));
|
|
354
|
+
const right = Math.max(...lines.map((l) => l[0] + l[2]));
|
|
355
|
+
for (let a = el; a && a !== document.body; a = a.parentElement) {
|
|
356
|
+
const s = getComputedStyle(a);
|
|
357
|
+
const y = clips(s.overflowY);
|
|
358
|
+
const x = clips(s.overflowX);
|
|
359
|
+
if (!x && !y)
|
|
360
|
+
continue;
|
|
361
|
+
const r = a.getBoundingClientRect();
|
|
362
|
+
const inTop = r.top + a.clientTop;
|
|
363
|
+
const inLeft = r.left + a.clientLeft;
|
|
364
|
+
const cut = (y && (bottom > inTop + a.clientHeight + 2 || top < inTop - 2)) ||
|
|
365
|
+
(x && (right > inLeft + a.clientWidth + 2 || left < inLeft - 2));
|
|
366
|
+
if (!cut)
|
|
367
|
+
continue;
|
|
368
|
+
const lineClamp = s.webkitLineClamp ??
|
|
369
|
+
"none";
|
|
370
|
+
clip = lineClamp !== "none" || s.textOverflow === "ellipsis" ? 2 : 1;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
text: textOf(el),
|
|
376
|
+
size: parseFloat(getComputedStyle(el).fontSize),
|
|
377
|
+
clip,
|
|
378
|
+
lines,
|
|
379
|
+
};
|
|
380
|
+
});
|
|
381
|
+
// The layout viewport: on a phone innerWidth grows to a page that's too wide.
|
|
382
|
+
const vw = document.documentElement.clientWidth;
|
|
383
|
+
const overflow = document.documentElement.scrollWidth - vw;
|
|
384
|
+
const culprits = [];
|
|
385
|
+
if (overflow > 1) {
|
|
386
|
+
// How far right an element reaches: its box, or its own text when a long word
|
|
387
|
+
// runs out of the box (the box stays put, the page still scrolls).
|
|
388
|
+
const reach = (el) => {
|
|
389
|
+
let right = el.getBoundingClientRect().right;
|
|
390
|
+
// A box that clips its own text (a visually hidden label) holds it.
|
|
391
|
+
if (getComputedStyle(el).overflowX !== "visible")
|
|
392
|
+
return right;
|
|
393
|
+
const range = document.createRange();
|
|
394
|
+
for (const node of el.childNodes)
|
|
395
|
+
if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {
|
|
396
|
+
range.selectNodeContents(node);
|
|
397
|
+
right = Math.max(right, range.getBoundingClientRect().right);
|
|
398
|
+
}
|
|
399
|
+
return right;
|
|
400
|
+
};
|
|
401
|
+
const out = new Map();
|
|
402
|
+
for (const el of document.body.querySelectorAll("*")) {
|
|
403
|
+
const right = reach(el);
|
|
404
|
+
if (right <= vw + 1)
|
|
405
|
+
continue;
|
|
406
|
+
// Inside a box that scrolls or clips on its own (a strip of cards): not the page's.
|
|
407
|
+
let held = false;
|
|
408
|
+
for (let a = el.parentElement; a && a !== document.body; a = a.parentElement)
|
|
409
|
+
if (getComputedStyle(a).overflowX !== "visible" &&
|
|
410
|
+
a.getBoundingClientRect().right <= vw + 1) {
|
|
411
|
+
held = true;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
if (!held)
|
|
415
|
+
out.set(el, right);
|
|
416
|
+
}
|
|
417
|
+
for (const [el, right] of out) {
|
|
418
|
+
if ([...el.children].some((c) => out.has(c)))
|
|
419
|
+
continue;
|
|
420
|
+
const cls = (el.getAttribute("class") ?? "").split(/\s+/).filter(Boolean);
|
|
421
|
+
const text = textOf(el);
|
|
422
|
+
culprits.push(`${el.tagName.toLowerCase()}${cls.length ? `.${cls.slice(0, 2).join(".")}` : ""}` +
|
|
423
|
+
`${text ? ` "${text.slice(0, 24)}"` : ""} to ${Math.round(right)} px`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
rows,
|
|
428
|
+
root: parseFloat(getComputedStyle(document.documentElement).fontSize),
|
|
429
|
+
meta: !!document.querySelector('meta[name="text-scale" i][content="scale" i]'),
|
|
430
|
+
overflow,
|
|
431
|
+
culprits: [...new Set(culprits)],
|
|
285
432
|
};
|
|
286
433
|
}
|
|
434
|
+
/** Pairs of texts whose lines cross by more than a sliver. A clipped text is left out:
|
|
435
|
+
* its hidden lines still have boxes (a clamped title's third line under the facts). */
|
|
436
|
+
function overlaps(p) {
|
|
437
|
+
const pairs = new Set();
|
|
438
|
+
const all = p.rows.flatMap((row, i) => row.clip ? [] : row.lines.map((l) => ({ i, l })));
|
|
439
|
+
all.sort((a, b) => a.l[1] - b.l[1]);
|
|
440
|
+
for (let a = 0; a < all.length; a++)
|
|
441
|
+
for (let b = a + 1; b < all.length; b++) {
|
|
442
|
+
const [x1, y1, w1, h1] = all[a].l;
|
|
443
|
+
const [x2, y2, w2, h2] = all[b].l;
|
|
444
|
+
if (y2 >= y1 + h1)
|
|
445
|
+
break;
|
|
446
|
+
if (all[a].i === all[b].i)
|
|
447
|
+
continue;
|
|
448
|
+
const dx = Math.min(x1 + w1, x2 + w2) - Math.max(x1, x2);
|
|
449
|
+
const dy = Math.min(y1 + h1, y2 + h2) - Math.max(y1, y2);
|
|
450
|
+
// Line boxes of stacked lines touch: a third of the shorter line is a real overlap.
|
|
451
|
+
if (dx > 2 && dy > Math.min(h1, h2) / 3)
|
|
452
|
+
pairs.add([all[a].i, all[b].i].sort((m, n) => m - n).join(","));
|
|
453
|
+
}
|
|
454
|
+
return pairs;
|
|
455
|
+
}
|
|
456
|
+
const scales = [1.3, 1.5, 2];
|
|
457
|
+
async function bigText(page) {
|
|
458
|
+
const cdp = await page.context().newCDPSession(page);
|
|
459
|
+
const base = await page.evaluate(probe, true);
|
|
460
|
+
const baseOverlaps = overlaps(base);
|
|
461
|
+
const runs = [];
|
|
462
|
+
for (const scale of scales) {
|
|
463
|
+
await cdp.send("Page.setFontSizes", {
|
|
464
|
+
fontSizes: { standard: Math.round(16 * scale), fixed: Math.round(13 * scale) },
|
|
465
|
+
});
|
|
466
|
+
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => setTimeout(r, 150))));
|
|
467
|
+
const p = await page.evaluate(probe, false);
|
|
468
|
+
runs.push({
|
|
469
|
+
scale,
|
|
470
|
+
p,
|
|
471
|
+
overlaps: [...overlaps(p)].filter((k) => !baseOverlaps.has(k)),
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
return { base, runs };
|
|
475
|
+
}
|
|
287
476
|
// --- The words (Italian) ---
|
|
288
477
|
const words = (s) => s.match(/[\p{L}\p{N}][\p{L}\p{N}'’.-]*[\p{L}\p{N}]|[\p{L}\p{N}]/gu) ?? [];
|
|
289
478
|
const letters = (s) => (s.match(/\p{L}/gu) ?? []).length;
|
|
@@ -474,12 +663,64 @@ for (const url of urls) {
|
|
|
474
663
|
isMobile: true,
|
|
475
664
|
hasTouch: true,
|
|
476
665
|
});
|
|
477
|
-
|
|
666
|
+
// The layout viewport (clientWidth), not innerWidth: on a phone a page wider than the
|
|
667
|
+
// screen widens innerWidth to the page, and the difference reads 0.
|
|
668
|
+
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
|
478
669
|
await context.close();
|
|
479
670
|
if (overflow > 1) {
|
|
480
671
|
failures++;
|
|
481
672
|
console.log(` ${"narrow 320".padEnd(15)}FAIL scrolls sideways by ${overflow} px`);
|
|
482
673
|
}
|
|
674
|
+
// The reader's text size, raised: does the phone layout hold?
|
|
675
|
+
{
|
|
676
|
+
const { context, page } = await open(url, screens["phone 390"]);
|
|
677
|
+
const { base, runs } = await bigText(page);
|
|
678
|
+
await context.close();
|
|
679
|
+
const fail = (note) => (failures++, `FAIL ${note}`);
|
|
680
|
+
const warn = (note) => (warnings++, `warn ${note}`);
|
|
681
|
+
const notes = [];
|
|
682
|
+
const top = runs[runs.length - 1];
|
|
683
|
+
const pct = (s) => `${Math.round(s * 100)}%`;
|
|
684
|
+
// From which size a problem starts, and the run to show it with (the biggest).
|
|
685
|
+
const first = (has) => {
|
|
686
|
+
const hit = runs.filter(has);
|
|
687
|
+
return hit.length
|
|
688
|
+
? { from: pct(hit[0].scale), run: hit[hit.length - 1] }
|
|
689
|
+
: null;
|
|
690
|
+
};
|
|
691
|
+
const since = (from) => (from === pct(top.scale) ? "" : ` (from ${from})`);
|
|
692
|
+
const label = (i) => `"${short(base.rows[i].text, 24)}"`;
|
|
693
|
+
// Only what the bigger text breaks: a clamp or an overlap there at 100% is a choice.
|
|
694
|
+
const newly = (r, kind) => r.p.rows.flatMap((row, i) => row.clip === kind && base.rows[i].clip === 0 ? [i] : []);
|
|
695
|
+
if (!base.meta)
|
|
696
|
+
notes.push(warn('no <meta name="text-scale" content="scale">: phones keep this page at their default text size'));
|
|
697
|
+
if (top.p.root < base.root * 1.25)
|
|
698
|
+
notes.push(warn(`the page fixes its root font size (${base.root} px at 100%, ${top.p.root} px at ${pct(top.scale)}): nothing in rem follows the reader`));
|
|
699
|
+
const wide = first((r) => r.p.overflow > 1);
|
|
700
|
+
if (wide)
|
|
701
|
+
notes.push(fail(`scrolls sideways by ${wide.run.p.overflow} px at ${pct(wide.run.scale)}${since(wide.from)}: ${list(wide.run.p.culprits, (c) => c)}`));
|
|
702
|
+
const cut = first((r) => newly(r, 1).length > 0);
|
|
703
|
+
if (cut) {
|
|
704
|
+
const rows = newly(cut.run, 1);
|
|
705
|
+
notes.push(fail(`${rows.length} text(s) cut off by a box that doesn't grow${since(cut.from)}: ${list(rows, label)}`));
|
|
706
|
+
}
|
|
707
|
+
const clamped = first((r) => newly(r, 2).length > 0);
|
|
708
|
+
if (clamped) {
|
|
709
|
+
const rows = newly(clamped.run, 2);
|
|
710
|
+
notes.push(warn(`${rows.length} text(s) shortened with "…" or a line clamp${since(clamped.from)}: ${list(rows, label, 2)}`));
|
|
711
|
+
}
|
|
712
|
+
const crossed = first((r) => r.overlaps.length > 0);
|
|
713
|
+
if (crossed)
|
|
714
|
+
notes.push(warn(`${crossed.run.overlaps.length} pair(s) of texts overlap${since(crossed.from)}: ${list(crossed.run.overlaps, (k) => k.split(",").map((i) => label(Number(i))).join(" on "), 2)}`));
|
|
715
|
+
const chars = base.rows.reduce((a, r) => a + r.text.length, 0) || 1;
|
|
716
|
+
const fixed = base.rows.flatMap((row, i) => top.p.rows[i] && top.p.rows[i].size < row.size * 1.25 ? [i] : []);
|
|
717
|
+
const fixedShare = Math.round((100 * fixed.reduce((a, i) => a + base.rows[i].text.length, 0)) / chars);
|
|
718
|
+
if (fixed.length && fixedShare >= 1)
|
|
719
|
+
notes.push(warn(`${fixedShare}% of the text keeps its size (set in px?): ${list(fixed, label, 2)}`));
|
|
720
|
+
console.log(` ${"text 130-200%".padEnd(15)}${base.rows.length} texts on the phone${notes.length ? "" : ": holds at 200%"}`);
|
|
721
|
+
for (const note of notes)
|
|
722
|
+
console.log(` ${pad}${note}`);
|
|
723
|
+
}
|
|
483
724
|
}
|
|
484
725
|
await browser.close();
|
|
485
726
|
console.log(`\n${failures} failure(s), ${warnings} warning(s) on ${urls.length} page(s).`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a.incantalupo/web-tools",
|
|
3
|
-
"version": "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
|
|
3
|
+
"version": "0.2.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.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"stack-tools": "dist/cli.js"
|
|
@@ -12,11 +12,6 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": ["dist", "README.md"],
|
|
14
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
15
|
"scripts": {
|
|
21
16
|
"build": "rm -rf dist && tsc -p tsconfig.json && chmod +x dist/cli.js",
|
|
22
17
|
"check": "tsc -p tsconfig.json --noEmit",
|