responsivelint 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +214 -2
- package/agents/skills/responsivelint/SKILL.md +57 -0
- package/agents/skills/responsivelint-fix/SKILL.md +38 -0
- package/agents/skills/responsivelint-fix-controls/SKILL.md +35 -0
- package/agents/skills/responsivelint-fix-cramped-text/SKILL.md +47 -0
- package/agents/skills/responsivelint-fix-overflow/SKILL.md +33 -0
- package/agents/skills/responsivelint-fix-overlap/SKILL.md +33 -0
- package/bin/responsivelint.mjs +111 -0
- package/dist/core.iife.js +944 -0
- package/dist/responsivelint.js +1232 -0
- package/dist/responsivelint.min.js +25 -0
- package/docs/rules/clipped-text.md +21 -0
- package/docs/rules/disappears-in-band.md +21 -0
- package/docs/rules/hidden-control.md +21 -0
- package/docs/rules/page-overflow.md +21 -0
- package/docs/rules/squashed-text.md +21 -0
- package/docs/rules/text-overlap.md +21 -0
- package/docs/rules/width-outlier.md +21 -0
- package/llms.txt +49 -0
- package/package.json +43 -4
- package/src/browser/entry.js +337 -0
- package/src/cli/replay.js +86 -0
- package/src/cli/report.js +90 -0
- package/src/cli/run.js +241 -0
- package/src/cli/server.js +24 -0
- package/src/core/analyze.js +265 -0
- package/src/core/bar.js +78 -0
- package/src/core/dom.js +122 -0
- package/src/core/highlight.js +73 -0
- package/src/core/index.js +5 -0
- package/src/core/inject.js +5 -0
- package/src/core/measure.js +241 -0
- package/src/core/recipe.js +19 -0
- package/src/explore/page.js +63 -0
- package/src/icons/measure.js +106 -0
- package/src/index.js +5 -0
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/core/index.js
|
|
9
|
+
var index_exports = {};
|
|
10
|
+
__export(index_exports, {
|
|
11
|
+
FIX_SKILLS: () => FIX_SKILLS,
|
|
12
|
+
INTERACTIVE_SELECTOR: () => INTERACTIVE_SELECTOR,
|
|
13
|
+
PACKS: () => PACKS,
|
|
14
|
+
RULES: () => RULES,
|
|
15
|
+
START_WIDTH: () => START_WIDTH,
|
|
16
|
+
analyze: () => analyze,
|
|
17
|
+
bands: () => bands,
|
|
18
|
+
checkNow: () => checkNow,
|
|
19
|
+
clearHighlight: () => clearHighlight,
|
|
20
|
+
detectEnvironment: () => detectEnvironment,
|
|
21
|
+
elementKey: () => elementKey,
|
|
22
|
+
findingLabel: () => findingLabel,
|
|
23
|
+
fingerprint: () => fingerprint,
|
|
24
|
+
highlight: () => highlight,
|
|
25
|
+
recipe: () => recipe,
|
|
26
|
+
skillFor: () => skillFor,
|
|
27
|
+
sweepOutliers: () => sweepOutliers
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// src/core/dom.js
|
|
31
|
+
var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE", "TITLE", "OPTION", "HEAD", "META", "LINK"]);
|
|
32
|
+
var INTERACTIVE_SELECTOR = [
|
|
33
|
+
"button",
|
|
34
|
+
"a[href]",
|
|
35
|
+
"summary",
|
|
36
|
+
"select",
|
|
37
|
+
"textarea",
|
|
38
|
+
"input:not([type=hidden])",
|
|
39
|
+
"[role=button]",
|
|
40
|
+
"[role=tab]",
|
|
41
|
+
"[role=link]",
|
|
42
|
+
"[role=menuitem]",
|
|
43
|
+
"[role=switch]",
|
|
44
|
+
"[role=checkbox]",
|
|
45
|
+
"[role=option]",
|
|
46
|
+
'[tabindex]:not([tabindex="-1"])'
|
|
47
|
+
].join(",");
|
|
48
|
+
function elementKey(el) {
|
|
49
|
+
const parts = [];
|
|
50
|
+
for (let node = el; node && node.nodeType === 1 && node !== document.body && node !== document.documentElement; node = node.parentElement) {
|
|
51
|
+
if (node.id && /^[A-Za-z][\w-]*$/.test(node.id)) {
|
|
52
|
+
parts.unshift("#" + node.id);
|
|
53
|
+
return parts.join(">");
|
|
54
|
+
}
|
|
55
|
+
const parent = node.parentElement;
|
|
56
|
+
const index = parent ? Array.prototype.indexOf.call(parent.children, node) + 1 : 1;
|
|
57
|
+
parts.unshift(node.tagName.toLowerCase() + ":nth-child(" + index + ")");
|
|
58
|
+
}
|
|
59
|
+
parts.unshift("body");
|
|
60
|
+
return parts.join(">");
|
|
61
|
+
}
|
|
62
|
+
function ignoredRules(el) {
|
|
63
|
+
const out = /* @__PURE__ */ new Set();
|
|
64
|
+
for (let node = el; node && node.nodeType === 1; node = node.parentElement) {
|
|
65
|
+
const v = node.getAttribute && node.getAttribute("data-rl-ignore");
|
|
66
|
+
if (v != null) {
|
|
67
|
+
if (v === "" || v === "all") out.add("all");
|
|
68
|
+
else v.split(/[\s,]+/).forEach((r) => out.add(r));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
function createContext() {
|
|
74
|
+
const style = /* @__PURE__ */ new Map(), opacity = /* @__PURE__ */ new Map(), clip = /* @__PURE__ */ new Map(), fixed = /* @__PURE__ */ new Map();
|
|
75
|
+
const cs = (el) => {
|
|
76
|
+
let s = style.get(el);
|
|
77
|
+
if (!s) {
|
|
78
|
+
s = getComputedStyle(el);
|
|
79
|
+
style.set(el, s);
|
|
80
|
+
}
|
|
81
|
+
return s;
|
|
82
|
+
};
|
|
83
|
+
function effectiveOpacity(el) {
|
|
84
|
+
if (!el || el.nodeType !== 1) return 1;
|
|
85
|
+
if (opacity.has(el)) return opacity.get(el);
|
|
86
|
+
const v = parseFloat(cs(el).opacity || "1") * effectiveOpacity(el.parentElement);
|
|
87
|
+
opacity.set(el, v);
|
|
88
|
+
return v;
|
|
89
|
+
}
|
|
90
|
+
function isPinned(el) {
|
|
91
|
+
if (!el || el.nodeType !== 1) return false;
|
|
92
|
+
if (fixed.has(el)) return fixed.get(el);
|
|
93
|
+
const p = cs(el).position;
|
|
94
|
+
const v = p === "fixed" || p === "sticky" || isPinned(el.parentElement);
|
|
95
|
+
fixed.set(el, v);
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
98
|
+
function clipRect(el) {
|
|
99
|
+
if (!el || el.nodeType !== 1 || el === document.documentElement) return { left: -1e9, top: -1e9, right: 1e9, bottom: 1e9 };
|
|
100
|
+
if (clip.has(el)) return clip.get(el);
|
|
101
|
+
const parent = clipRect(el.parentElement);
|
|
102
|
+
const s = cs(el);
|
|
103
|
+
let out = parent;
|
|
104
|
+
if (el !== document.body && (s.overflowX !== "visible" || s.overflowY !== "visible")) {
|
|
105
|
+
const r = el.getBoundingClientRect();
|
|
106
|
+
const box = { left: r.left + scrollX + el.clientLeft, top: r.top + scrollY + el.clientTop };
|
|
107
|
+
box.right = box.left + el.clientWidth;
|
|
108
|
+
box.bottom = box.top + el.clientHeight;
|
|
109
|
+
out = {
|
|
110
|
+
left: s.overflowX === "visible" ? parent.left : Math.max(parent.left, box.left),
|
|
111
|
+
right: s.overflowX === "visible" ? parent.right : Math.min(parent.right, box.right),
|
|
112
|
+
top: s.overflowY === "visible" ? parent.top : Math.max(parent.top, box.top),
|
|
113
|
+
bottom: s.overflowY === "visible" ? parent.bottom : Math.min(parent.bottom, box.bottom)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (s.position === "fixed") out = { left: -1e9, top: -1e9, right: 1e9, bottom: 1e9 };
|
|
117
|
+
clip.set(el, out);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
function hidden(el) {
|
|
121
|
+
for (let node = el; node && node.nodeType === 1; node = node.parentElement) {
|
|
122
|
+
if (node.getAttribute("aria-hidden") === "true" || node.hasAttribute("inert") || node.hidden) return true;
|
|
123
|
+
}
|
|
124
|
+
const s = cs(el);
|
|
125
|
+
return s.visibility !== "visible" || s.display === "none" || s.contentVisibility === "hidden";
|
|
126
|
+
}
|
|
127
|
+
return { cs, effectiveOpacity, isPinned, clipRect, hidden };
|
|
128
|
+
}
|
|
129
|
+
var intersect = (a, b) => ({ left: Math.max(a.left, b.left), top: Math.max(a.top, b.top), right: Math.min(a.right, b.right), bottom: Math.min(a.bottom, b.bottom) });
|
|
130
|
+
var area = (r) => Math.max(0, r.right - r.left) * Math.max(0, r.bottom - r.top);
|
|
131
|
+
function ownTextRects(el, ctx) {
|
|
132
|
+
const rects = [];
|
|
133
|
+
let text = "";
|
|
134
|
+
const clipTo = ctx.clipRect(el);
|
|
135
|
+
for (const node of el.childNodes) {
|
|
136
|
+
if (node.nodeType !== 3 || !node.textContent.trim()) continue;
|
|
137
|
+
text += node.textContent;
|
|
138
|
+
const range = document.createRange();
|
|
139
|
+
range.selectNodeContents(node);
|
|
140
|
+
for (const r of range.getClientRects()) {
|
|
141
|
+
if (r.width < 1 || r.height < 1) continue;
|
|
142
|
+
const doc = { left: r.left + scrollX, top: r.top + scrollY, right: r.right + scrollX, bottom: r.bottom + scrollY };
|
|
143
|
+
const cut = intersect(doc, clipTo);
|
|
144
|
+
if (area(cut) > 0) rects.push(cut);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { text: text.replace(/\s+/g, " ").trim(), rects };
|
|
148
|
+
}
|
|
149
|
+
function countLines(rects) {
|
|
150
|
+
const centres = rects.map((r) => (r.top + r.bottom) / 2).sort((a, b) => a - b);
|
|
151
|
+
let lines = 0, last = -1e9;
|
|
152
|
+
for (const c of centres) {
|
|
153
|
+
if (c - last > 3) {
|
|
154
|
+
lines++;
|
|
155
|
+
last = c;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return lines;
|
|
159
|
+
}
|
|
160
|
+
function label(el, text) {
|
|
161
|
+
const name = el.getAttribute("aria-label") || text || el.getAttribute("title") || el.getAttribute("alt") || "";
|
|
162
|
+
return name.replace(/\s+/g, " ").trim().slice(0, 60);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/core/measure.js
|
|
166
|
+
var MAX_TEXT = 4e3;
|
|
167
|
+
var MAX_MEASURES = 2500;
|
|
168
|
+
function detectEnvironment() {
|
|
169
|
+
const w = globalThis;
|
|
170
|
+
const frameworks = [];
|
|
171
|
+
if (w.__THREE__) frameworks.push("three.js r" + w.__THREE__);
|
|
172
|
+
if (w.AFRAME) frameworks.push("A-Frame " + (w.AFRAME.version || ""));
|
|
173
|
+
if (w.BABYLON) frameworks.push("Babylon.js " + (w.BABYLON.Engine?.Version || ""));
|
|
174
|
+
if (w.pc && w.pc.version) frameworks.push("PlayCanvas " + w.pc.version);
|
|
175
|
+
if ([...document.querySelectorAll("canvas")].some((c) => c.__r3f || c.parentElement?.__r3f)) frameworks.push("React Three Fiber");
|
|
176
|
+
const contexts = w.__rlContexts || {};
|
|
177
|
+
const canvases = document.querySelectorAll("canvas").length;
|
|
178
|
+
return {
|
|
179
|
+
frameworks: frameworks.map((f) => f.trim()),
|
|
180
|
+
webgl: (contexts.webgl || 0) + (contexts.webgl2 || 0),
|
|
181
|
+
webgpu: contexts.webgpu || 0,
|
|
182
|
+
canvases,
|
|
183
|
+
xr: !!w.__rlXR || !!navigator.xr && frameworks.length > 0,
|
|
184
|
+
is3D: frameworks.length > 0 || (contexts.webgl || 0) + (contexts.webgl2 || 0) + (contexts.webgpu || 0) > 0
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function checkNow(options = {}) {
|
|
188
|
+
let reveal = null;
|
|
189
|
+
if (options.revealSkipped) {
|
|
190
|
+
reveal = document.createElement("style");
|
|
191
|
+
reveal.textContent = "*{content-visibility:visible!important}";
|
|
192
|
+
document.head.append(reveal);
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
return measureAll(options);
|
|
196
|
+
} finally {
|
|
197
|
+
reveal?.remove();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function measureAll(options) {
|
|
201
|
+
const ctx = createContext();
|
|
202
|
+
const viewport = { width: innerWidth, height: innerHeight };
|
|
203
|
+
const findings = [];
|
|
204
|
+
const add = (f) => findings.push(f);
|
|
205
|
+
const texts = [];
|
|
206
|
+
const measures = [];
|
|
207
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
208
|
+
for (let el = walker.currentNode; el; el = walker.nextNode()) {
|
|
209
|
+
if (texts.length >= MAX_TEXT) break;
|
|
210
|
+
if (!(el instanceof HTMLElement) || SKIP_TAGS.has(el.tagName)) continue;
|
|
211
|
+
if (el.closest("[data-rl-overlay]")) continue;
|
|
212
|
+
const { text, rects } = ownTextRects(el, ctx);
|
|
213
|
+
if (!text || !rects.length || ctx.hidden(el) || ctx.effectiveOpacity(el) < 0.05) continue;
|
|
214
|
+
if (!options.revealSkipped && el.checkVisibility && !el.checkVisibility({ contentVisibilityAuto: true })) continue;
|
|
215
|
+
const box = el.getBoundingClientRect();
|
|
216
|
+
if (box.width <= 2 || box.height <= 2) continue;
|
|
217
|
+
const ignore = ignoredRules(el);
|
|
218
|
+
texts.push({ el, key: elementKey(el), text, rects, ignore, pinned: ctx.isPinned(el) });
|
|
219
|
+
}
|
|
220
|
+
const boxes = [];
|
|
221
|
+
texts.forEach((t, i) => t.rects.forEach((r) => boxes.push({ i, r })));
|
|
222
|
+
boxes.sort((a, b) => a.r.top - b.r.top);
|
|
223
|
+
const reported = /* @__PURE__ */ new Set();
|
|
224
|
+
const overlaps = [];
|
|
225
|
+
let start = 0;
|
|
226
|
+
for (let a = 0; a < boxes.length; a++) {
|
|
227
|
+
const A = boxes[a];
|
|
228
|
+
while (start < a && boxes[start].r.bottom <= A.r.top) start++;
|
|
229
|
+
for (let b = start; b < a; b++) {
|
|
230
|
+
const B = boxes[b];
|
|
231
|
+
if (A.i === B.i || B.r.bottom <= A.r.top) continue;
|
|
232
|
+
const ta = texts[A.i], tb = texts[B.i];
|
|
233
|
+
if (ta.pinned !== tb.pinned) continue;
|
|
234
|
+
if (ta.el.contains(tb.el) || tb.el.contains(ta.el)) continue;
|
|
235
|
+
if (ta.ignore.has("all") || ta.ignore.has("text-overlap") || tb.ignore.has("all") || tb.ignore.has("text-overlap")) continue;
|
|
236
|
+
const cut = intersect(A.r, B.r);
|
|
237
|
+
const smaller = Math.min(area(A.r), area(B.r));
|
|
238
|
+
const minH = Math.min(A.r.bottom - A.r.top, B.r.bottom - B.r.top);
|
|
239
|
+
if (area(cut) < 0.25 * smaller || cut.bottom - cut.top < 0.4 * minH) continue;
|
|
240
|
+
const pair = A.i < B.i ? A.i + ":" + B.i : B.i + ":" + A.i;
|
|
241
|
+
if (reported.has(pair)) continue;
|
|
242
|
+
reported.add(pair);
|
|
243
|
+
overlaps.push({ ta, tb, cut, share: Math.round(100 * area(cut) / smaller) });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const o of confirmOverlaps(overlaps)) {
|
|
247
|
+
const { ta, tb, cut, share, top } = o;
|
|
248
|
+
add({
|
|
249
|
+
rule: "text-overlap",
|
|
250
|
+
keys: [ta.key, tb.key].sort(),
|
|
251
|
+
elements: [{ key: ta.key, text: ta.text.slice(0, 60) }, { key: tb.key, text: tb.text.slice(0, 60) }],
|
|
252
|
+
rect: cut,
|
|
253
|
+
onTop: top,
|
|
254
|
+
measured: { overlap: share + "% of the smaller line", ...top ? { onTop: top.summary } : {} }
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
for (const t of texts) {
|
|
258
|
+
const words = t.text.split(/\s+/).filter(Boolean).length;
|
|
259
|
+
const lines = countLines(t.rects);
|
|
260
|
+
if (measures.length < MAX_MEASURES && t.text.length >= 6) {
|
|
261
|
+
const left = Math.min(...t.rects.map((r) => r.left)), right = Math.max(...t.rects.map((r) => r.right));
|
|
262
|
+
const top = Math.min(...t.rects.map((r) => r.top)), bottom = Math.max(...t.rects.map((r) => r.bottom));
|
|
263
|
+
measures.push({ key: t.key, kind: "text", text: t.text.slice(0, 60), words, lines, w: Math.round(right - left), rect: { left, top, right, bottom } });
|
|
264
|
+
}
|
|
265
|
+
if (t.ignore.has("all") || t.ignore.has("squashed-text")) continue;
|
|
266
|
+
if (words >= 3 && lines >= 3 && words / lines <= 1.25 && t.text.length >= 15) {
|
|
267
|
+
const left = Math.min(...t.rects.map((r) => r.left)), right = Math.max(...t.rects.map((r) => r.right));
|
|
268
|
+
const top = Math.min(...t.rects.map((r) => r.top)), bottom = Math.max(...t.rects.map((r) => r.bottom));
|
|
269
|
+
add({
|
|
270
|
+
rule: "squashed-text",
|
|
271
|
+
keys: [t.key],
|
|
272
|
+
elements: [{ key: t.key, text: t.text.slice(0, 60) }],
|
|
273
|
+
rect: { left, top, right, bottom },
|
|
274
|
+
measured: { width: Math.round(right - left), lines, words }
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const seenClip = /* @__PURE__ */ new Set();
|
|
279
|
+
for (const t of texts) {
|
|
280
|
+
for (let el = t.el; el && el !== document.body; el = el.parentElement) {
|
|
281
|
+
const s = ctx.cs(el);
|
|
282
|
+
const clipsX = s.overflowX === "hidden" || s.overflowX === "clip";
|
|
283
|
+
const clipsY = s.overflowY === "hidden" || s.overflowY === "clip";
|
|
284
|
+
if (!clipsX && !clipsY) continue;
|
|
285
|
+
if (seenClip.has(el)) break;
|
|
286
|
+
seenClip.add(el);
|
|
287
|
+
if (el.clientWidth < 2 || el.clientHeight < 2 || ctx.hidden(el)) break;
|
|
288
|
+
if (s.webkitLineClamp && s.webkitLineClamp !== "none") break;
|
|
289
|
+
const over = clipsX && el.scrollWidth > el.clientWidth + 2 || clipsY && el.scrollHeight > el.clientHeight + 2;
|
|
290
|
+
if (!over) break;
|
|
291
|
+
const r = el.getBoundingClientRect();
|
|
292
|
+
const edge = { left: r.left + scrollX, top: r.top + scrollY, right: r.left + scrollX + el.clientWidth, bottom: r.top + scrollY + el.clientHeight };
|
|
293
|
+
const ig = ignoredRules(el);
|
|
294
|
+
if (!ig.has("all") && !ig.has("clipped-text")) {
|
|
295
|
+
add({
|
|
296
|
+
rule: "clipped-text",
|
|
297
|
+
keys: [elementKey(el)],
|
|
298
|
+
elements: [{ key: elementKey(el), text: label(el, t.text) }],
|
|
299
|
+
rect: edge,
|
|
300
|
+
ellipsis: s.textOverflow === "ellipsis",
|
|
301
|
+
measured: { contentWidth: el.scrollWidth, boxWidth: el.clientWidth, contentHeight: el.scrollHeight, boxHeight: el.clientHeight }
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const docWidth = document.documentElement.scrollWidth;
|
|
308
|
+
if (docWidth > viewport.width + 1 && !ignoredRules(document.body).has("page-overflow")) {
|
|
309
|
+
const culprits = [];
|
|
310
|
+
const all = document.body.querySelectorAll("*");
|
|
311
|
+
for (const el of all) {
|
|
312
|
+
if (culprits.length >= 5) break;
|
|
313
|
+
if (!(el instanceof HTMLElement) || SKIP_TAGS.has(el.tagName) || ctx.hidden(el)) continue;
|
|
314
|
+
const r = el.getBoundingClientRect();
|
|
315
|
+
if (r.right + scrollX <= viewport.width + 1 || r.width === 0) continue;
|
|
316
|
+
const c = ctx.clipRect(el.parentElement);
|
|
317
|
+
if (c.right <= viewport.width + 1) continue;
|
|
318
|
+
const parent = el.parentElement.getBoundingClientRect();
|
|
319
|
+
if (parent.right + scrollX > viewport.width + 1 && el.parentElement !== document.body) continue;
|
|
320
|
+
culprits.push({ key: elementKey(el), text: label(el, (el.textContent || "").trim()) || el.tagName.toLowerCase(), right: Math.round(r.right + scrollX) });
|
|
321
|
+
}
|
|
322
|
+
add({
|
|
323
|
+
rule: "page-overflow",
|
|
324
|
+
keys: culprits.map((c) => c.key).sort().slice(0, 1),
|
|
325
|
+
elements: culprits,
|
|
326
|
+
rect: null,
|
|
327
|
+
measured: { pageWidth: docWidth, viewport: viewport.width, by: docWidth - viewport.width }
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
for (const el of document.body.querySelectorAll(INTERACTIVE_SELECTOR)) {
|
|
331
|
+
if (!(el instanceof HTMLElement) || el.closest("[data-rl-overlay]")) continue;
|
|
332
|
+
const s = ctx.cs(el);
|
|
333
|
+
if (s.display === "none" || el.disabled) continue;
|
|
334
|
+
if (el.closest("[aria-hidden=true],[inert],[hidden]")) continue;
|
|
335
|
+
const r = el.getBoundingClientRect();
|
|
336
|
+
if (r.width < 4 || r.height < 4) continue;
|
|
337
|
+
const box = { left: r.left + scrollX, top: r.top + scrollY, right: r.right + scrollX, bottom: r.bottom + scrollY };
|
|
338
|
+
if (area(intersect(box, ctx.clipRect(el.parentElement))) < 4) continue;
|
|
339
|
+
const op = ctx.effectiveOpacity(el);
|
|
340
|
+
const invisible = op < 0.1 && s.visibility === "visible" && s.pointerEvents !== "none";
|
|
341
|
+
if (measures.length < MAX_MEASURES + 500) measures.push({ key: elementKey(el), kind: "control", text: label(el, (el.textContent || "").trim()), visible: !invisible, rect: box });
|
|
342
|
+
if (!invisible) continue;
|
|
343
|
+
if (el.matches("input[type=checkbox],input[type=radio],input[type=file],input[type=range]") && (el.labels?.length || el.closest("label"))) continue;
|
|
344
|
+
const ig = ignoredRules(el);
|
|
345
|
+
if (ig.has("all") || ig.has("hidden-control")) continue;
|
|
346
|
+
add({
|
|
347
|
+
rule: "hidden-control",
|
|
348
|
+
keys: [elementKey(el)],
|
|
349
|
+
elements: [{ key: elementKey(el), text: label(el, (el.textContent || "").trim()) || el.tagName.toLowerCase() }],
|
|
350
|
+
rect: box,
|
|
351
|
+
measured: { opacity: +op.toFixed(2) }
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return { width: viewport.width, height: viewport.height, env: detectEnvironment(), findings, measures };
|
|
355
|
+
}
|
|
356
|
+
function confirmOverlaps(list) {
|
|
357
|
+
if (!list.length) return [];
|
|
358
|
+
const allow = document.createElement("style");
|
|
359
|
+
allow.textContent = "*{pointer-events:auto!important}";
|
|
360
|
+
document.head.append(allow);
|
|
361
|
+
const sx = scrollX, sy = scrollY;
|
|
362
|
+
const out = [];
|
|
363
|
+
try {
|
|
364
|
+
for (const o of list) {
|
|
365
|
+
const cx = (o.cut.left + o.cut.right) / 2, cy = (o.cut.top + o.cut.bottom) / 2;
|
|
366
|
+
const pinned = o.ta.pinned && o.tb.pinned;
|
|
367
|
+
let vx = cx - scrollX, vy = cy - scrollY;
|
|
368
|
+
if (!pinned && (vx < 0 || vy < 0 || vx >= innerWidth || vy >= innerHeight)) {
|
|
369
|
+
window.scrollTo({ left: Math.max(0, cx - innerWidth / 2), top: Math.max(0, cy - innerHeight / 2), behavior: "instant" });
|
|
370
|
+
vx = cx - scrollX;
|
|
371
|
+
vy = cy - scrollY;
|
|
372
|
+
}
|
|
373
|
+
if (pinned) {
|
|
374
|
+
vx = cx - sx;
|
|
375
|
+
vy = cy - sy;
|
|
376
|
+
}
|
|
377
|
+
const stack = document.elementsFromPoint(vx, vy);
|
|
378
|
+
const at = (el) => stack.findIndex((s) => s === el || el.contains(s));
|
|
379
|
+
const ia = at(o.ta.el), ib = at(o.tb.el);
|
|
380
|
+
if (ia < 0 && ib < 0) continue;
|
|
381
|
+
const topEl = ia < 0 ? o.tb.el : ib < 0 ? o.ta.el : ia <= ib ? o.ta.el : o.tb.el;
|
|
382
|
+
out.push({ ...o, top: describeLayer(topEl) });
|
|
383
|
+
}
|
|
384
|
+
} finally {
|
|
385
|
+
allow.remove();
|
|
386
|
+
if (scrollX !== sx || scrollY !== sy) window.scrollTo({ left: sx, top: sy, behavior: "instant" });
|
|
387
|
+
}
|
|
388
|
+
return out;
|
|
389
|
+
}
|
|
390
|
+
function describeLayer(el) {
|
|
391
|
+
let layer = el;
|
|
392
|
+
for (let n = el; n && n !== document.body; n = n.parentElement) {
|
|
393
|
+
const s2 = getComputedStyle(n);
|
|
394
|
+
if (s2.position !== "static" || s2.zIndex !== "auto" || s2.transform !== "none") {
|
|
395
|
+
layer = n;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const s = getComputedStyle(layer);
|
|
400
|
+
const parts = [s.position !== "static" ? "position: " + s.position : "", s.zIndex !== "auto" ? "z-index: " + s.zIndex : "", s.transform !== "none" ? "transformed" : ""].filter(Boolean);
|
|
401
|
+
const text = (el.textContent || "").replace(/\s+/g, " ").trim().slice(0, 40);
|
|
402
|
+
return { key: elementKey(layer), text, position: s.position, zIndex: s.zIndex, summary: `"${text}"` + (parts.length ? " (" + parts.join(", ") + ")" : " (normal flow)") };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/core/analyze.js
|
|
406
|
+
var REPO = "https://github.com/prajwalsouza/ResponsiveLint/blob/main/";
|
|
407
|
+
var FIX_SKILLS = {
|
|
408
|
+
"responsivelint-fix-overlap": { title: "Fix text drawn over other text", rules: ["text-overlap"] },
|
|
409
|
+
"responsivelint-fix-cramped-text": { title: "Fix text that is squeezed or cut off", rules: ["squashed-text", "clipped-text", "width-outlier"] },
|
|
410
|
+
"responsivelint-fix-overflow": { title: "Fix a page that scrolls sideways", rules: ["page-overflow"] },
|
|
411
|
+
"responsivelint-fix-controls": { title: "Fix controls that are invisible or go missing", rules: ["hidden-control", "disappears-in-band"] }
|
|
412
|
+
};
|
|
413
|
+
var skillFor = (rule) => {
|
|
414
|
+
const name = Object.keys(FIX_SKILLS).find((k) => FIX_SKILLS[k].rules.includes(rule)) || "responsivelint-fix";
|
|
415
|
+
const file = `agents/skills/${name}/SKILL.md`;
|
|
416
|
+
return { name, file, url: REPO + file };
|
|
417
|
+
};
|
|
418
|
+
var RULES = {
|
|
419
|
+
"text-overlap": {
|
|
420
|
+
pack: "text",
|
|
421
|
+
severity: "error",
|
|
422
|
+
confidence: "high",
|
|
423
|
+
title: "Text covers other text",
|
|
424
|
+
why: "Two pieces of visible text are drawn in the same place, so neither can be read.",
|
|
425
|
+
tries: [
|
|
426
|
+
"An element with position: absolute or fixed sits on text that wraps at this width: place it with flex or grid instead, or move it off the text. Changing z-index only swaps which text is hidden.",
|
|
427
|
+
"A box has a fixed height, so its text spills out when it wraps: remove height, or use min-height.",
|
|
428
|
+
"A negative margin or a transform pulls one element onto another: remove it at these widths.",
|
|
429
|
+
"A toast, tooltip or badge is placed on a toolbar: place it above or beside the toolbar."
|
|
430
|
+
]
|
|
431
|
+
},
|
|
432
|
+
"squashed-text": {
|
|
433
|
+
pack: "text",
|
|
434
|
+
severity: "warning",
|
|
435
|
+
confidence: "high",
|
|
436
|
+
title: "Text squeezed to about one word per line",
|
|
437
|
+
why: "The text has become so narrow that almost every word sits on its own line.",
|
|
438
|
+
tries: [
|
|
439
|
+
"A neighbour in the same row does not wrap (white-space: nowrap, flex-shrink: 0, an auto grid column full of buttons): let it wrap with flex-wrap: wrap, or put it on its own line with grid-template-columns: 1fr.",
|
|
440
|
+
"The row keeps two columns at a width where one fits better: stack them below this width with a media or container query.",
|
|
441
|
+
"Nothing stops the text from shrinking: give it min-width: 12em (or similar)."
|
|
442
|
+
]
|
|
443
|
+
},
|
|
444
|
+
"clipped-text": {
|
|
445
|
+
pack: "text",
|
|
446
|
+
severity: "warning",
|
|
447
|
+
confidence: "medium",
|
|
448
|
+
title: "Text cut off by its box",
|
|
449
|
+
why: "A box with overflow hidden is smaller than the text inside it, so part of the text is not shown.",
|
|
450
|
+
tries: [
|
|
451
|
+
"The box has a fixed width or height: remove it, or use min-width or min-height, so the box grows with its text.",
|
|
452
|
+
"The text is not allowed to wrap (white-space: nowrap): allow wrapping.",
|
|
453
|
+
"The cut is intended: add text-overflow: ellipsis and a title with the full text, so the finding becomes a note."
|
|
454
|
+
]
|
|
455
|
+
},
|
|
456
|
+
"page-overflow": {
|
|
457
|
+
pack: "overflow",
|
|
458
|
+
severity: "error",
|
|
459
|
+
confidence: "high",
|
|
460
|
+
title: "The page scrolls sideways",
|
|
461
|
+
why: "Something is wider than the screen, so the whole page can be dragged sideways.",
|
|
462
|
+
tries: [
|
|
463
|
+
"The named element has a fixed width in pixels: use max-width: 100%, or a width in % or fr.",
|
|
464
|
+
"A row of controls or a long word or URL does not wrap: add flex-wrap: wrap, or overflow-wrap: anywhere for long words.",
|
|
465
|
+
"A wide table, code block or image: wrap it in a box with overflow-x: auto, or give images max-width: 100%.",
|
|
466
|
+
"Do not hide the problem with overflow-x: hidden on body or html; it cuts content off instead."
|
|
467
|
+
]
|
|
468
|
+
},
|
|
469
|
+
"hidden-control": {
|
|
470
|
+
pack: "visibility",
|
|
471
|
+
severity: "warning",
|
|
472
|
+
confidence: "medium",
|
|
473
|
+
title: "A control takes space but cannot be seen",
|
|
474
|
+
why: "A button, link or tab is laid out, clickable and focusable, but fully transparent in its resting state, so people do not know it is there.",
|
|
475
|
+
tries: [
|
|
476
|
+
"It appears only on hover (opacity: 0 until :hover): show it at rest, perhaps quieter, because touch screens have no hover.",
|
|
477
|
+
"It should stay hidden until something happens: hide it properly with display: none, visibility: hidden or the hidden attribute until then, so it leaves the tab order too.",
|
|
478
|
+
"Keyboard users cannot find it: also show it on :focus-visible and :focus-within."
|
|
479
|
+
]
|
|
480
|
+
},
|
|
481
|
+
"width-outlier": {
|
|
482
|
+
pack: "sweep",
|
|
483
|
+
severity: "warning",
|
|
484
|
+
confidence: "high",
|
|
485
|
+
title: "Breaks only in a narrow band of widths",
|
|
486
|
+
why: "This element looks normal at the widths on both sides, but changes sharply inside this band, which is how layout bugs between breakpoints show up.",
|
|
487
|
+
tries: [
|
|
488
|
+
"One part of the layout switches at a breakpoint before another does (a sidebar appears before the content stacks): line the two media queries up, or switch the content to a container query.",
|
|
489
|
+
"A neighbour stops wrapping inside the band and takes the width: let it wrap, or stack it below this width.",
|
|
490
|
+
"A fixed size takes over inside the band: replace it with min(), max() or clamp()."
|
|
491
|
+
]
|
|
492
|
+
},
|
|
493
|
+
"disappears-in-band": {
|
|
494
|
+
pack: "sweep",
|
|
495
|
+
severity: "warning",
|
|
496
|
+
confidence: "medium",
|
|
497
|
+
title: "A control disappears in a narrow band of widths",
|
|
498
|
+
why: "The control is visible at the widths on both sides but not inside this band.",
|
|
499
|
+
tries: [
|
|
500
|
+
"Two media queries hand over at different widths (one hides the desktop control, the other shows the mobile one a few pixels later): use the same width for both, or one query.",
|
|
501
|
+
"max-width and min-width both use the same number, so one pixel shows neither: use max-width: 767px with min-width: 768px, or a range query.",
|
|
502
|
+
"The control is pushed out of its row and clipped: let the row wrap."
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
for (const r of Object.values(RULES)) r.fix = r.tries[0];
|
|
507
|
+
var PACKS = ["text", "overlap", "visibility", "overflow", "sweep"];
|
|
508
|
+
function bands(widths, allWidths) {
|
|
509
|
+
const sorted = [...new Set(widths)].sort((a, b) => a - b);
|
|
510
|
+
const index = new Map(allWidths.map((w, i) => [w, i]));
|
|
511
|
+
const out = [];
|
|
512
|
+
for (const w of sorted) {
|
|
513
|
+
const last = out[out.length - 1];
|
|
514
|
+
if (last && index.get(w) === index.get(last[1]) + 1) last[1] = w;
|
|
515
|
+
else out.push([w, w]);
|
|
516
|
+
}
|
|
517
|
+
return out;
|
|
518
|
+
}
|
|
519
|
+
var median = (xs) => {
|
|
520
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
521
|
+
return s.length ? s[Math.floor(s.length / 2)] : 0;
|
|
522
|
+
};
|
|
523
|
+
function sweepOutliers(series, allWidths, state) {
|
|
524
|
+
const findings = [];
|
|
525
|
+
for (const [key, byWidth] of series) {
|
|
526
|
+
const pts = allWidths.map((w) => byWidth.get(w));
|
|
527
|
+
if (pts.filter(Boolean).length < 5) continue;
|
|
528
|
+
const kind = pts.find(Boolean).kind;
|
|
529
|
+
const odd = new Array(pts.length).fill(false);
|
|
530
|
+
for (let i2 = 0; i2 < pts.length; i2++) {
|
|
531
|
+
const p = pts[i2];
|
|
532
|
+
const near = [];
|
|
533
|
+
for (let d = 1; d <= 3; d++) {
|
|
534
|
+
if (pts[i2 - d]) near.push(pts[i2 - d]);
|
|
535
|
+
if (pts[i2 + d]) near.push(pts[i2 + d]);
|
|
536
|
+
}
|
|
537
|
+
if (near.length < 3) continue;
|
|
538
|
+
if (kind === "text") {
|
|
539
|
+
if (!p) continue;
|
|
540
|
+
const ml = median(near.map((n) => n.lines)), mw = median(near.map((n) => n.words / Math.max(1, n.lines)));
|
|
541
|
+
const wpl = p.words / Math.max(1, p.lines);
|
|
542
|
+
odd[i2] = p.words >= 3 && p.lines >= Math.max(3, 2 * ml, ml + 2) && wpl <= 0.5 * mw && wpl <= 2.5;
|
|
543
|
+
} else if (kind === "control") {
|
|
544
|
+
const visibleNear = near.filter((n) => n.visible).length;
|
|
545
|
+
odd[i2] = (!p || !p.visible) && visibleNear >= near.length - 1;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
let i = 0;
|
|
549
|
+
while (i < pts.length) {
|
|
550
|
+
if (!odd[i]) {
|
|
551
|
+
i++;
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
let j = i;
|
|
555
|
+
while (j + 1 < pts.length && odd[j + 1]) j++;
|
|
556
|
+
const before = pts.slice(0, i).some((p, k) => p && !odd[k]);
|
|
557
|
+
const after = pts.slice(j + 1).some((p, k) => p && !odd[j + 1 + k]);
|
|
558
|
+
const narrow = j - i + 1 <= Math.max(1, Math.floor(0.35 * pts.length));
|
|
559
|
+
if (before && after && narrow) {
|
|
560
|
+
const bad = pts[i] || pts.slice(i, j + 1).find(Boolean);
|
|
561
|
+
const good = pts.slice(0, i).reverse().find(Boolean);
|
|
562
|
+
const rule = kind === "text" ? "width-outlier" : "disappears-in-band";
|
|
563
|
+
findings.push({
|
|
564
|
+
rule,
|
|
565
|
+
keys: [key],
|
|
566
|
+
state,
|
|
567
|
+
widths: allWidths.slice(i, j + 1),
|
|
568
|
+
elements: [{ key, text: (bad || good)?.text || "" }],
|
|
569
|
+
rect: bad?.rect || good?.rect,
|
|
570
|
+
goodWidth: allWidths[allWidths.indexOf(allWidths[i]) - 1],
|
|
571
|
+
measured: kind === "text" && bad ? { lines: bad.lines, wordsPerLine: +(bad.words / bad.lines).toFixed(1) } : { visible: false },
|
|
572
|
+
expected: kind === "text" && good ? { lines: good.lines, wordsPerLine: +(good.words / Math.max(1, good.lines)).toFixed(1) } : { visible: true }
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
i = j + 1;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return findings;
|
|
579
|
+
}
|
|
580
|
+
function analyze(snapshots, options = {}) {
|
|
581
|
+
const allWidths = [...new Set(snapshots.map((s) => s.width))].sort((a, b) => a - b);
|
|
582
|
+
const raw = [];
|
|
583
|
+
for (const s of snapshots) for (const f of s.findings) raw.push({ ...f, state: s.state, widths: [s.width] });
|
|
584
|
+
const states = /* @__PURE__ */ new Map();
|
|
585
|
+
for (const s of snapshots) {
|
|
586
|
+
if (!states.has(s.state.id)) states.set(s.state.id, { state: s.state, snaps: [] });
|
|
587
|
+
states.get(s.state.id).snaps.push(s);
|
|
588
|
+
}
|
|
589
|
+
for (const { state, snaps } of states.values()) {
|
|
590
|
+
if (snaps.length < 5) continue;
|
|
591
|
+
const series = /* @__PURE__ */ new Map();
|
|
592
|
+
for (const s of snaps) for (const m of s.measures) {
|
|
593
|
+
if (!series.has(m.key + "|" + m.kind)) series.set(m.key + "|" + m.kind, /* @__PURE__ */ new Map());
|
|
594
|
+
series.get(m.key + "|" + m.kind).set(s.width, m);
|
|
595
|
+
}
|
|
596
|
+
const keyed = new Map([...series].map(([k, v]) => [k.split("|")[0], v]));
|
|
597
|
+
raw.push(...sweepOutliers(keyed, snaps.map((s) => s.width).sort((a, b) => a - b), state));
|
|
598
|
+
}
|
|
599
|
+
const groups = /* @__PURE__ */ new Map();
|
|
600
|
+
for (const f of raw) {
|
|
601
|
+
const id = f.rule + "|" + f.keys.join("+");
|
|
602
|
+
if (!groups.has(id)) groups.set(id, { ...f, widths: [], states: [], instances: [] });
|
|
603
|
+
const g = groups.get(id);
|
|
604
|
+
g.widths.push(...f.widths);
|
|
605
|
+
if (!g.states.some((s) => s.id === f.state.id)) g.states.push(f.state);
|
|
606
|
+
g.instances.push({ state: f.state.id, width: f.widths[0], rect: f.rect, measured: f.measured });
|
|
607
|
+
}
|
|
608
|
+
mergeOverlaps(groups);
|
|
609
|
+
const order = { error: 0, warning: 1, info: 2 };
|
|
610
|
+
const conf = { high: 0, medium: 1, low: 2 };
|
|
611
|
+
const out = [];
|
|
612
|
+
for (const [id, g] of groups) {
|
|
613
|
+
const meta = RULES[g.rule];
|
|
614
|
+
if (options.only && !options.only.includes(meta.pack) && !options.only.includes(g.rule)) continue;
|
|
615
|
+
if (options.skip && (options.skip.includes(meta.pack) || options.skip.includes(g.rule))) continue;
|
|
616
|
+
let severity = meta.severity, confidence = meta.confidence;
|
|
617
|
+
if (g.rule === "clipped-text" && g.ellipsis) {
|
|
618
|
+
severity = "info";
|
|
619
|
+
}
|
|
620
|
+
const ws = [...new Set(g.widths)].sort((a, b) => a - b);
|
|
621
|
+
const tries = likelyTries(g, meta);
|
|
622
|
+
out.push({
|
|
623
|
+
id: fingerprint(id),
|
|
624
|
+
rule: g.rule,
|
|
625
|
+
pack: meta.pack,
|
|
626
|
+
severity,
|
|
627
|
+
confidence,
|
|
628
|
+
title: meta.title,
|
|
629
|
+
elements: g.elements,
|
|
630
|
+
widths: ws,
|
|
631
|
+
bands: bands(ws, allWidths),
|
|
632
|
+
everyWidth: ws.length === allWidths.length,
|
|
633
|
+
states: g.states.map((s) => s.label),
|
|
634
|
+
measured: g.measured,
|
|
635
|
+
expected: g.expected,
|
|
636
|
+
why: meta.why,
|
|
637
|
+
fix: tries[0],
|
|
638
|
+
tries,
|
|
639
|
+
guide: REPO + "docs/rules/" + g.rule + ".md",
|
|
640
|
+
skill: skillFor(g.rule),
|
|
641
|
+
suppress: `data-rl-ignore="${g.rule}"`,
|
|
642
|
+
instances: g.instances.slice(0, 50),
|
|
643
|
+
goodWidth: g.goodWidth
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
if (options.minConfidence) out.splice(0, out.length, ...out.filter((f) => conf[f.confidence] <= conf[options.minConfidence]));
|
|
647
|
+
out.sort((a, b) => order[a.severity] - order[b.severity] || conf[a.confidence] - conf[b.confidence] || b.widths.length - a.widths.length);
|
|
648
|
+
return { widths: allWidths, findings: out };
|
|
649
|
+
}
|
|
650
|
+
function likelyTries(g, meta) {
|
|
651
|
+
const t = [...meta.tries];
|
|
652
|
+
const first = (i, text) => {
|
|
653
|
+
const [x] = t.splice(i, 1);
|
|
654
|
+
t.unshift(text || x);
|
|
655
|
+
};
|
|
656
|
+
const m = g.measured || {};
|
|
657
|
+
if (g.rule === "text-overlap") {
|
|
658
|
+
const top = g.onTop;
|
|
659
|
+
if (top && ["absolute", "fixed", "sticky"].includes(top.position)) {
|
|
660
|
+
first(0, `The text on top, ${top.summary}, is taken out of the normal layout: place it with flex or grid instead, or move it so it does not sit on the text. Changing z-index only swaps which text is hidden. (${top.key})`);
|
|
661
|
+
} else if (top && top.position === "static") first(1);
|
|
662
|
+
} else if (g.rule === "clipped-text") {
|
|
663
|
+
if (g.ellipsis) first(2, "The cut is marked with an ellipsis, so it looks intended: make sure a title or tooltip gives the full text.");
|
|
664
|
+
else if (m.contentWidth > m.boxWidth && !(m.contentHeight > m.boxHeight)) first(1);
|
|
665
|
+
}
|
|
666
|
+
return t;
|
|
667
|
+
}
|
|
668
|
+
function mergeOverlaps(groups) {
|
|
669
|
+
const parent = (k) => k.includes(">") ? k.slice(0, k.lastIndexOf(">")) : k;
|
|
670
|
+
const byRoot = /* @__PURE__ */ new Map();
|
|
671
|
+
for (const [id, g] of groups) {
|
|
672
|
+
if (g.rule !== "text-overlap") continue;
|
|
673
|
+
const [a, b] = g.keys;
|
|
674
|
+
for (const [shared, other] of [[a, b], [b, a]]) {
|
|
675
|
+
const root = shared + "~" + parent(other);
|
|
676
|
+
if (!byRoot.has(root)) byRoot.set(root, []);
|
|
677
|
+
byRoot.get(root).push({ id, shared, other });
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
const done = /* @__PURE__ */ new Set();
|
|
681
|
+
for (const [root, list] of [...byRoot].sort((x, y) => y[1].length - x[1].length)) {
|
|
682
|
+
const live = list.filter((x) => !done.has(x.id) && groups.has(x.id));
|
|
683
|
+
if (live.length < 2) continue;
|
|
684
|
+
const first = groups.get(live[0].id);
|
|
685
|
+
const shared = live[0].shared, container = parent(live[0].other);
|
|
686
|
+
const sharedEl = first.elements.find((e) => e.key === shared);
|
|
687
|
+
const others = live.map((x) => groups.get(x.id).elements.find((e) => e.key === x.other)?.text).filter(Boolean);
|
|
688
|
+
const merged = {
|
|
689
|
+
...first,
|
|
690
|
+
keys: [shared, container],
|
|
691
|
+
widths: [],
|
|
692
|
+
states: [],
|
|
693
|
+
instances: [],
|
|
694
|
+
elements: [sharedEl, { key: container, text: others.join(" \xB7 ").slice(0, 60) }]
|
|
695
|
+
};
|
|
696
|
+
for (const x of live) {
|
|
697
|
+
const g = groups.get(x.id);
|
|
698
|
+
merged.widths.push(...g.widths);
|
|
699
|
+
for (const st of g.states) if (!merged.states.some((s) => s.id === st.id)) merged.states.push(st);
|
|
700
|
+
merged.instances.push(...g.instances);
|
|
701
|
+
groups.delete(x.id);
|
|
702
|
+
done.add(x.id);
|
|
703
|
+
}
|
|
704
|
+
groups.set("text-overlap|" + shared + "+" + container, merged);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
function fingerprint(s) {
|
|
708
|
+
let h = 2166136261;
|
|
709
|
+
for (let i = 0; i < s.length; i++) {
|
|
710
|
+
h ^= s.charCodeAt(i);
|
|
711
|
+
h = Math.imul(h, 16777619);
|
|
712
|
+
}
|
|
713
|
+
return (h >>> 0).toString(36);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// src/core/highlight.js
|
|
717
|
+
var TOKENS = {
|
|
718
|
+
error: "hsla(358, 75%, 59%, 1)",
|
|
719
|
+
warning: "hsla(38, 92%, 50%, 1)",
|
|
720
|
+
info: "hsla(220, 9%, 46%, 1)",
|
|
721
|
+
labelText: "hsla(0, 0%, 100%, 1)",
|
|
722
|
+
halo: "hsla(0, 0%, 100%, 0.85)"
|
|
723
|
+
};
|
|
724
|
+
var findingLabel = (finding, width) => `${finding.title} \xB7 ${width} px`;
|
|
725
|
+
function highlight(doc, finding, { width, rect: fallback } = {}) {
|
|
726
|
+
const win = doc.defaultView;
|
|
727
|
+
clearHighlight(doc);
|
|
728
|
+
const els = (finding.elements || []).map((e) => {
|
|
729
|
+
try {
|
|
730
|
+
return doc.querySelector(e.key);
|
|
731
|
+
} catch {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
const main = els[0];
|
|
736
|
+
if (main) {
|
|
737
|
+
const b = main.getBoundingClientRect();
|
|
738
|
+
const left = b.left < 0 || b.right > win.innerWidth ? Math.max(0, win.scrollX + b.left - 16) : win.scrollX;
|
|
739
|
+
win.scrollTo(left, Math.max(0, win.scrollY + b.top - Math.max(48, (win.innerHeight - b.height) / 3)));
|
|
740
|
+
} else if (fallback) {
|
|
741
|
+
win.scrollTo(0, Math.max(0, fallback.top - win.innerHeight / 3));
|
|
742
|
+
}
|
|
743
|
+
const pageRect = (el) => {
|
|
744
|
+
const b = el.getBoundingClientRect();
|
|
745
|
+
return { left: b.left + win.scrollX, top: b.top + win.scrollY, right: b.right + win.scrollX, bottom: b.bottom + win.scrollY };
|
|
746
|
+
};
|
|
747
|
+
const r = main ? pageRect(main) : fallback;
|
|
748
|
+
if (!r) return { found: false, rect: null, remove: () => {
|
|
749
|
+
} };
|
|
750
|
+
const color = TOKENS[finding.severity] || TOKENS.error;
|
|
751
|
+
const host = doc.createElement("div");
|
|
752
|
+
host.setAttribute("data-rl-overlay", "highlight");
|
|
753
|
+
host.style.cssText = "all:initial;position:absolute;left:0;top:0;width:0;height:0;z-index:2147483646;pointer-events:none";
|
|
754
|
+
const root = host.attachShadow({ mode: "open" });
|
|
755
|
+
const box = (q, dashed) => {
|
|
756
|
+
const d = doc.createElement("div");
|
|
757
|
+
d.style.cssText = `position:absolute;box-sizing:border-box;left:${q.left - 3}px;top:${q.top - 3}px;width:${q.right - q.left + 6}px;height:${q.bottom - q.top + 6}px;border:2px ${dashed ? "dashed" : "solid"} ${color};border-radius:4px;box-shadow:0 0 0 2px ${TOKENS.halo}`;
|
|
758
|
+
d.setAttribute("part", dashed ? "other" : "outline");
|
|
759
|
+
root.append(d);
|
|
760
|
+
};
|
|
761
|
+
box(r, false);
|
|
762
|
+
if (els[1] && els[1] !== main) box(pageRect(els[1]), true);
|
|
763
|
+
const above = r.top - win.scrollY > 56 || r.top > 56;
|
|
764
|
+
const x = Math.min(Math.max(r.left + 12, 12), win.scrollX + win.innerWidth - 24);
|
|
765
|
+
const arrow = doc.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
766
|
+
arrow.setAttribute("width", "16");
|
|
767
|
+
arrow.setAttribute("height", "10");
|
|
768
|
+
arrow.setAttribute("viewBox", "0 0 16 10");
|
|
769
|
+
arrow.setAttribute("part", "pointer");
|
|
770
|
+
arrow.style.cssText = `position:absolute;left:${x}px;top:${above ? r.top - 15 : r.bottom + 5}px;overflow:visible;${above ? "" : "transform:rotate(180deg)"}`;
|
|
771
|
+
arrow.innerHTML = `<path d="M0 0 L16 0 L8 10 Z" fill="${color}"/>`;
|
|
772
|
+
root.append(arrow);
|
|
773
|
+
const label2 = doc.createElement("div");
|
|
774
|
+
label2.setAttribute("part", "label");
|
|
775
|
+
label2.textContent = findingLabel(finding, width ?? win.innerWidth);
|
|
776
|
+
label2.style.cssText = `position:absolute;left:${Math.max(4, x - 8)}px;top:${above ? r.top - 15 : r.bottom + 15}px;transform:${above ? "translateY(-100%)" : "none"};max-width:${Math.max(160, win.innerWidth - 24)}px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;background:${color};color:${TOKENS.labelText};font:600 12px/1.4 system-ui,-apple-system,sans-serif;padding:3px 8px;border-radius:5px`;
|
|
777
|
+
root.append(label2);
|
|
778
|
+
doc.body.append(host);
|
|
779
|
+
return { found: !!main, rect: r, remove: () => host.remove() };
|
|
780
|
+
}
|
|
781
|
+
function clearHighlight(doc) {
|
|
782
|
+
for (const el of doc.querySelectorAll('[data-rl-overlay="highlight"]')) el.remove();
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/core/recipe.js
|
|
786
|
+
var START_WIDTH = 1280;
|
|
787
|
+
function recipe(f, states, { url, route, storage, height }) {
|
|
788
|
+
const inst = f.instances[0];
|
|
789
|
+
const state = states.find((s) => s.id === inst?.state) || states[0];
|
|
790
|
+
const seen = f.instances.filter((i) => i.state === inst?.state).map((i) => i.width);
|
|
791
|
+
const band = f.bands.find(([a, b]) => seen.some((w) => w >= a && w <= b)) || f.bands[0];
|
|
792
|
+
const mid = (band[0] + band[1]) / 2;
|
|
793
|
+
const inBand = seen.filter((w) => w >= band[0] && w <= band[1]);
|
|
794
|
+
const width = (inBand.length ? inBand : seen.length ? seen : [Math.round(mid)]).reduce((best, w) => Math.abs(w - mid) < Math.abs(best - mid) ? w : best);
|
|
795
|
+
return { url, route, storage, width, height, startWidth: START_WIDTH, state: state.id, label: state.label, actions: state.actions || [] };
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// src/explore/page.js
|
|
799
|
+
var DANGEROUS = /\b(delete|remove|destroy|erase|log ?out|sign ?out|unsubscribe|pay|purchase|buy|checkout|submit|send|publish|reset)\b/i;
|
|
800
|
+
function discoverCandidates({ limit = 60 } = {}) {
|
|
801
|
+
const ctx = createContext();
|
|
802
|
+
const found = /* @__PURE__ */ new Set();
|
|
803
|
+
const nodes = [...document.querySelectorAll(INTERACTIVE_SELECTOR)];
|
|
804
|
+
for (const el of document.body.querySelectorAll("div,span,li,img,svg,label,h1,h2,h3,h4,p")) {
|
|
805
|
+
if (nodes.length > 4e3) break;
|
|
806
|
+
if (el.closest(INTERACTIVE_SELECTOR)) continue;
|
|
807
|
+
if (getComputedStyle(el).cursor === "pointer" && !(el.parentElement && getComputedStyle(el.parentElement).cursor === "pointer")) nodes.push(el);
|
|
808
|
+
}
|
|
809
|
+
const groups = /* @__PURE__ */ new Map();
|
|
810
|
+
for (const el of nodes) {
|
|
811
|
+
if (!(el instanceof Element) || found.has(el) || el.closest("[data-rl-overlay]")) continue;
|
|
812
|
+
found.add(el);
|
|
813
|
+
if (el.closest("[data-rl-never]") || el.matches("[disabled],[aria-disabled=true]")) continue;
|
|
814
|
+
if (el.matches("input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]),textarea,select")) continue;
|
|
815
|
+
if (el.matches("[type=submit],button:not([type])") && el.closest("form")) continue;
|
|
816
|
+
const r = el.getBoundingClientRect();
|
|
817
|
+
if (r.width < 4 || r.height < 4 || ctx.hidden(el)) continue;
|
|
818
|
+
const name = label(el, (el.textContent || "").trim());
|
|
819
|
+
if (DANGEROUS.test(name)) continue;
|
|
820
|
+
let href = null;
|
|
821
|
+
if (el.matches("a[href]")) {
|
|
822
|
+
const url = new URL(el.getAttribute("href"), location.href);
|
|
823
|
+
if (url.origin !== location.origin || el.hasAttribute("download") || el.target === "_blank") continue;
|
|
824
|
+
if (url.pathname !== location.pathname) continue;
|
|
825
|
+
href = url.hash;
|
|
826
|
+
}
|
|
827
|
+
const sig = [el.tagName, el.getAttribute("role") || "", el.parentElement?.tagName || "", el.className && typeof el.className === "string" ? el.className.split(/\s+/).sort().join(".") : ""].join("|");
|
|
828
|
+
if (!groups.has(sig)) groups.set(sig, []);
|
|
829
|
+
groups.get(sig).push({
|
|
830
|
+
key: elementKey(el),
|
|
831
|
+
label: name || el.tagName.toLowerCase(),
|
|
832
|
+
role: el.getAttribute("role") || el.tagName.toLowerCase(),
|
|
833
|
+
expanded: el.getAttribute("aria-expanded"),
|
|
834
|
+
href,
|
|
835
|
+
area: Math.round(r.width * r.height),
|
|
836
|
+
top: Math.round(r.top + scrollY)
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
const out = [];
|
|
840
|
+
for (const list of groups.values()) out.push({ ...list[0], repeats: list.length });
|
|
841
|
+
out.sort((a, b) => (b.expanded != null) - (a.expanded != null) || a.top - b.top);
|
|
842
|
+
return out.slice(0, limit);
|
|
843
|
+
}
|
|
844
|
+
function layoutSignature({ max = 2500 } = {}) {
|
|
845
|
+
const out = [];
|
|
846
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
847
|
+
for (let el = walker.currentNode; el && out.length < max; el = walker.nextNode()) {
|
|
848
|
+
if (!(el instanceof HTMLElement) || el.closest("[data-rl-overlay]")) continue;
|
|
849
|
+
const r = el.getBoundingClientRect();
|
|
850
|
+
if (r.width * r.height < 400) continue;
|
|
851
|
+
const s = getComputedStyle(el);
|
|
852
|
+
if (s.visibility !== "visible" || +s.opacity < 0.05) continue;
|
|
853
|
+
out.push([elementKey(el), Math.round(r.left + scrollX), Math.round(r.top + scrollY), Math.round(r.width), Math.round(r.height)]);
|
|
854
|
+
}
|
|
855
|
+
return { url: location.href, hash: location.hash, boxes: out };
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/core/bar.js
|
|
859
|
+
var T = {
|
|
860
|
+
bg: "hsla(222, 18%, 13%, 0.96)",
|
|
861
|
+
fg: "hsla(0, 0%, 100%, 0.95)",
|
|
862
|
+
muted: "hsla(220, 12%, 72%, 1)",
|
|
863
|
+
line: "hsla(0, 0%, 100%, 0.14)",
|
|
864
|
+
hover: "hsla(0, 0%, 100%, 0.08)",
|
|
865
|
+
link: "hsla(212, 92%, 72%, 1)",
|
|
866
|
+
shadow: "hsla(0, 0%, 0%, 0.28)"
|
|
867
|
+
};
|
|
868
|
+
var CSS = `
|
|
869
|
+
:host { all: initial; }
|
|
870
|
+
.bar { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2147483647; box-sizing: border-box;
|
|
871
|
+
width: min(560px, calc(100vw - 16px)); background: ${T.bg}; color: ${T.fg}; border-radius: 12px; padding: 10px 12px;
|
|
872
|
+
box-shadow: 0 8px 28px ${T.shadow}; font: 13px/1.45 system-ui, -apple-system, sans-serif; }
|
|
873
|
+
.nav { display: flex; align-items: center; gap: 6px; }
|
|
874
|
+
button { all: unset; cursor: pointer; padding: 3px 10px; border-radius: 7px; border: 1px solid ${T.line}; color: ${T.fg}; font: inherit; }
|
|
875
|
+
button:hover:not([disabled]) { background: ${T.hover}; }
|
|
876
|
+
button[disabled] { opacity: .4; cursor: default; }
|
|
877
|
+
button.close { border-color: transparent; margin-left: auto; padding: 3px 8px; font-size: 16px; line-height: 1; }
|
|
878
|
+
.count { color: ${T.muted}; min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
|
|
879
|
+
.title { margin-top: 8px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
|
|
880
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; transform: translateY(-1px); }
|
|
881
|
+
.where, .note, .skill { color: ${T.muted}; margin-top: 2px; }
|
|
882
|
+
.try { margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
|
|
883
|
+
a { color: ${T.link}; text-decoration: none; }
|
|
884
|
+
a:hover { text-decoration: none; opacity: .85; }
|
|
885
|
+
[hidden] { display: none !important; }
|
|
886
|
+
`;
|
|
887
|
+
var fmtWhere = (f) => (f.bands || []).map(([a, b]) => a === b ? `${a}` : `${a}\u2013${b}`).join(", ") + " px";
|
|
888
|
+
function createBar(doc, { onPrev, onNext, onClose } = {}) {
|
|
889
|
+
const host = doc.createElement("div");
|
|
890
|
+
host.setAttribute("data-rl-overlay", "bar");
|
|
891
|
+
const root = host.attachShadow({ mode: "open" });
|
|
892
|
+
root.innerHTML = `<style>${CSS}</style><div class="bar" role="dialog" aria-label="ResponsiveLint replay">
|
|
893
|
+
<div class="nav"><button class="prev" type="button">\u2039 Previous</button><span class="count"></span><button class="next" type="button">Next \u203A</button>
|
|
894
|
+
<button class="close" type="button" aria-label="Close">\xD7</button></div>
|
|
895
|
+
<div class="title"><span class="dot"></span><span class="text"></span></div>
|
|
896
|
+
<div class="where"></div><div class="try"></div><div class="skill"></div><div class="note" hidden></div></div>`;
|
|
897
|
+
const $ = (s) => root.querySelector(s);
|
|
898
|
+
$(".prev").onclick = () => onPrev?.();
|
|
899
|
+
$(".next").onclick = () => onNext?.();
|
|
900
|
+
$(".close").onclick = () => onClose?.();
|
|
901
|
+
const key = (e) => {
|
|
902
|
+
if (e.target?.closest?.("input,textarea,select,[contenteditable]")) return;
|
|
903
|
+
if (e.key === "ArrowRight") onNext?.();
|
|
904
|
+
else if (e.key === "ArrowLeft") onPrev?.();
|
|
905
|
+
else if (e.key === "Escape") onClose?.();
|
|
906
|
+
else return;
|
|
907
|
+
e.preventDefault();
|
|
908
|
+
};
|
|
909
|
+
doc.addEventListener("keydown", key, true);
|
|
910
|
+
(doc.body || doc.documentElement).append(host);
|
|
911
|
+
return {
|
|
912
|
+
host,
|
|
913
|
+
update({ finding: f, index, total, width, note, busy }) {
|
|
914
|
+
$(".count").textContent = `${index + 1} of ${total}`;
|
|
915
|
+
$(".prev").disabled = busy || index <= 0;
|
|
916
|
+
$(".next").disabled = busy || index >= total - 1;
|
|
917
|
+
$(".dot").style.background = TOKENS[f.severity] || TOKENS.error;
|
|
918
|
+
$(".text").textContent = f.title;
|
|
919
|
+
const states = (f.states || []).join(" \xB7 ");
|
|
920
|
+
$(".where").textContent = `${fmtWhere(f)}${states ? " \xB7 " + states : ""}${width ? ` \xB7 shown at ${width} px` : ""}`;
|
|
921
|
+
$(".try").textContent = f.tries?.[0] ? "Try: " + f.tries[0] : "";
|
|
922
|
+
const sk = $(".skill");
|
|
923
|
+
sk.textContent = "";
|
|
924
|
+
if (f.skill?.url) {
|
|
925
|
+
const a = doc.createElement("a");
|
|
926
|
+
a.href = f.skill.url;
|
|
927
|
+
a.target = "_blank";
|
|
928
|
+
a.rel = "noopener";
|
|
929
|
+
a.textContent = f.skill.name;
|
|
930
|
+
sk.append("Fix skill: ", a);
|
|
931
|
+
}
|
|
932
|
+
$(".note").hidden = !(note || busy);
|
|
933
|
+
$(".note").textContent = busy ? "Loading from the start\u2026" : note || "";
|
|
934
|
+
},
|
|
935
|
+
remove() {
|
|
936
|
+
doc.removeEventListener("keydown", key, true);
|
|
937
|
+
host.remove();
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/core/inject.js
|
|
943
|
+
globalThis.__ResponsiveLint = { ...index_exports, discoverCandidates, layoutSignature, createBar };
|
|
944
|
+
})();
|