responsivelint 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -7
- package/agents/skills/responsivelint/SKILL.md +16 -3
- package/bin/responsivelint.mjs +40 -3
- package/dist/core.iife.js +172 -1
- package/dist/responsivelint.js +399 -5
- package/dist/responsivelint.min.js +25 -3
- package/llms.txt +10 -3
- package/package.json +1 -1
- package/src/browser/entry.js +205 -6
- package/src/cli/replay.js +86 -0
- package/src/cli/run.js +109 -45
- package/src/core/bar.js +78 -0
- package/src/core/highlight.js +73 -0
- package/src/core/index.js +2 -0
- package/src/core/inject.js +2 -1
- package/src/core/recipe.js +19 -0
- package/src/index.js +1 -0
package/src/core/bar.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The replay bar: Previous, "n of N", Next and close, with the finding's title, where it happens and the first
|
|
2
|
+
// thing to try. It lives in a shadow root so the page's styles cannot reach it, and it is never measured.
|
|
3
|
+
import {TOKENS} from './highlight.js';
|
|
4
|
+
|
|
5
|
+
const T = {
|
|
6
|
+
bg: 'hsla(222, 18%, 13%, 0.96)',
|
|
7
|
+
fg: 'hsla(0, 0%, 100%, 0.95)',
|
|
8
|
+
muted: 'hsla(220, 12%, 72%, 1)',
|
|
9
|
+
line: 'hsla(0, 0%, 100%, 0.14)',
|
|
10
|
+
hover: 'hsla(0, 0%, 100%, 0.08)',
|
|
11
|
+
link: 'hsla(212, 92%, 72%, 1)',
|
|
12
|
+
shadow: 'hsla(0, 0%, 0%, 0.28)',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const CSS = `
|
|
16
|
+
:host { all: initial; }
|
|
17
|
+
.bar { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2147483647; box-sizing: border-box;
|
|
18
|
+
width: min(560px, calc(100vw - 16px)); background: ${T.bg}; color: ${T.fg}; border-radius: 12px; padding: 10px 12px;
|
|
19
|
+
box-shadow: 0 8px 28px ${T.shadow}; font: 13px/1.45 system-ui, -apple-system, sans-serif; }
|
|
20
|
+
.nav { display: flex; align-items: center; gap: 6px; }
|
|
21
|
+
button { all: unset; cursor: pointer; padding: 3px 10px; border-radius: 7px; border: 1px solid ${T.line}; color: ${T.fg}; font: inherit; }
|
|
22
|
+
button:hover:not([disabled]) { background: ${T.hover}; }
|
|
23
|
+
button[disabled] { opacity: .4; cursor: default; }
|
|
24
|
+
button.close { border-color: transparent; margin-left: auto; padding: 3px 8px; font-size: 16px; line-height: 1; }
|
|
25
|
+
.count { color: ${T.muted}; min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
|
|
26
|
+
.title { margin-top: 8px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
|
|
27
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; transform: translateY(-1px); }
|
|
28
|
+
.where, .note, .skill { color: ${T.muted}; margin-top: 2px; }
|
|
29
|
+
.try { margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
|
|
30
|
+
a { color: ${T.link}; text-decoration: none; }
|
|
31
|
+
a:hover { text-decoration: none; opacity: .85; }
|
|
32
|
+
[hidden] { display: none !important; }
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const fmtWhere = (f) => (f.bands || []).map(([a, b]) => (a === b ? `${a}` : `${a}–${b}`)).join(', ') + ' px';
|
|
36
|
+
|
|
37
|
+
/** createBar(doc, {onPrev, onNext, onClose}) → {update({finding, index, total, width, note, busy}), remove()} */
|
|
38
|
+
export function createBar(doc, {onPrev, onNext, onClose} = {}) {
|
|
39
|
+
const host = doc.createElement('div');
|
|
40
|
+
host.setAttribute('data-rl-overlay', 'bar');
|
|
41
|
+
const root = host.attachShadow({mode: 'open'});
|
|
42
|
+
root.innerHTML = `<style>${CSS}</style><div class="bar" role="dialog" aria-label="ResponsiveLint replay">
|
|
43
|
+
<div class="nav"><button class="prev" type="button">‹ Previous</button><span class="count"></span><button class="next" type="button">Next ›</button>
|
|
44
|
+
<button class="close" type="button" aria-label="Close">×</button></div>
|
|
45
|
+
<div class="title"><span class="dot"></span><span class="text"></span></div>
|
|
46
|
+
<div class="where"></div><div class="try"></div><div class="skill"></div><div class="note" hidden></div></div>`;
|
|
47
|
+
const $ = (s) => root.querySelector(s);
|
|
48
|
+
$('.prev').onclick = () => onPrev?.();
|
|
49
|
+
$('.next').onclick = () => onNext?.();
|
|
50
|
+
$('.close').onclick = () => onClose?.();
|
|
51
|
+
const key = (e) => {
|
|
52
|
+
if (e.target?.closest?.('input,textarea,select,[contenteditable]')) return;
|
|
53
|
+
if (e.key === 'ArrowRight') onNext?.(); else if (e.key === 'ArrowLeft') onPrev?.(); else if (e.key === 'Escape') onClose?.(); else return;
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
};
|
|
56
|
+
doc.addEventListener('keydown', key, true);
|
|
57
|
+
(doc.body || doc.documentElement).append(host);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
host,
|
|
61
|
+
update({finding: f, index, total, width, note, busy}) {
|
|
62
|
+
$('.count').textContent = `${index + 1} of ${total}`;
|
|
63
|
+
$('.prev').disabled = busy || index <= 0;
|
|
64
|
+
$('.next').disabled = busy || index >= total - 1;
|
|
65
|
+
$('.dot').style.background = TOKENS[f.severity] || TOKENS.error;
|
|
66
|
+
$('.text').textContent = f.title;
|
|
67
|
+
const states = (f.states || []).join(' · ');
|
|
68
|
+
$('.where').textContent = `${fmtWhere(f)}${states ? ' · ' + states : ''}${width ? ` · shown at ${width} px` : ''}`;
|
|
69
|
+
$('.try').textContent = f.tries?.[0] ? 'Try: ' + f.tries[0] : '';
|
|
70
|
+
const sk = $('.skill');
|
|
71
|
+
sk.textContent = '';
|
|
72
|
+
if (f.skill?.url) { const a = doc.createElement('a'); a.href = f.skill.url; a.target = '_blank'; a.rel = 'noopener'; a.textContent = f.skill.name; sk.append('Fix skill: ', a); }
|
|
73
|
+
$('.note').hidden = !(note || busy);
|
|
74
|
+
$('.note').textContent = busy ? 'Loading from the start…' : note || '';
|
|
75
|
+
},
|
|
76
|
+
remove() { doc.removeEventListener('keydown', key, true); host.remove(); },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Points at a finding on the page: an outline, a pointer and the finding's own label. Nothing else is written
|
|
2
|
+
// to the page. Used by the in-page replay (inside its frame) and by the command-line replay.
|
|
3
|
+
|
|
4
|
+
export const TOKENS = {
|
|
5
|
+
error: 'hsla(358, 75%, 59%, 1)',
|
|
6
|
+
warning: 'hsla(38, 92%, 50%, 1)',
|
|
7
|
+
info: 'hsla(220, 9%, 46%, 1)',
|
|
8
|
+
labelText: 'hsla(0, 0%, 100%, 1)',
|
|
9
|
+
halo: 'hsla(0, 0%, 100%, 0.85)',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** The label the highlighter shows: the finding's title and the width it is shown at. */
|
|
13
|
+
export const findingLabel = (finding, width) => `${finding.title} · ${width} px`;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* highlight(doc, finding, {width, rect}) scrolls the finding's element into view and draws the outline, the
|
|
17
|
+
* pointer and the label. rect (page coordinates) is used when the element cannot be found. Returns
|
|
18
|
+
* {found, rect, remove}.
|
|
19
|
+
*/
|
|
20
|
+
export function highlight(doc, finding, {width, rect: fallback} = {}) {
|
|
21
|
+
const win = doc.defaultView;
|
|
22
|
+
clearHighlight(doc);
|
|
23
|
+
const els = (finding.elements || []).map((e) => { try { return doc.querySelector(e.key); } catch { return null; } });
|
|
24
|
+
const main = els[0];
|
|
25
|
+
if (main) {
|
|
26
|
+
const b = main.getBoundingClientRect();
|
|
27
|
+
const left = b.left < 0 || b.right > win.innerWidth ? Math.max(0, win.scrollX + b.left - 16) : win.scrollX;
|
|
28
|
+
win.scrollTo(left, Math.max(0, win.scrollY + b.top - Math.max(48, (win.innerHeight - b.height) / 3)));
|
|
29
|
+
} else if (fallback) {
|
|
30
|
+
win.scrollTo(0, Math.max(0, fallback.top - win.innerHeight / 3));
|
|
31
|
+
}
|
|
32
|
+
const pageRect = (el) => { const b = el.getBoundingClientRect(); return {left: b.left + win.scrollX, top: b.top + win.scrollY, right: b.right + win.scrollX, bottom: b.bottom + win.scrollY}; };
|
|
33
|
+
const r = main ? pageRect(main) : fallback;
|
|
34
|
+
if (!r) return {found: false, rect: null, remove: () => {}};
|
|
35
|
+
|
|
36
|
+
const color = TOKENS[finding.severity] || TOKENS.error;
|
|
37
|
+
const host = doc.createElement('div');
|
|
38
|
+
host.setAttribute('data-rl-overlay', 'highlight');
|
|
39
|
+
host.style.cssText = 'all:initial;position:absolute;left:0;top:0;width:0;height:0;z-index:2147483646;pointer-events:none';
|
|
40
|
+
const root = host.attachShadow({mode: 'open'});
|
|
41
|
+
const box = (q, dashed) => {
|
|
42
|
+
const d = doc.createElement('div');
|
|
43
|
+
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;` +
|
|
44
|
+
`border:2px ${dashed ? 'dashed' : 'solid'} ${color};border-radius:4px;box-shadow:0 0 0 2px ${TOKENS.halo}`;
|
|
45
|
+
d.setAttribute('part', dashed ? 'other' : 'outline');
|
|
46
|
+
root.append(d);
|
|
47
|
+
};
|
|
48
|
+
box(r, false);
|
|
49
|
+
if (els[1] && els[1] !== main) box(pageRect(els[1]), true);
|
|
50
|
+
|
|
51
|
+
// The pointer sits above the element, or below it when there is no room above.
|
|
52
|
+
const above = r.top - win.scrollY > 56 || r.top > 56;
|
|
53
|
+
const x = Math.min(Math.max(r.left + 12, 12), win.scrollX + win.innerWidth - 24);
|
|
54
|
+
const arrow = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
55
|
+
arrow.setAttribute('width', '16'); arrow.setAttribute('height', '10'); arrow.setAttribute('viewBox', '0 0 16 10');
|
|
56
|
+
arrow.setAttribute('part', 'pointer');
|
|
57
|
+
arrow.style.cssText = `position:absolute;left:${x}px;top:${above ? r.top - 15 : r.bottom + 5}px;overflow:visible;${above ? '' : 'transform:rotate(180deg)'}`;
|
|
58
|
+
arrow.innerHTML = `<path d="M0 0 L16 0 L8 10 Z" fill="${color}"/>`;
|
|
59
|
+
root.append(arrow);
|
|
60
|
+
const label = doc.createElement('div');
|
|
61
|
+
label.setAttribute('part', 'label');
|
|
62
|
+
label.textContent = findingLabel(finding, width ?? win.innerWidth);
|
|
63
|
+
label.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'};` +
|
|
64
|
+
`max-width:${Math.max(160, win.innerWidth - 24)}px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;` +
|
|
65
|
+
`background:${color};color:${TOKENS.labelText};font:600 12px/1.4 system-ui,-apple-system,sans-serif;padding:3px 8px;border-radius:5px`;
|
|
66
|
+
root.append(label);
|
|
67
|
+
doc.body.append(host);
|
|
68
|
+
return {found: !!main, rect: r, remove: () => host.remove()};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function clearHighlight(doc) {
|
|
72
|
+
for (const el of doc.querySelectorAll('[data-rl-overlay="highlight"]')) el.remove();
|
|
73
|
+
}
|
package/src/core/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export {checkNow, detectEnvironment} from './measure.js';
|
|
2
2
|
export {analyze, sweepOutliers, bands, RULES, PACKS, FIX_SKILLS, skillFor, fingerprint} from './analyze.js';
|
|
3
3
|
export {elementKey, INTERACTIVE_SELECTOR} from './dom.js';
|
|
4
|
+
export {highlight, clearHighlight, findingLabel} from './highlight.js';
|
|
5
|
+
export {recipe, START_WIDTH} from './recipe.js';
|
package/src/core/inject.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Entry for the injected build: the command line adds this to each page it checks.
|
|
2
2
|
import * as core from './index.js';
|
|
3
3
|
import {discoverCandidates, layoutSignature} from '../explore/page.js';
|
|
4
|
-
|
|
4
|
+
import {createBar} from './bar.js';
|
|
5
|
+
globalThis.__ResponsiveLint = {...core, discoverCandidates, layoutSignature, createBar};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The replay recipe of a finding. Shared by the command line and the script tag.
|
|
2
|
+
|
|
3
|
+
export const START_WIDTH = 1280;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Everything needed to reproduce a finding from zero: load url at startWidth (with storage), do the clicks in
|
|
7
|
+
* actions, then set the width. width is a checked width inside the finding's first band in that state, nearest
|
|
8
|
+
* the band's middle. url already includes route.
|
|
9
|
+
*/
|
|
10
|
+
export function recipe(f, states, {url, route, storage, height}) {
|
|
11
|
+
const inst = f.instances[0];
|
|
12
|
+
const state = states.find((s) => s.id === inst?.state) || states[0];
|
|
13
|
+
const seen = f.instances.filter((i) => i.state === inst?.state).map((i) => i.width);
|
|
14
|
+
const band = f.bands.find(([a, b]) => seen.some((w) => w >= a && w <= b)) || f.bands[0];
|
|
15
|
+
const mid = (band[0] + band[1]) / 2;
|
|
16
|
+
const inBand = seen.filter((w) => w >= band[0] && w <= band[1]);
|
|
17
|
+
const width = (inBand.length ? inBand : seen.length ? seen : [Math.round(mid)]).reduce((best, w) => (Math.abs(w - mid) < Math.abs(best - mid) ? w : best));
|
|
18
|
+
return {url, route, storage, width, height, startWidth: START_WIDTH, state: state.id, label: state.label, actions: state.actions || []};
|
|
19
|
+
}
|
package/src/index.js
CHANGED