@uselazuli/cli 0.0.0-stage → 1.0.2
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 +120 -0
- package/LICENSE +21 -0
- package/README.md +202 -2
- package/agents/lazuli-design-reviewer.md +30 -0
- package/agents/lazuli-first-look.md +22 -0
- package/agents/lazuli-task-tester.md +25 -0
- package/bin/lazuli.mjs +747 -0
- package/package.json +11 -4
- package/rules/accessibility/HYPOTHESES.md +8 -0
- package/rules/accessibility/_area.yaml +7 -0
- package/rules/accessibility/operable.yaml +100 -0
- package/rules/accessibility/perceivable.yaml +153 -0
- package/rules/accessibility/robust.yaml +24 -0
- package/rules/accessibility/understandable.yaml +72 -0
- package/rules/color/HYPOTHESES.md +27 -0
- package/rules/color/_area.yaml +10 -0
- package/rules/color/adapt.yaml +183 -0
- package/rules/color/create.yaml +259 -0
- package/rules/color/review.yaml +215 -0
- package/rules/color/signal.yaml +196 -0
- package/rules/content/HYPOTHESES.md +19 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +378 -0
- package/rules/content/voice.yaml +144 -0
- package/rules/content/writing.yaml +202 -0
- package/rules/data/HYPOTHESES.md +11 -0
- package/rules/data/_area.yaml +7 -0
- package/rules/data/charts.yaml +189 -0
- package/rules/data/dashboards.yaml +141 -0
- package/rules/data/review.yaml +159 -0
- package/rules/graphic/HYPOTHESES.md +18 -0
- package/rules/graphic/_area.yaml +8 -0
- package/rules/graphic/identity.yaml +141 -0
- package/rules/graphic/pieces.yaml +164 -0
- package/rules/graphic/review.yaml +271 -0
- package/rules/graphic/symbol.yaml +141 -0
- package/rules/motion/HYPOTHESES.md +19 -0
- package/rules/motion/_area.yaml +7 -0
- package/rules/motion/micro.yaml +143 -0
- package/rules/motion/review.yaml +347 -0
- package/rules/motion/transitions.yaml +169 -0
- package/rules/typography/HYPOTHESES.md +12 -0
- package/rules/typography/_area.yaml +8 -0
- package/rules/typography/adapt.yaml +45 -0
- package/rules/typography/create.yaml +126 -0
- package/rules/typography/review.yaml +127 -0
- package/rules/ui/HYPOTHESES.md +23 -0
- package/rules/ui/_area.yaml +9 -0
- package/rules/ui/compose.yaml +246 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +400 -0
- package/rules/ui/states.yaml +257 -0
- package/rules/ux/HYPOTHESES.md +13 -0
- package/rules/ux/_area.yaml +8 -0
- package/rules/ux/flows.yaml +164 -0
- package/rules/ux/forms.yaml +142 -0
- package/rules/ux/review.yaml +186 -0
- package/skills/lazuli/SKILL.md +183 -0
- package/skills/lazuli/procedures/create.md +29 -0
- package/skills/lazuli/procedures/explain-decisions.md +22 -0
- package/skills/lazuli/procedures/improve.md +30 -0
- package/skills/lazuli/procedures/remember-this.md +41 -0
- package/skills/lazuli/procedures/review-design.md +36 -0
- package/skills/lazuli/procedures/show-options.md +33 -0
- package/skills/lazuli-accessibility-check/SKILL.md +68 -0
- package/skills/lazuli-color-context-and-culture/SKILL.md +53 -0
- package/skills/lazuli-color-context-and-culture/references/sectors.md +26 -0
- package/skills/lazuli-color-palette-by-intent/SKILL.md +54 -0
- package/skills/lazuli-color-palette-by-intent/references/intent-chords.md +51 -0
- package/skills/lazuli-color-screen-review/SKILL.md +51 -0
- package/skills/lazuli-color-states-and-signals/SKILL.md +53 -0
- package/skills/lazuli-content-interface-writing/SKILL.md +53 -0
- package/skills/lazuli-content-voice/SKILL.md +40 -0
- package/skills/lazuli-data-charts-and-dashboards/SKILL.md +59 -0
- package/skills/lazuli-graphic-derived-pieces/SKILL.md +40 -0
- package/skills/lazuli-graphic-derived-pieces/references/piece-template.html +24 -0
- package/skills/lazuli-graphic-identity/SKILL.md +45 -0
- package/skills/lazuli-motion-micro-and-transitions/SKILL.md +49 -0
- package/skills/lazuli-typography-choose-and-pair/SKILL.md +50 -0
- package/skills/lazuli-typography-screen-review/SKILL.md +51 -0
- package/skills/lazuli-ui-composition/SKILL.md +42 -0
- package/skills/lazuli-ui-composition/references/option-template.html +34 -0
- package/skills/lazuli-ui-layout-review/SKILL.md +47 -0
- package/skills/lazuli-ui-states-and-system/SKILL.md +54 -0
- package/skills/lazuli-ux-flows-and-forms/SKILL.md +51 -0
- package/skills/lazuli-ux-task-test/SKILL.md +44 -0
- package/src/browser.mjs +162 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +463 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +160 -0
- package/src/commands/draft-memo.mjs +162 -0
- package/src/commands/hooks.mjs +345 -0
- package/src/commands/install-hooks.mjs +120 -0
- package/src/commands/install.mjs +132 -0
- package/src/commands/list-rules.mjs +49 -0
- package/src/commands/map-page.mjs +594 -0
- package/src/commands/record-answers.mjs +79 -0
- package/src/commands/record-log.mjs +325 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +227 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +391 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +566 -0
- package/src/measure/chart-read.mjs +401 -0
- package/src/measure/chart.mjs +264 -0
- package/src/measure/coherence.mjs +145 -0
- package/src/measure/color.mjs +86 -0
- package/src/measure/content.mjs +82 -0
- package/src/measure/cvd.mjs +24 -0
- package/src/measure/extreme.mjs +241 -0
- package/src/measure/forms.mjs +150 -0
- package/src/measure/in-page/a11y.js +522 -0
- package/src/measure/in-page/color.js +348 -0
- package/src/measure/in-page/composition.js +1496 -0
- package/src/measure/in-page/contrast.js +15 -0
- package/src/measure/in-page/cvd.js +173 -0
- package/src/measure/in-page/extreme.js +377 -0
- package/src/measure/in-page/frames.js +781 -0
- package/src/measure/in-page/look.js +28 -0
- package/src/measure/in-page/motion-probe.js +171 -0
- package/src/measure/in-page/style.js +107 -0
- package/src/measure/in-page/svg-strokes.js +112 -0
- package/src/measure/in-page/svg-uses.js +50 -0
- package/src/measure/in-page/symbol.js +123 -0
- package/src/measure/in-page/type.js +269 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +100 -0
- package/src/measure/motion.mjs +509 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +253 -0
- package/src/measure/rhythm.mjs +81 -0
- package/src/measure/signature.mjs +65 -0
- package/src/measure/states.mjs +240 -0
- package/src/measure/style.mjs +13 -0
- package/src/measure/symbol.mjs +268 -0
- package/src/measure/terms.mjs +153 -0
- package/src/measure/tiles.mjs +20 -0
- package/src/measure/timeline.mjs +621 -0
- package/src/measure/type.mjs +167 -0
- package/src/measure/weight.mjs +18 -0
- package/src/private-strings.mjs +81 -0
- package/src/project/blind.mjs +70 -0
- package/src/project/edits.mjs +154 -0
- package/src/project/gate.mjs +168 -0
- package/src/project/lazuli-md.mjs +521 -0
- package/src/project/log.mjs +335 -0
- package/src/project/match.mjs +200 -0
- package/src/project/records.mjs +380 -0
- package/src/project/tasks.mjs +153 -0
- package/src/report/evaluate.mjs +27 -0
- package/src/report/evaluators/a11y.mjs +227 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +133 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +87 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +103 -0
- package/src/report/evaluators/motion.mjs +280 -0
- package/src/report/evaluators/piece.mjs +69 -0
- package/src/report/evaluators/rhythm.mjs +99 -0
- package/src/report/evaluators/states.mjs +39 -0
- package/src/report/evaluators/style.mjs +35 -0
- package/src/report/evaluators/symbol.mjs +110 -0
- package/src/report/evaluators/terms.mjs +49 -0
- package/src/report/evaluators/type.mjs +166 -0
- package/src/report/evaluators/weight.mjs +51 -0
- package/src/report/evidence.mjs +4 -0
- package/src/report/finding.mjs +11 -0
- package/src/report/format.mjs +215 -0
- package/src/rules/hypotheses.mjs +28 -0
- package/src/rules/load.mjs +274 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +220 -0
- package/templates/LAZULI.md +88 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Evaluated inside the page as one expression: an IIFE that returns { lin, lum, ratio } over { r, g, b } in
|
|
2
|
+
// 0 to 255 (WCAG 2 relative luminance and contrast ratio). Interpolated as an argument value by the color and
|
|
3
|
+
// symbol measurers, so it runs under a page CSP with no eval. Plain script, no imports, no trailing semicolon.
|
|
4
|
+
(() => {
|
|
5
|
+
const lin = (v) => {
|
|
6
|
+
v /= 255;
|
|
7
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
8
|
+
};
|
|
9
|
+
const lum = ({ r, g, b }) => 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
10
|
+
const ratio = (x, y) => {
|
|
11
|
+
const [hi, lo] = [lum(x), lum(y)].sort((p, q) => q - p);
|
|
12
|
+
return (hi + 0.05) / (lo + 0.05);
|
|
13
|
+
};
|
|
14
|
+
return { lin, lum, ratio };
|
|
15
|
+
})()
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Evaluated as one expression: an IIFE that returns the color library of the chart measure,
|
|
2
|
+
// { VIEWS, SEVERITY, MAX_SERIES, toLab, deltaE, simulate, saturated, simulateImage, bucketsOf }, over { r, g, b }
|
|
3
|
+
// in 0 to 255 and { width, height, data } images (RGBA bytes). Interpolated as an argument value into the
|
|
4
|
+
// analysis page and loaded in Node with vm.runInNewContext (src/measure/cvd.mjs), so the sheet and the
|
|
5
|
+
// distances come from one model. Plain script, no imports, no trailing semicolon.
|
|
6
|
+
//
|
|
7
|
+
// Color vision deficiency: Machado, Oliveira and Fernandes (2009), "A Physiologically-based Model for
|
|
8
|
+
// Simulation of Color Vision Deficiency", IEEE TVCG 15(6). Matrices copied from Table 1 of the authors' page,
|
|
9
|
+
// https://www.inf.ufrgs.br/~oliveira/pubs_files/CVD_Simulation/CVD_Simulation.html (opened 2026-11-26), at
|
|
10
|
+
// severity 1.0, which the page calls "the highest severity or a case of dichromacy": its Protanomaly,
|
|
11
|
+
// Deuteranomaly and Tritanomaly columns at 1.0, named here protanopia, deuteranopia and tritanopia. The page
|
|
12
|
+
// names no color space (it multiplies "the reference RGB color"); the matrices are applied in
|
|
13
|
+
// linear sRGB, (our claim). The result is clamped to 0 to 1 in linear, then encoded and rounded to 0 to 255.
|
|
14
|
+
//
|
|
15
|
+
// Conversions: CSS Color 4 (W3C Candidate Recommendation Draft, 23 November 2026), section 19
|
|
16
|
+
// "Sample code for Color Conversions", https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
17
|
+
// (opened 2026-11-26): the sRGB transfer functions (0.04045), linear sRGB to XYZ D65, Bradford D65 to D50, the D50 white and XYZ to Lab.
|
|
18
|
+
// Delta E is CIE 1976 (Euclidean distance in Lab). Grayscale uses, on purpose, the WCAG 2 relative luminance
|
|
19
|
+
// of src/measure/in-page/contrast.js (0.03928), inlined, so the gray matches the contrast checks.
|
|
20
|
+
//
|
|
21
|
+
// `saturated` copies `hsl` of src/measure/in-page/color.js (rounded HSL in percent) and the predicate of
|
|
22
|
+
// src/report/evaluators/color.mjs (PA4, color H2: saturation above minSaturation, lightness from minLightness
|
|
23
|
+
// to maxLightness); those two files are the source of truth (tested in tests/cvd.test.mjs).
|
|
24
|
+
// `bucketsOf` quantizes as the color measurer does (4 bits per channel, mean real color per bucket).
|
|
25
|
+
(() => {
|
|
26
|
+
const VIEWS = ["normal", "protanopia", "deuteranopia", "tritanopia", "grayscale"];
|
|
27
|
+
// The full deficiency, the strongest case of the model (a definition).
|
|
28
|
+
const SEVERITY = 1;
|
|
29
|
+
// Equals MAX_SERIES of src/measure/chart-read.mjs (sampling limit; a test checks they are equal).
|
|
30
|
+
const MAX_SERIES = 20;
|
|
31
|
+
const MATRICES = {
|
|
32
|
+
protanopia: [
|
|
33
|
+
[0.152286, 1.052583, -0.204868],
|
|
34
|
+
[0.114503, 0.786281, 0.099216],
|
|
35
|
+
[-0.003882, -0.048116, 1.051998],
|
|
36
|
+
],
|
|
37
|
+
deuteranopia: [
|
|
38
|
+
[0.367322, 0.860646, -0.227968],
|
|
39
|
+
[0.280085, 0.672501, 0.047413],
|
|
40
|
+
[-0.01182, 0.04294, 0.968881],
|
|
41
|
+
],
|
|
42
|
+
tritanopia: [
|
|
43
|
+
[1.255528, -0.076749, -0.178779],
|
|
44
|
+
[-0.078411, 0.930809, 0.147602],
|
|
45
|
+
[0.004733, 0.691367, 0.3039],
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const multiply = (M, v) => M.map((row) => row[0] * v[0] + row[1] * v[1] + row[2] * v[2]);
|
|
50
|
+
|
|
51
|
+
// CSS Color 4 lin_sRGB and gam_sRGB.
|
|
52
|
+
const linear = (val) => {
|
|
53
|
+
const sign = val < 0 ? -1 : 1;
|
|
54
|
+
const abs = Math.abs(val);
|
|
55
|
+
if (abs <= 0.04045) return val / 12.92;
|
|
56
|
+
return sign * Math.pow((abs + 0.055) / 1.055, 2.4);
|
|
57
|
+
};
|
|
58
|
+
const gamma = (val) => {
|
|
59
|
+
const sign = val < 0 ? -1 : 1;
|
|
60
|
+
const abs = Math.abs(val);
|
|
61
|
+
if (abs > 0.0031308) return sign * (1.055 * Math.pow(abs, 1 / 2.4) - 0.055);
|
|
62
|
+
return 12.92 * val;
|
|
63
|
+
};
|
|
64
|
+
const toLinear = ({ r, g, b }) => [r, g, b].map((v) => linear(v / 255));
|
|
65
|
+
const byte = (v) => Math.min(255, Math.max(0, Math.round(v)));
|
|
66
|
+
const fromLinear = (rgb) => {
|
|
67
|
+
const [r, g, b] = rgb.map((v) => byte(255 * gamma(Math.min(1, Math.max(0, v)))));
|
|
68
|
+
return { r, g, b };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// CSS Color 4 lin_sRGB_to_XYZ, D65_to_D50, D50 and XYZ_to_Lab.
|
|
72
|
+
const SRGB_TO_XYZ = [
|
|
73
|
+
[506752 / 1228815, 87881 / 245763, 12673 / 70218],
|
|
74
|
+
[87098 / 409605, 175762 / 245763, 12673 / 175545],
|
|
75
|
+
[7918 / 409605, 87881 / 737289, 1001167 / 1053270],
|
|
76
|
+
];
|
|
77
|
+
const D65_TO_D50 = [
|
|
78
|
+
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
|
|
79
|
+
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
80
|
+
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371],
|
|
81
|
+
];
|
|
82
|
+
const D50 = [0.3457 / 0.3585, 1.0, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
83
|
+
const EPSILON = 216 / 24389;
|
|
84
|
+
const KAPPA = 24389 / 27;
|
|
85
|
+
const toLab = (rgb) => {
|
|
86
|
+
const xyz = multiply(D65_TO_D50, multiply(SRGB_TO_XYZ, toLinear(rgb))).map((v, i) => v / D50[i]);
|
|
87
|
+
const f = xyz.map((v) => (v > EPSILON ? Math.cbrt(v) : (KAPPA * v + 16) / 116));
|
|
88
|
+
return { L: 116 * f[1] - 16, a: 500 * (f[0] - f[1]), b: 200 * (f[1] - f[2]) };
|
|
89
|
+
};
|
|
90
|
+
const deltaE = (x, y) => {
|
|
91
|
+
const p = toLab(x), q = toLab(y);
|
|
92
|
+
return Math.hypot(p.L - q.L, p.a - q.a, p.b - q.b);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// WCAG 2 relative luminance (src/measure/in-page/contrast.js) and the sRGB gray that has it.
|
|
96
|
+
const wcagLin = (v) => {
|
|
97
|
+
v /= 255;
|
|
98
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
|
99
|
+
};
|
|
100
|
+
const lum = ({ r, g, b }) => 0.2126 * wcagLin(r) + 0.7152 * wcagLin(g) + 0.0722 * wcagLin(b);
|
|
101
|
+
const grayOf = (y) => {
|
|
102
|
+
const v = byte(255 * (y <= 0.03928 / 12.92 ? y * 12.92 : 1.055 * Math.pow(y, 1 / 2.4) - 0.055));
|
|
103
|
+
return { r: v, g: v, b: v };
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const simulate = (rgb, view) => {
|
|
107
|
+
if (view === "normal") return { r: byte(rgb.r), g: byte(rgb.g), b: byte(rgb.b) };
|
|
108
|
+
if (view === "grayscale") return grayOf(lum(rgb));
|
|
109
|
+
const M = MATRICES[view];
|
|
110
|
+
if (!M) throw new Error(`unknown view: ${view}`);
|
|
111
|
+
return fromLinear(multiply(M, toLinear(rgb)));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Copy of `hsl` in src/measure/in-page/color.js (source of truth).
|
|
115
|
+
const hsl = ({ r, g, b }) => {
|
|
116
|
+
const [R, G, B] = [r, g, b].map((v) => v / 255);
|
|
117
|
+
const M = Math.max(R, G, B), m = Math.min(R, G, B), l = (M + m) / 2;
|
|
118
|
+
let h = 0, s = 0;
|
|
119
|
+
if (M !== m) {
|
|
120
|
+
const d = M - m;
|
|
121
|
+
s = l > 0.5 ? d / (2 - M - m) : d / (M + m);
|
|
122
|
+
h = M === R ? (G - B) / d + (G < B ? 6 : 0) : M === G ? (B - R) / d + 2 : (R - G) / d + 4;
|
|
123
|
+
h *= 60;
|
|
124
|
+
}
|
|
125
|
+
return { h: Math.round(h), s: Math.round(s * 100), l: Math.round(l * 100) };
|
|
126
|
+
};
|
|
127
|
+
const saturated = (rgb, { minSaturation, minLightness, maxLightness }) => {
|
|
128
|
+
const { s, l } = hsl(rgb);
|
|
129
|
+
return s > minSaturation && l >= minLightness && l <= maxLightness;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const simulateImage = (img, view) => {
|
|
133
|
+
const src = img.data;
|
|
134
|
+
const data = new Uint8ClampedArray(src.length);
|
|
135
|
+
const cache = new Map();
|
|
136
|
+
for (let i = 0; i < src.length; i += 4) {
|
|
137
|
+
const key = (src[i] << 16) | (src[i + 1] << 8) | src[i + 2];
|
|
138
|
+
let c = cache.get(key);
|
|
139
|
+
if (!c) cache.set(key, (c = simulate({ r: src[i], g: src[i + 1], b: src[i + 2] }, view)));
|
|
140
|
+
data[i] = c.r;
|
|
141
|
+
data[i + 1] = c.g;
|
|
142
|
+
data[i + 2] = c.b;
|
|
143
|
+
data[i + 3] = src[i + 3];
|
|
144
|
+
}
|
|
145
|
+
return { width: img.width, height: img.height, data };
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const hex = ({ r, g, b }) => "#" + [r, g, b].map((v) => byte(v).toString(16).padStart(2, "0")).join("");
|
|
149
|
+
const bucketsOf = (img, { minShare }) => {
|
|
150
|
+
const px = img.data;
|
|
151
|
+
const buckets = new Map();
|
|
152
|
+
let total = 0;
|
|
153
|
+
for (let i = 0; i < px.length; i += 4) {
|
|
154
|
+
const key = ((px[i] >> 4) << 8) | ((px[i + 1] >> 4) << 4) | (px[i + 2] >> 4);
|
|
155
|
+
let b = buckets.get(key);
|
|
156
|
+
if (!b) buckets.set(key, (b = { key, n: 0, r: 0, g: 0, b: 0 }));
|
|
157
|
+
b.n++;
|
|
158
|
+
b.r += px[i];
|
|
159
|
+
b.g += px[i + 1];
|
|
160
|
+
b.b += px[i + 2];
|
|
161
|
+
total++;
|
|
162
|
+
}
|
|
163
|
+
if (total === 0) return [];
|
|
164
|
+
const sorted = [...buckets.values()].sort((x, y) => y.n - x.n || x.key - y.key);
|
|
165
|
+
return sorted
|
|
166
|
+
.slice(1)
|
|
167
|
+
.filter((b) => b.n / total >= minShare)
|
|
168
|
+
.slice(0, MAX_SERIES)
|
|
169
|
+
.map((b) => ({ hex: hex({ r: b.r / b.n, g: b.g / b.n, b: b.b / b.n }), share: b.n / total }));
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return { VIEWS, SEVERITY, MAX_SERIES, toLab, deltaE, simulate, saturated, simulateImage, bucketsOf };
|
|
173
|
+
})()
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
// Evaluated inside a case page as one function expression, (composition, defs) => ({ tag, inject, read }), where
|
|
2
|
+
// composition is the value of in-page/composition.js and defs the definitions of src/measure/cases.mjs
|
|
3
|
+
// (EXTREME_DEFS); compose it as `(${extreme})(${composition}, ${JSON.stringify(EXTREME_DEFS)})`. Plain script,
|
|
4
|
+
// no imports, no trailing semicolon. Case pages run no page script; this library is our own DOM change inside
|
|
5
|
+
// the case page only: it never clicks, focuses, types, selects or submits, and sends nothing.
|
|
6
|
+
//
|
|
7
|
+
// Kept elements are those the composition walk keeps (read "seen", keepPinned) outside DECORATIVE (aria-hidden)
|
|
8
|
+
// subtrees: hidden, clipped, off-page and decorative content is never read, changed or reported.
|
|
9
|
+
// tag(): data-lazuli-x on body and every element in it, a sequential index in document order; returns the count.
|
|
10
|
+
// inject(kind, params) -> { lists, added, shortLists, cut, removed } for kind "base", "growth", "long-text",
|
|
11
|
+
// "empty", "one", "many". shortLists: the lists many filled with fewer than MANY_ITEMS items. removed lists the data-lazuli-x of every element removed, descendants included. The k-th copy of an
|
|
12
|
+
// item (many) has its data-lazuli-x and those of its descendants rewritten to <original>~c<k> and its id
|
|
13
|
+
// attributes removed, so every copy stays apart and is compared through its original. The caller runs
|
|
14
|
+
// the at-rest walk again (restStill) before read().
|
|
15
|
+
// read() -> { overflowX, clippedX, texts: { id, selector, text, spills, cut, whole, bleeds, pastRight, right }[], kept, overlaps,
|
|
16
|
+
// rectsCut, away, fonts, sheets, brokenImages }. overflowX: how far the page scrolls sideways, null when the
|
|
17
|
+
// viewport hides its sideways overflow (html, or body when html is visible, has overflow-x hidden or clip, as
|
|
18
|
+
// composition reads it); clippedX: on such a page, how far the content runs past the clipped right edge, else
|
|
19
|
+
// null. whole: every line box of the text was read for overlap. bleeds:
|
|
20
|
+
// the text's box (its element's box joined with its line boxes) is partly in the viewport and crosses its left
|
|
21
|
+
// or right edge by more than ALIGN_PX, on a page that does not scroll sideways (the gate of composition's bleeds); pastRight: that box's right edge passes the viewport by more than ALIGN_PX; right: that edge in px. away: the
|
|
22
|
+
// tagged text elements the walk did not keep whose every line box lies outside the padding box of a hidden or
|
|
23
|
+
// clip ancestor, walked by containing block. fonts: the font faces loaded, loading or failed; sheets: the
|
|
24
|
+
// linked stylesheets and how many rules each holds; brokenImages: the ids of images that failed.
|
|
25
|
+
(composition, defs) => {
|
|
26
|
+
const {
|
|
27
|
+
SLACK_PX, ALIGN_PX, MANY_ITEMS, LIST_SELECTOR, NOT_LIST, REPEATED_MIN, LABEL_SCOPE, HEADING_SCOPE, DECORATIVE, INLINE_ITEMS,
|
|
28
|
+
LONG_LABEL, LONG_HEADING, LONG_TEXT, GROWTH_FILL, MAX_LISTS, MAX_CLONE_ELEMENTS, MAX_RECTS,
|
|
29
|
+
} = defs;
|
|
30
|
+
const ATTR = "data-lazuli-x";
|
|
31
|
+
const COPY = "~c";
|
|
32
|
+
const INPUT_BUTTONS = new Set(["button", "submit", "reset"]);
|
|
33
|
+
const CLIPS = new Set(["hidden", "clip"]);
|
|
34
|
+
const SCROLLS = new Set(["auto", "scroll", "overlay"]);
|
|
35
|
+
|
|
36
|
+
const INLINE = new Set(INLINE_ITEMS);
|
|
37
|
+
const keptEls = () => composition({ read: "seen", keepPinned: true }).filter((el) => !el.closest(DECORATIVE));
|
|
38
|
+
const idOf = (el) => el.getAttribute(ATTR);
|
|
39
|
+
const ownTexts = (el) => [...el.childNodes].filter((n) => n.nodeType === 3 && /\S/.test(n.nodeValue));
|
|
40
|
+
const isInputButton = (el) => el.tagName === "INPUT" && INPUT_BUTTONS.has((el.getAttribute("type") || "").toLowerCase());
|
|
41
|
+
const collapse = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
|
42
|
+
const byId = (a, b) => a.localeCompare(b, "en", { numeric: true });
|
|
43
|
+
// The same selector words the composition readers use.
|
|
44
|
+
const selectorOf = (el) => {
|
|
45
|
+
const tag = el.tagName.toLowerCase();
|
|
46
|
+
if (el.id) return `${tag}#${CSS.escape(el.id)}`;
|
|
47
|
+
const first = (el.getAttribute("class") || "").split(/\s+/).find(Boolean);
|
|
48
|
+
if (first) return `${tag}.${CSS.escape(first)}`;
|
|
49
|
+
const block = el.getAttribute("data-block");
|
|
50
|
+
return block ? `${tag}[data-block="${block}"]` : tag;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const tag = () => {
|
|
54
|
+
let i = 0;
|
|
55
|
+
for (const el of [document.body, ...document.body.querySelectorAll("*")]) el.setAttribute(ATTR, String(i++));
|
|
56
|
+
return i;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// The text plus a space plus GROWTH_FILL words until the length reaches ceil(length * growth).
|
|
60
|
+
const grow = (text, growth) => {
|
|
61
|
+
const target = Math.ceil(text.length * growth);
|
|
62
|
+
let out = text;
|
|
63
|
+
for (let i = 0; out.length < target; i++) out += ` ${GROWTH_FILL[i % GROWTH_FILL.length]}`;
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const removedIds = (el) => [el, ...el.querySelectorAll(`[${ATTR}]`)].map(idOf).filter((id) => id !== null);
|
|
68
|
+
|
|
69
|
+
// Lists: LIST_SELECTOR, or an element with REPEATED_MIN or more kept element children sharing tag and class
|
|
70
|
+
// list (body excluded: its children are the page, not items); kept, outside NOT_LIST; a list inside an item of
|
|
71
|
+
// an earlier list is part of that item. Items are block-level: a child whose computed display is in
|
|
72
|
+
// INLINE_ITEMS is never an item. The first MAX_LISTS in document order.
|
|
73
|
+
const findLists = (kept, keptSet, cut) => {
|
|
74
|
+
const found = [];
|
|
75
|
+
for (const el of kept) {
|
|
76
|
+
if (el.closest(NOT_LIST)) continue;
|
|
77
|
+
const items = [...el.children].filter((c) => keptSet.has(c) && !INLINE.has(getComputedStyle(c).display));
|
|
78
|
+
if (items.length === 0) continue;
|
|
79
|
+
let list = el.matches(LIST_SELECTOR);
|
|
80
|
+
if (!list && el !== document.body) {
|
|
81
|
+
const groups = new Map();
|
|
82
|
+
for (const c of items) {
|
|
83
|
+
const key = `${c.tagName} ${(c.getAttribute("class") || "").split(/\s+/).filter(Boolean).sort().join(" ")}`;
|
|
84
|
+
groups.set(key, (groups.get(key) ?? 0) + 1);
|
|
85
|
+
}
|
|
86
|
+
list = [...groups.values()].some((n) => n >= REPEATED_MIN);
|
|
87
|
+
}
|
|
88
|
+
if (!list || found.some((f) => f.el.contains(el))) continue;
|
|
89
|
+
found.push({ el, items });
|
|
90
|
+
}
|
|
91
|
+
if (found.length > MAX_LISTS) cut.push(`${found.length} lists were found; only the first ${MAX_LISTS} were changed.`);
|
|
92
|
+
return found.slice(0, MAX_LISTS);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const inject = (kind, params = {}) => {
|
|
96
|
+
const out = { lists: 0, added: 0, shortLists: 0, cut: [], removed: [] };
|
|
97
|
+
if (kind === "base") return out;
|
|
98
|
+
const kept = keptEls();
|
|
99
|
+
const keptSet = new Set(kept);
|
|
100
|
+
if (kind === "growth") {
|
|
101
|
+
const growth = params.growth;
|
|
102
|
+
if (!Number.isFinite(growth)) throw new Error("the growth case needs a finite growth factor");
|
|
103
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
104
|
+
const nodes = [];
|
|
105
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
106
|
+
if (/\S/.test(n.nodeValue) && keptSet.has(n.parentElement)) nodes.push(n);
|
|
107
|
+
}
|
|
108
|
+
for (const n of nodes) {
|
|
109
|
+
const m = /^(\s*)([\s\S]*?)(\s*)$/.exec(n.nodeValue);
|
|
110
|
+
n.nodeValue = m[1] + grow(m[2], growth) + m[3];
|
|
111
|
+
}
|
|
112
|
+
for (const el of kept) {
|
|
113
|
+
if (isInputButton(el) && el.value.trim()) el.value = grow(el.value, growth);
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
if (kind === "long-text") {
|
|
118
|
+
for (const el of kept) {
|
|
119
|
+
if (isInputButton(el)) {
|
|
120
|
+
el.value = LONG_LABEL;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const n = ownTexts(el)[0];
|
|
124
|
+
if (!n) continue;
|
|
125
|
+
n.nodeValue = el.closest(LABEL_SCOPE) ? LONG_LABEL : el.closest(HEADING_SCOPE) ? LONG_HEADING : LONG_TEXT;
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
if (kind !== "empty" && kind !== "one" && kind !== "many") throw new Error(`unknown case: ${kind}`);
|
|
130
|
+
const lists = findLists(kept, keptSet, out.cut);
|
|
131
|
+
out.lists = lists.length;
|
|
132
|
+
let budget = MAX_CLONE_ELEMENTS;
|
|
133
|
+
for (const { el, items } of lists) {
|
|
134
|
+
const spent = budget < MAX_CLONE_ELEMENTS;
|
|
135
|
+
if (kind === "empty" || kind === "one") {
|
|
136
|
+
for (const item of kind === "empty" ? items : items.slice(1)) {
|
|
137
|
+
out.removed.push(...removedIds(item));
|
|
138
|
+
item.remove();
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const first = items[0];
|
|
143
|
+
const size = 1 + first.querySelectorAll("*").length;
|
|
144
|
+
const want = MANY_ITEMS - items.length;
|
|
145
|
+
if (want <= 0) continue;
|
|
146
|
+
const frag = document.createDocumentFragment();
|
|
147
|
+
let n = 0;
|
|
148
|
+
while (n < want && budget - size >= 0) {
|
|
149
|
+
const copy = first.cloneNode(true);
|
|
150
|
+
for (const c of [copy, ...copy.querySelectorAll("*")]) {
|
|
151
|
+
const id = idOf(c);
|
|
152
|
+
if (id !== null) c.setAttribute(ATTR, `${id.split("~")[0]}${COPY}${n + 1}`);
|
|
153
|
+
c.removeAttribute("id");
|
|
154
|
+
}
|
|
155
|
+
frag.appendChild(copy);
|
|
156
|
+
budget -= size;
|
|
157
|
+
n += 1;
|
|
158
|
+
}
|
|
159
|
+
items[items.length - 1].after(frag);
|
|
160
|
+
out.added += n;
|
|
161
|
+
if (n < want) {
|
|
162
|
+
out.shortLists += 1;
|
|
163
|
+
// The reason: this item alone, or the copies already added to earlier lists.
|
|
164
|
+
const why = spent && size * want <= MAX_CLONE_ELEMENTS ? `the copies in earlier lists reached ${MAX_CLONE_ELEMENTS} elements` : `one item has ${size} elements`;
|
|
165
|
+
out.cut.push(`${n} items were added to ${selectorOf(el)}, not ${MANY_ITEMS}: ${why}.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// ---- reading ----
|
|
172
|
+
const rectsOf = (nodes) =>
|
|
173
|
+
nodes.flatMap((n) => {
|
|
174
|
+
const range = document.createRange();
|
|
175
|
+
range.selectNodeContents(n);
|
|
176
|
+
return [...range.getClientRects()].filter((r) => r.width > 0 && r.height > 0);
|
|
177
|
+
});
|
|
178
|
+
// For the overlap reading only: a line box's vertical extent clamped to the element's computed line-height,
|
|
179
|
+
// centred on the content area, when that line-height is a length smaller than the box (at
|
|
180
|
+
// tight leading the content area is taller than the line).
|
|
181
|
+
const lineBox = (r, lineHeight) => {
|
|
182
|
+
const lh = parseFloat(lineHeight);
|
|
183
|
+
if (!(lh > 0) || lh >= r.height) return { left: r.left, right: r.right, top: r.top, bottom: r.bottom };
|
|
184
|
+
const mid = (r.top + r.bottom) / 2;
|
|
185
|
+
return { left: r.left, right: r.right, top: mid - lh / 2, bottom: mid + lh / 2 };
|
|
186
|
+
};
|
|
187
|
+
// The nearest ancestor-or-self whose display is not inline or contents.
|
|
188
|
+
const containerOf = (el) => {
|
|
189
|
+
let c = el;
|
|
190
|
+
while (c && c !== document.body) {
|
|
191
|
+
const d = getComputedStyle(c).display;
|
|
192
|
+
if (d !== "inline" && d !== "contents") return c;
|
|
193
|
+
c = c.parentElement;
|
|
194
|
+
}
|
|
195
|
+
return document.body;
|
|
196
|
+
};
|
|
197
|
+
// A box that is the containing block of absolutely positioned (abs) or fixed descendants.
|
|
198
|
+
const holdsFixed = (s) =>
|
|
199
|
+
s.transform !== "none" || s.filter !== "none" || s.perspective !== "none" ||
|
|
200
|
+
(s.backdropFilter && s.backdropFilter !== "none") || /paint|layout|strict|content/.test(s.contain) ||
|
|
201
|
+
/transform|perspective|filter/.test(s.willChange);
|
|
202
|
+
// The next box up the containing-block chain: an absolute box skips static ancestors, a fixed box starts
|
|
203
|
+
// from the viewport (null) unless an ancestor holds fixed descendants.
|
|
204
|
+
const upOf = (el) => {
|
|
205
|
+
const pos = getComputedStyle(el).position;
|
|
206
|
+
if (pos !== "absolute" && pos !== "fixed") return el.parentElement;
|
|
207
|
+
for (let a = el.parentElement; a; a = a.parentElement) {
|
|
208
|
+
const s = getComputedStyle(a);
|
|
209
|
+
if (holdsFixed(s) || (pos === "absolute" && s.position !== "static")) return a;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
213
|
+
const paddingBox = (el, s) => {
|
|
214
|
+
const r = el.getBoundingClientRect();
|
|
215
|
+
return {
|
|
216
|
+
left: r.left + parseFloat(s.borderLeftWidth), right: r.right - parseFloat(s.borderRightWidth),
|
|
217
|
+
top: r.top + parseFloat(s.borderTopWidth), bottom: r.bottom - parseFloat(s.borderBottomWidth),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
// The hidden or clip boxes over a container, by containing block, each with the axes it clips. A scroll
|
|
221
|
+
// box (auto, scroll) never cuts and ends the walk on its axis: what lies in it is reachable. html and body
|
|
222
|
+
// pass their overflow to the viewport and are not walked.
|
|
223
|
+
const clippersOf = (container) => {
|
|
224
|
+
const out = [];
|
|
225
|
+
const open = { x: true, y: true };
|
|
226
|
+
for (let el = container; el && el !== document.body && el !== document.documentElement; el = upOf(el)) {
|
|
227
|
+
const s = getComputedStyle(el);
|
|
228
|
+
const x = open.x && CLIPS.has(s.overflowX);
|
|
229
|
+
const y = open.y && CLIPS.has(s.overflowY);
|
|
230
|
+
if (x || y) out.push({ x, y, box: paddingBox(el, s) });
|
|
231
|
+
if (SCROLLS.has(s.overflowX)) open.x = false;
|
|
232
|
+
if (SCROLLS.has(s.overflowY)) open.y = false;
|
|
233
|
+
if (!open.x && !open.y) break;
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
};
|
|
237
|
+
const passes = (r, c) =>
|
|
238
|
+
(c.x && (r.left < c.box.left - SLACK_PX || r.right > c.box.right + SLACK_PX)) ||
|
|
239
|
+
(c.y && (r.top < c.box.top - SLACK_PX || r.bottom > c.box.bottom + SLACK_PX));
|
|
240
|
+
// Entirely outside the clip on an axis it clips (an overlap of SLACK_PX or less is none).
|
|
241
|
+
const outside = (r, c) =>
|
|
242
|
+
(c.x && (r.right <= c.box.left + SLACK_PX || r.left >= c.box.right - SLACK_PX)) ||
|
|
243
|
+
(c.y && (r.bottom <= c.box.top + SLACK_PX || r.top >= c.box.bottom - SLACK_PX));
|
|
244
|
+
|
|
245
|
+
const cutOf = (container, rects) => {
|
|
246
|
+
const s = getComputedStyle(container);
|
|
247
|
+
if (s.textOverflow === "ellipsis" && container.scrollWidth - container.clientWidth > SLACK_PX) return "ellipsis";
|
|
248
|
+
const clamp = s.webkitLineClamp;
|
|
249
|
+
if (clamp && clamp !== "none" && container.scrollHeight - container.clientHeight > SLACK_PX) return "clamped";
|
|
250
|
+
const clips = clippersOf(container);
|
|
251
|
+
return rects.some((r) => clips.some((c) => passes(r, c))) ? "cut" : null;
|
|
252
|
+
};
|
|
253
|
+
const spillsOf = (container, rects) => {
|
|
254
|
+
const s = getComputedStyle(container);
|
|
255
|
+
const b = container.getBoundingClientRect();
|
|
256
|
+
const vx = s.overflowX === "visible";
|
|
257
|
+
const vy = s.overflowY === "visible";
|
|
258
|
+
return rects.some(
|
|
259
|
+
(r) =>
|
|
260
|
+
(vx && (r.left < b.left - SLACK_PX || r.right > b.right + SLACK_PX)) ||
|
|
261
|
+
(vy && (r.top < b.top - SLACK_PX || r.bottom > b.bottom + SLACK_PX)),
|
|
262
|
+
);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// The text's box across: its element's box joined with its line boxes (a word can run out of its box).
|
|
266
|
+
const across = (el, rects) => {
|
|
267
|
+
const b = el.getBoundingClientRect();
|
|
268
|
+
return { left: Math.min(b.left, ...rects.map((r) => r.left)), right: Math.max(b.right, ...rects.map((r) => r.right)) };
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const read = () => {
|
|
272
|
+
const kept = keptEls();
|
|
273
|
+
const keptSet = new Set(kept);
|
|
274
|
+
const root = document.documentElement;
|
|
275
|
+
const vw = root.clientWidth;
|
|
276
|
+
// As composition's bleeds: a page that scrolls sideways (html, or body when html is visible, does not
|
|
277
|
+
// hide that overflow) has no bleed.
|
|
278
|
+
const rootStyle = getComputedStyle(root);
|
|
279
|
+
const viewStyle = rootStyle.overflowX === "visible" && rootStyle.overflowY === "visible" ? getComputedStyle(document.body) : rootStyle;
|
|
280
|
+
const lockedX = CLIPS.has(viewStyle.overflowX);
|
|
281
|
+
const sideways = root.scrollWidth > vw + ALIGN_PX && !lockedX;
|
|
282
|
+
const entries = [];
|
|
283
|
+
for (const el of kept) {
|
|
284
|
+
const id = idOf(el);
|
|
285
|
+
if (id === null) continue;
|
|
286
|
+
const nodes = ownTexts(el);
|
|
287
|
+
if (nodes.length === 0) continue;
|
|
288
|
+
const rects = rectsOf(nodes);
|
|
289
|
+
const container = containerOf(el);
|
|
290
|
+
const box = across(el, rects);
|
|
291
|
+
const pastRight = box.right > vw + ALIGN_PX;
|
|
292
|
+
const bleeds = !sideways && box.right > 0 && box.left < vw && (box.left < -ALIGN_PX || pastRight);
|
|
293
|
+
entries.push({
|
|
294
|
+
el, rects, container,
|
|
295
|
+
text: { id, selector: selectorOf(el), text: collapse(nodes.map((n) => n.nodeValue).join(" ")).slice(0, 40), spills: spillsOf(container, rects), cut: cutOf(container, rects), whole: true, bleeds, pastRight, right: box.right },
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// Overlaps over the first MAX_RECTS line boxes, in document order.
|
|
299
|
+
const all = [];
|
|
300
|
+
let rectsCut = false;
|
|
301
|
+
for (let i = 0; i < entries.length; i++) {
|
|
302
|
+
const lineHeight = getComputedStyle(entries[i].el).lineHeight;
|
|
303
|
+
for (const rect of entries[i].rects) {
|
|
304
|
+
const r = lineBox(rect, lineHeight);
|
|
305
|
+
if (all.length >= MAX_RECTS) {
|
|
306
|
+
rectsCut = true;
|
|
307
|
+
entries[i].text.whole = false;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
all.push({ i, r });
|
|
311
|
+
}
|
|
312
|
+
if (rectsCut) for (let k = i + 1; k < entries.length; k++) if (entries[k].rects.length) entries[k].text.whole = false;
|
|
313
|
+
if (rectsCut) break;
|
|
314
|
+
}
|
|
315
|
+
all.sort((a, b) => a.r.top - b.r.top || a.i - b.i);
|
|
316
|
+
const pairs = new Set();
|
|
317
|
+
for (let a = 0; a < all.length; a++) {
|
|
318
|
+
const A = all[a];
|
|
319
|
+
for (let b = a + 1; b < all.length && all[b].r.top < A.r.bottom; b++) {
|
|
320
|
+
const B = all[b];
|
|
321
|
+
if (A.i === B.i) continue;
|
|
322
|
+
const ea = entries[A.i].el;
|
|
323
|
+
const eb = entries[B.i].el;
|
|
324
|
+
if (ea.contains(eb) || eb.contains(ea)) continue;
|
|
325
|
+
// One block container: one inline formatting context, where a wrap is not an overlap
|
|
326
|
+
// (tight leading makes the content areas of two rows intersect).
|
|
327
|
+
if (entries[A.i].container === entries[B.i].container) continue;
|
|
328
|
+
const w = Math.min(A.r.right, B.r.right) - Math.max(A.r.left, B.r.left);
|
|
329
|
+
const h = Math.min(A.r.bottom, B.r.bottom) - Math.max(A.r.top, B.r.top);
|
|
330
|
+
if (w > SLACK_PX && h > SLACK_PX) pairs.add(JSON.stringify([entries[A.i].text.id, entries[B.i].text.id].sort(byId)));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const overlaps = [...pairs].map((p) => JSON.parse(p)).sort((p, q) => byId(p[0], q[0]) || byId(p[1], q[1]));
|
|
334
|
+
|
|
335
|
+
// Text elements the walk did not keep, cut away entirely by a hidden or clip box; decorative ones are
|
|
336
|
+
// never read.
|
|
337
|
+
const away = [];
|
|
338
|
+
for (const el of document.body.querySelectorAll(`[${ATTR}]`)) {
|
|
339
|
+
if (keptSet.has(el) || el.closest(DECORATIVE)) continue;
|
|
340
|
+
const nodes = ownTexts(el);
|
|
341
|
+
if (nodes.length === 0) continue;
|
|
342
|
+
const rects = rectsOf(nodes);
|
|
343
|
+
if (rects.length === 0) continue;
|
|
344
|
+
const clips = clippersOf(containerOf(el));
|
|
345
|
+
if (rects.every((r) => clips.some((c) => outside(r, c)))) away.push(idOf(el));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const fonts = [...new Set([...document.fonts].filter((f) => f.status !== "unloaded").map((f) => `${f.family} ${f.weight} ${f.style} ${f.stretch}: ${f.status}`))].sort();
|
|
349
|
+
const sheets = [...document.querySelectorAll("link[rel~=stylesheet][href]")]
|
|
350
|
+
.map((l) => {
|
|
351
|
+
// The rules the sheet holds (a link that failed keeps an empty sheet); null when it cannot be read.
|
|
352
|
+
let rules = null;
|
|
353
|
+
try {
|
|
354
|
+
rules = l.sheet ? l.sheet.cssRules.length : 0;
|
|
355
|
+
} catch {
|
|
356
|
+
rules = null;
|
|
357
|
+
}
|
|
358
|
+
return { href: l.href, rules };
|
|
359
|
+
})
|
|
360
|
+
.sort((a, b) => (a.href < b.href ? -1 : a.href > b.href ? 1 : 0));
|
|
361
|
+
const brokenImages = [...new Set([...document.images].filter((img) => img.complete && img.naturalWidth === 0 && idOf(img) !== null).map(idOf))].sort(byId);
|
|
362
|
+
return {
|
|
363
|
+
overflowX: lockedX ? null : root.scrollWidth - root.clientWidth,
|
|
364
|
+
clippedX: lockedX ? root.scrollWidth - root.clientWidth : null,
|
|
365
|
+
texts: entries.map((e) => e.text),
|
|
366
|
+
kept: kept.map(idOf).filter((id) => id !== null),
|
|
367
|
+
overlaps,
|
|
368
|
+
rectsCut,
|
|
369
|
+
away: away.sort(byId),
|
|
370
|
+
fonts,
|
|
371
|
+
sheets,
|
|
372
|
+
brokenImages,
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
return { tag, inject, read };
|
|
377
|
+
}
|