responsivelint 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/agents/skills/responsivelint/SKILL.md +44 -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 +74 -0
- package/dist/core.iife.js +773 -0
- package/dist/responsivelint.js +838 -0
- package/dist/responsivelint.min.js +3 -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 +42 -0
- package/package.json +43 -4
- package/src/browser/entry.js +138 -0
- package/src/cli/report.js +90 -0
- package/src/cli/run.js +177 -0
- package/src/cli/server.js +24 -0
- package/src/core/analyze.js +265 -0
- package/src/core/dom.js +122 -0
- package/src/core/index.js +3 -0
- package/src/core/inject.js +4 -0
- package/src/core/measure.js +241 -0
- package/src/explore/page.js +63 -0
- package/src/icons/measure.js +106 -0
- package/src/index.js +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prajwal DSouza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ResponsiveLint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## What it does
|
|
4
|
+
|
|
5
|
+
ResponsiveLint finds where a web page's layout breaks as the window changes width. It opens the page in Chromium, tries clicks that can open menus or panels, and checks the starting layout and the states it finds. It compares the same element at nearby widths, so it can catch a problem that appears only between two breakpoints.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
▲ width-outlier Breaks only in a narrow band of widths high confidence
|
|
9
|
+
element "Citation style for papers, as used in psychology, education " body>main:nth-child(2)>div:nth-child(1)>b:nth-child(1)
|
|
10
|
+
where 944–992 px · Default · after clicking button "Show details"
|
|
11
|
+
measured lines 13, wordsPerLine 1 neighbours lines 1, wordsPerLine 13
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This finding points to the element whose text jumps from one line to 13. Resize the page to a width in the reported range to see it.
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
With Node.js 20 or newer, start your site's dev server. In another terminal, run this with your site's address.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npx responsivelint http://localhost:5173
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The first run needs Chromium. If you see `ResponsiveLint could not find Chromium. Run: npx playwright install chromium`, run the install command and try again.
|
|
25
|
+
|
|
26
|
+
If you are running ResponsiveLint via `npx` without installing it in your project, use the Playwright version that matches ResponsiveLint 0.1.0.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npx --yes --package=playwright@1.59.1 playwright install chromium
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You can also pass a built site folder. Add report options to save the findings alongside the terminal output.
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npx responsivelint ./dist --json report.json --html report.html
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Use it in the page
|
|
39
|
+
|
|
40
|
+
Add this script to a local development page. The URL loads the browser build from npm through jsDelivr.
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script src="https://cdn.jsdelivr.net/npm/responsivelint@0.1.0/dist/responsivelint.js" data-ui data-sweep></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- Findings appear once each in DevTools with a reference to the affected element.
|
|
47
|
+
- `data-ui` outlines problems and lists them in a panel.
|
|
48
|
+
- `data-sweep` checks widths in a hidden copy of the current page. Use the command line when you want to explore click states.
|
|
49
|
+
- `data-anywhere` enables startup on other hosts. Automatic startup normally runs on `localhost`, `127.0.0.1`, `[::1]`, `*.localhost`, `*.test` and `file:` pages.
|
|
50
|
+
|
|
51
|
+
In DevTools, call `window.ResponsiveLint.check()` to check the current width, `await window.ResponsiveLint.sweep()` to sweep widths, or `window.ResponsiveLint.ui(false)` to close the panel. Read the results from `window.ResponsiveLint.findings`.
|
|
52
|
+
|
|
53
|
+
## What it checks
|
|
54
|
+
|
|
55
|
+
- [text-overlap](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/text-overlap.md) finds visible text drawn over other text.
|
|
56
|
+
- [squashed-text](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/squashed-text.md) finds text squeezed to about one word per line.
|
|
57
|
+
- [clipped-text](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/clipped-text.md) finds text partly hidden by its box.
|
|
58
|
+
- [page-overflow](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/page-overflow.md) names the element that makes the page scroll sideways.
|
|
59
|
+
- [hidden-control](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/hidden-control.md) finds clickable controls that are fully transparent at rest.
|
|
60
|
+
- [width-outlier](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/width-outlier.md) finds elements that break only in a narrow range of widths.
|
|
61
|
+
- [disappears-in-band](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/disappears-in-band.md) finds controls that disappear only in a narrow range of widths.
|
|
62
|
+
|
|
63
|
+
## Options
|
|
64
|
+
|
|
65
|
+
The default sweep checks widths from 320 to 1920 px in 48 px steps and includes the endpoint. Use `--step 1` to check every whole-pixel width in a range. State discovery checks one click from the starting page.
|
|
66
|
+
|
|
67
|
+
| Option | What it does |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `--mode quick\|normal\|aggressive` | Quick checks four widths with no extra states. Normal checks up to eight extra states. Aggressive uses 24 px steps and up to 20 extra states. |
|
|
70
|
+
| `--only text,overflow` | Runs only the named rules or rule groups. Groups are `text`, `overlap`, `visibility`, `overflow` and `sweep`. |
|
|
71
|
+
| `--skip sweep` | Skips the named rules or groups. Separate multiple names with commas. |
|
|
72
|
+
| `--from 320 --to 1920 --step 48` | Sets the starting width, ending width and spacing in pixels. |
|
|
73
|
+
| `--states 8` | Caps the number of extra states to check. Use `0` for the starting page only. |
|
|
74
|
+
| `--route '#/settings'` | Starts at a path or hash route of the target. |
|
|
75
|
+
| `--storage key=value` | Sets a localStorage value before loading the page. Repeat for more values. |
|
|
76
|
+
| `--json report.json` | Saves findings and run details as JSON. |
|
|
77
|
+
| `--html report.html` | Saves a report you can open in a browser. |
|
|
78
|
+
| `--evidence 12` | Takes screenshots for the first N findings where evidence is available. HTML reports default to 12. |
|
|
79
|
+
| `--min-confidence high\|medium` | Hides findings below the chosen confidence level. |
|
|
80
|
+
| `--strict` | Treats warnings as failures too. |
|
|
81
|
+
| `--allow-remote` | Allows a target outside the local and test hosts. |
|
|
82
|
+
|
|
83
|
+
Exit code `0` means no findings met the failure threshold. Code `1` means the report contains errors, or warnings with `--strict`. Code `2` means the command failed to run or received an unknown option.
|
|
84
|
+
|
|
85
|
+
## Use in CI
|
|
86
|
+
|
|
87
|
+
This GitHub Actions workflow assumes `npm run dev` starts your site on port 5173. The report uploads even when layout findings fail the job.
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
name: ResponsiveLint
|
|
91
|
+
on: [push, pull_request]
|
|
92
|
+
jobs:
|
|
93
|
+
layout:
|
|
94
|
+
runs-on: ubuntu-latest
|
|
95
|
+
steps:
|
|
96
|
+
- uses: actions/checkout@v4
|
|
97
|
+
- uses: actions/setup-node@v4
|
|
98
|
+
with:
|
|
99
|
+
node-version: 22
|
|
100
|
+
- run: npm ci
|
|
101
|
+
- run: npx --yes --package=playwright@1.59.1 playwright install --with-deps chromium
|
|
102
|
+
- run: |
|
|
103
|
+
npm run dev &
|
|
104
|
+
curl --fail --retry 15 --retry-connrefused --retry-delay 1 http://localhost:5173 > /dev/null
|
|
105
|
+
npx --yes responsivelint@0.1.0 http://localhost:5173 --html report.html
|
|
106
|
+
- uses: actions/upload-artifact@v4
|
|
107
|
+
if: always()
|
|
108
|
+
with:
|
|
109
|
+
name: responsivelint-report
|
|
110
|
+
path: report.html
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## For AI agents
|
|
114
|
+
|
|
115
|
+
Start with [llms.txt](https://github.com/prajwalsouza/ResponsiveLint/blob/main/llms.txt). The skills in
|
|
116
|
+
[agents/skills](https://github.com/prajwalsouza/ResponsiveLint/tree/main/agents/skills) are short guides an agent loads when it needs them:
|
|
117
|
+
|
|
118
|
+
| Skill | Load it to |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| [responsivelint](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint/SKILL.md) | Run a check and read the report |
|
|
121
|
+
| [responsivelint-fix](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint-fix/SKILL.md) | Work through a report and pick the right fix skill |
|
|
122
|
+
| [responsivelint-fix-overlap](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint-fix-overlap/SKILL.md) | Fix `text-overlap` |
|
|
123
|
+
| [responsivelint-fix-cramped-text](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint-fix-cramped-text/SKILL.md) | Fix `squashed-text`, `clipped-text` and `width-outlier` |
|
|
124
|
+
| [responsivelint-fix-overflow](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint-fix-overflow/SKILL.md) | Fix `page-overflow` |
|
|
125
|
+
| [responsivelint-fix-controls](https://github.com/prajwalsouza/ResponsiveLint/blob/main/agents/skills/responsivelint-fix-controls/SKILL.md) | Fix `hidden-control` and `disappears-in-band` |
|
|
126
|
+
|
|
127
|
+
Every finding names its fix skill, so an agent loads only what the report needs. The skills also ship in the
|
|
128
|
+
npm package, in `node_modules/responsivelint/agents/skills/`. To install them, copy the folders into your
|
|
129
|
+
project's `.claude/skills/` or `.agents/skills/`, one folder per skill:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
cp -R node_modules/responsivelint/agents/skills/* .claude/skills/
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Run with `--json report.json`. The top-level `widths` and `states` say what was checked. Each finding has:
|
|
136
|
+
|
|
137
|
+
| Field | Meaning |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `rule`, `severity`, `confidence` | What was found and how sure the check is |
|
|
140
|
+
| `elements` | The element: a CSS selector in `key` and its visible `text` |
|
|
141
|
+
| `bands`, `states` | The widths in pixels and the states (clicks) where it happens |
|
|
142
|
+
| `measured`, `expected` | What was measured; for sweep rules, the same element at nearby widths |
|
|
143
|
+
| `why` | Why it is a problem |
|
|
144
|
+
| `tries` | The usual causes and their fixes, most likely first, ordered by what was measured |
|
|
145
|
+
| `skill` | The fix skill: `name`, `file` in the package, `url` |
|
|
146
|
+
| `guide`, `suppress` | The rule guide, and the attribute that silences the rule when a layout is intended |
|
|
147
|
+
|
|
148
|
+
## Ignoring and safety
|
|
149
|
+
|
|
150
|
+
Use `data-rl-ignore="rule-name"` on an element or its container for an intentional layout. Use `data-rl-ignore` without a value to suppress all rules there. Add `data-rl-never` to a control or its container to keep the command from clicking it.
|
|
151
|
+
|
|
152
|
+
The command accepts local and test hosts by default. Use `--allow-remote` to check another host. During a check it blocks POST, PUT, PATCH and DELETE requests and navigation to other sites. It dismisses dialogs, skips form submit controls, avoids typing into fields and skips controls with names that suggest actions such as deleting, paying or sending.
|
|
153
|
+
|
|
154
|
+
## Important files
|
|
155
|
+
|
|
156
|
+
| Where | What you will find |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| [bin/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/bin) | The terminal command and its options. |
|
|
159
|
+
| [src/core/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/src/core) | Page measurements and rules. |
|
|
160
|
+
| [src/cli/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/src/cli) | The browser runner and report writers. |
|
|
161
|
+
| [src/browser/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/src/browser) | The script tag entry point and page overlay. |
|
|
162
|
+
| [docs/rules/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/docs/rules) | A guide for each rule. |
|
|
163
|
+
| [agents/skills/](https://github.com/prajwalsouza/ResponsiveLint/tree/main/agents/skills) | Agent Skills: running a check, and one fix skill per group of rules. |
|
|
164
|
+
| [llms.txt](https://github.com/prajwalsouza/ResponsiveLint/blob/main/llms.txt) | A short reference for agents. |
|
|
165
|
+
|
|
166
|
+
## Acknowledgements
|
|
167
|
+
|
|
168
|
+
ResponsiveLint builds on ideas from ReDeCheck (Walsh, Kapfhammer and McMinn, 2017), which compares a page's layout across widths, and from uilint, OverflowLint, ghost-qa, eva-qa, boxy-layout and Crawljax.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
[MIT](https://github.com/prajwalsouza/ResponsiveLint/blob/main/LICENSE)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint
|
|
3
|
+
description: "Use when checking whether a web page's layout holds across screen widths and in states reachable in one click (sidebar collapsed, menu or panel opened, dialog shown), or when a layout breaks on mobile, when resizing, or at one particular width: overlapping text, text cut off, labels squeezed to one word per line, the page scrolling sideways, invisible buttons. Runs ResponsiveLint and reads its findings."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ResponsiveLint
|
|
7
|
+
|
|
8
|
+
ResponsiveLint opens a page in a real browser, finds states a reader can reach in one click, and sweeps a range of widths in each state. It compares each element with itself at
|
|
9
|
+
neighbouring widths, so it finds the band of widths where something breaks, not only problems at fixed sizes.
|
|
10
|
+
|
|
11
|
+
## Run it
|
|
12
|
+
|
|
13
|
+
1. Start the project's dev server, or build it to a folder.
|
|
14
|
+
2. Install Chromium with `npx playwright install chromium` if it is missing. See the [quick start](https://github.com/prajwalsouza/ResponsiveLint#quick-start) for the matching Playwright version when using `npx` alone.
|
|
15
|
+
3. Run `npx responsivelint http://localhost:5173 --json .responsivelint/report.json`
|
|
16
|
+
(or `node bin/responsivelint.mjs …` inside the ResponsiveLint repository). For a folder, pass the folder.
|
|
17
|
+
4. For a page behind a hash route, add `--route '#/settings'`. For a quick look, add `--mode quick`.
|
|
18
|
+
5. The exit status is 1 when there are errors. `--strict` also fails on warnings.
|
|
19
|
+
|
|
20
|
+
The command line only runs against local or test hosts unless `--allow-remote` is given. It never types into
|
|
21
|
+
fields, submits forms, or follows links to other sites.
|
|
22
|
+
|
|
23
|
+
## Read a finding
|
|
24
|
+
|
|
25
|
+
Each finding has `rule`, `severity`, `confidence`, `elements` (a CSS selector in `key` and the visible `text`),
|
|
26
|
+
`bands` (width ranges in pixels), `states` (which click led there), `measured` and, for sweep rules, `expected`
|
|
27
|
+
(the same element at neighbouring widths), plus `why`, `tries` (the usual causes and fixes, most likely
|
|
28
|
+
first), `skill` (the fix skill to load) and `guide`. The terminal report ends with the list of fix skills the
|
|
29
|
+
findings need.
|
|
30
|
+
|
|
31
|
+
Reproduce it before fixing: open the page at a width inside the band, repeat the click named in the state, and
|
|
32
|
+
look at the element. Compare with a width just outside the band.
|
|
33
|
+
|
|
34
|
+
## Fix it
|
|
35
|
+
|
|
36
|
+
Load the skill each finding names in `skill.name` (`responsivelint-fix` says which covers which rule), or read the [rule guides](https://github.com/prajwalsouza/ResponsiveLint/tree/main/docs/rules). Fix the layout, then run the check again
|
|
37
|
+
and confirm that the finding is gone and no new one appeared. Use `data-rl-ignore="<rule>"` only for a layout
|
|
38
|
+
that is intended, never to hide a real problem.
|
|
39
|
+
|
|
40
|
+
## While developing in the browser
|
|
41
|
+
|
|
42
|
+
Add `<script src="…/responsivelint.js" data-ui></script>` to a local page. Findings appear once each in the
|
|
43
|
+
console, with the element you can hover in DevTools, and `data-ui` outlines them on the page. `data-sweep`
|
|
44
|
+
also sweeps widths in a hidden copy of the page.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint-fix
|
|
3
|
+
description: "Use when fixing ResponsiveLint findings, or any layout bug where text overlaps, is cut off or squeezed to one word per line, the page scrolls sideways on mobile, or a control is invisible or disappears at some widths. Says which focused fix skill to load for each rule and how to work through a report."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fix ResponsiveLint findings
|
|
7
|
+
|
|
8
|
+
Every finding names the skill that fixes it in `skill.name` and `skill.file`, and lists the usual causes,
|
|
9
|
+
most likely first, in `tries`. Load only the skills the report names:
|
|
10
|
+
|
|
11
|
+
| Rules | Skill |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| text-overlap | [responsivelint-fix-overlap](../responsivelint-fix-overlap/SKILL.md) |
|
|
14
|
+
| squashed-text, clipped-text, width-outlier | [responsivelint-fix-cramped-text](../responsivelint-fix-cramped-text/SKILL.md) |
|
|
15
|
+
| page-overflow | [responsivelint-fix-overflow](../responsivelint-fix-overflow/SKILL.md) |
|
|
16
|
+
| hidden-control, disappears-in-band | [responsivelint-fix-controls](../responsivelint-fix-controls/SKILL.md) |
|
|
17
|
+
|
|
18
|
+
## Work through a report
|
|
19
|
+
|
|
20
|
+
1. Fix errors first, then warnings. Notes (`severity: "info"`) are usually intended.
|
|
21
|
+
2. Group findings by element (`elements[0].key`). One cause often produces several findings: an element
|
|
22
|
+
that overflows its row can be squashed at one width and overlap at another.
|
|
23
|
+
3. Reproduce each one: open the page at a width inside `bands`, repeat the click named in `states`, and look
|
|
24
|
+
at the element. Compare with a width just outside the band.
|
|
25
|
+
4. Check the causes in `tries` in order. The first one is ordered by what was measured, so it is the most
|
|
26
|
+
likely. Read the computed styles of the element and its parent and neighbours before changing anything.
|
|
27
|
+
5. Change the layout at its cause, not at the symptom: fixing the neighbour that takes the width is better
|
|
28
|
+
than shrinking the text.
|
|
29
|
+
6. Run ResponsiveLint again with the same options. Done means the finding is gone and nothing new appeared.
|
|
30
|
+
|
|
31
|
+
## What not to do
|
|
32
|
+
|
|
33
|
+
- Do not hide a problem with `overflow: hidden`, `overflow-x: hidden` on body, a smaller font, or z-index.
|
|
34
|
+
- Do not add `data-rl-ignore` to make a report pass. Use it only for a layout that is intended, with a comment
|
|
35
|
+
saying why.
|
|
36
|
+
- Do not change unrelated breakpoints; fix the band the finding names.
|
|
37
|
+
|
|
38
|
+
Each rule also has a longer guide: [rule guides](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint-fix-controls
|
|
3
|
+
description: "Use when a ResponsiveLint finding is hidden-control or disappears-in-band, or when a button, link or tab is invisible until hovered, cannot be found on touch screens or by keyboard, or goes missing at some window widths (for example between the desktop menu and the mobile menu)."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fix controls that are invisible or go missing
|
|
7
|
+
|
|
8
|
+
## hidden-control: clickable but fully transparent
|
|
9
|
+
|
|
10
|
+
`measured.opacity` is 0 (or nearly) while the control is laid out, clickable and focusable. Often it only
|
|
11
|
+
appears on `:hover` of a parent, which touch screens and keyboards never trigger.
|
|
12
|
+
|
|
13
|
+
- If people need it: show it at rest. It can be quieter (lower contrast, smaller) and stronger on hover.
|
|
14
|
+
- If it should stay hidden until something happens: hide it properly with `display: none`,
|
|
15
|
+
`visibility: hidden` or the `hidden` attribute until then, so it also leaves the tab order.
|
|
16
|
+
- Either way, show it on `:focus-visible` and on the parent's `:focus-within`, so keyboard users find it.
|
|
17
|
+
|
|
18
|
+
## disappears-in-band: missing in a narrow band of widths
|
|
19
|
+
|
|
20
|
+
The control is visible at the widths on both sides but not inside `bands`. Usually one rule hides the
|
|
21
|
+
desktop control and another shows the mobile one, and they do not meet.
|
|
22
|
+
|
|
23
|
+
1. Find the media or container queries that hide and show this control and its replacement. Search the
|
|
24
|
+
styles for the band's edge widths, and `display: none` on the control.
|
|
25
|
+
2. Usual causes:
|
|
26
|
+
- Two queries use different numbers (hide below 800 px, show the menu button below 760 px): use one
|
|
27
|
+
number, or one query for both.
|
|
28
|
+
- `max-width: 768px` and `min-width: 768px` overlap or leave a gap at one pixel: use 767/768, or range
|
|
29
|
+
syntax (`@media (width < 768px)`).
|
|
30
|
+
- The control is pushed out of a row that does not wrap and is clipped: let the row wrap.
|
|
31
|
+
|
|
32
|
+
## Check
|
|
33
|
+
|
|
34
|
+
Run ResponsiveLint again; also check that the control is reachable with Tab and shows a focus ring.
|
|
35
|
+
Guides: [hidden-control](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/hidden-control.md), [disappears-in-band](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/disappears-in-band.md).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint-fix-cramped-text
|
|
3
|
+
description: "Use when a ResponsiveLint finding is squashed-text, clipped-text or width-outlier, or when text is squeezed to one word per line, cut off by its box, or looks fine at most widths but breaks in a narrow range of widths between breakpoints."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fix text that is squeezed or cut off
|
|
7
|
+
|
|
8
|
+
## squashed-text: about one word per line
|
|
9
|
+
|
|
10
|
+
`measured` gives `lines`, `words` and `width`. Something next to the text has taken the row's width.
|
|
11
|
+
|
|
12
|
+
1. Look at the text's parent: is it `display: flex` or `grid`? Which sibling is wide?
|
|
13
|
+
2. Usual causes, in order:
|
|
14
|
+
- The sibling does not wrap: `white-space: nowrap`, `flex-shrink: 0`, or an `auto` grid column full of
|
|
15
|
+
buttons. Let it wrap (`flex-wrap: wrap`) or put it on its own line (`grid-template-columns: 1fr`).
|
|
16
|
+
- Two columns are kept at a width where one fits better: stack them below this width with a media or
|
|
17
|
+
container query.
|
|
18
|
+
- Nothing stops the text from shrinking: `min-width: 12em` on the text, or `flex: 1 1 12em`.
|
|
19
|
+
|
|
20
|
+
## clipped-text: cut off by its box
|
|
21
|
+
|
|
22
|
+
`measured` gives `contentWidth` and `boxWidth`, `contentHeight` and `boxHeight`. The larger pair is the
|
|
23
|
+
direction of the cut.
|
|
24
|
+
|
|
25
|
+
- Too tall for the box: remove the fixed `height` or use `min-height`.
|
|
26
|
+
- Too wide for the box: remove the fixed `width`, allow wrapping, or use `min-width`.
|
|
27
|
+
- Intended cut (one-line labels, tab names): add `text-overflow: ellipsis` and a `title` with the full text.
|
|
28
|
+
ResponsiveLint then reports a note, not a warning.
|
|
29
|
+
|
|
30
|
+
## width-outlier: breaks only in a narrow band
|
|
31
|
+
|
|
32
|
+
`measured` is the element inside the band, `expected` the same element at neighbouring widths. The
|
|
33
|
+
element is fine on both sides, so look for what changes at the band's edges.
|
|
34
|
+
|
|
35
|
+
1. Open the page at the first width of the band and at the width just before it. Compare the layout.
|
|
36
|
+
2. Usual causes:
|
|
37
|
+
- Two parts switch at different breakpoints (a sidebar appears at 760 px, but the content stacks only
|
|
38
|
+
from 1200 px): make them switch together, or base the content on its own width with a container query
|
|
39
|
+
(`container-type: inline-size` and `@container`).
|
|
40
|
+
- A neighbour stops wrapping inside the band: let it wrap, or stack it there.
|
|
41
|
+
- A fixed size takes over: use `min()`, `max()` or `clamp()`.
|
|
42
|
+
|
|
43
|
+
## Check
|
|
44
|
+
|
|
45
|
+
Run ResponsiveLint again over the same widths. Also look at one width on each side of the old band: a fix
|
|
46
|
+
for the band must not move the problem next door. Guides: [squashed-text](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/squashed-text.md),
|
|
47
|
+
[clipped-text](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/clipped-text.md), [width-outlier](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/width-outlier.md).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint-fix-overflow
|
|
3
|
+
description: "Use when a ResponsiveLint finding is page-overflow, or when a page scrolls sideways or can be dragged left and right on a phone or narrow window, or shows a horizontal scrollbar."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fix a page that scrolls sideways (page-overflow)
|
|
7
|
+
|
|
8
|
+
The finding names the element that reaches furthest past the right edge, and `measured` gives the page
|
|
9
|
+
width, the viewport and by how many pixels it overflows.
|
|
10
|
+
|
|
11
|
+
## Find the cause
|
|
12
|
+
|
|
13
|
+
Open the page at the narrowest width in `bands`. The named element is the widest culprit; its parent or a
|
|
14
|
+
child may be the real cause, so check its computed `width`, `min-width` and `white-space` and its children's.
|
|
15
|
+
|
|
16
|
+
| Cause | Fix |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| A fixed width in pixels (`width: 600px`, `min-width`) | `max-width: 100%`, or a width in `%`, `fr` or `min(600px, 100%)` |
|
|
19
|
+
| A row of buttons or tabs that does not wrap | `flex-wrap: wrap`, or a grid with `repeat(auto-fit, minmax(8em, 1fr))` |
|
|
20
|
+
| A long word, URL or code line | `overflow-wrap: anywhere` on the text |
|
|
21
|
+
| A wide table or code block | Wrap it in a box with `overflow-x: auto`, so only that box scrolls |
|
|
22
|
+
| An image, video or canvas | `max-width: 100%; height: auto` |
|
|
23
|
+
| `100vw` with a scrollbar, or a negative margin | Use `100%`, or remove the margin at these widths |
|
|
24
|
+
| A grid track that cannot shrink (`1fr` with long content) | `minmax(0, 1fr)`, and `min-width: 0` on flex children |
|
|
25
|
+
|
|
26
|
+
## Do not
|
|
27
|
+
|
|
28
|
+
Set `overflow-x: hidden` on `body` or `html`. It cuts content off instead of fitting it, and breaks
|
|
29
|
+
`position: sticky`.
|
|
30
|
+
|
|
31
|
+
## Check
|
|
32
|
+
|
|
33
|
+
Run ResponsiveLint again from 320 px. Guide: [page-overflow](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/page-overflow.md).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: responsivelint-fix-overlap
|
|
3
|
+
description: "Use when a ResponsiveLint finding is text-overlap, or when text is drawn on top of other text at some screen widths or after opening something: a navigation over a title, a badge over a label, a toast over a toolbar, a heading running into the next line."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fix text drawn over other text (text-overlap)
|
|
7
|
+
|
|
8
|
+
The finding names both texts in `elements`, and `measured.onTop` names the one painted on top, with the
|
|
9
|
+
positioning that puts it there (`position: absolute`, `fixed`, `z-index`, `transformed` or normal flow).
|
|
10
|
+
|
|
11
|
+
## Find the cause
|
|
12
|
+
|
|
13
|
+
1. Open the page at a width inside `bands`, in the state named in `states`.
|
|
14
|
+
2. Look at the element in `measured.onTop`, or the nearest ancestor with a non-static `position`.
|
|
15
|
+
3. Match what you see:
|
|
16
|
+
|
|
17
|
+
| What you see | Cause | Fix |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| The top element is `absolute` or `fixed` | It is outside the normal layout, so the text under it does not make room when it wraps | Place it with flex or grid (`display: flex; gap`), or move it beside the text. At narrow widths, put it on its own line |
|
|
20
|
+
| Both are in normal flow and a parent has `height` | The parent cannot grow when its text wraps | Replace `height` with `min-height`, or remove it |
|
|
21
|
+
| A negative `margin` or a `transform: translate` | One element is pulled onto the other | Remove it at these widths, or use `gap` |
|
|
22
|
+
| A toast, tooltip or badge over a toolbar | It is placed on the bar, not next to it | Place it above the bar, offset by the bar's height (measure it; do not guess) |
|
|
23
|
+
| `line-height` smaller than 1 with wrapped lines | Lines of the same element run into each other | Use `line-height: 1.2` or more |
|
|
24
|
+
|
|
25
|
+
## Do not
|
|
26
|
+
|
|
27
|
+
- Change `z-index`: it only swaps which text is hidden.
|
|
28
|
+
- Hide one of the texts at these widths unless it is truly not needed there.
|
|
29
|
+
|
|
30
|
+
## Check
|
|
31
|
+
|
|
32
|
+
Run ResponsiveLint again. The finding must be gone in every state it was in, and no `clipped-text` or
|
|
33
|
+
`page-overflow` must appear where the element now sits. Guide: [text-overlap](https://github.com/prajwalsouza/ResponsiveLint/blob/main/docs/rules/text-overlap.md).
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// responsivelint <url | folder> [options]
|
|
3
|
+
import {writeFile, mkdir} from 'node:fs/promises';
|
|
4
|
+
import {dirname} from 'node:path';
|
|
5
|
+
import {check} from '../src/cli/run.js';
|
|
6
|
+
import {terminalReport, htmlReport} from '../src/cli/report.js';
|
|
7
|
+
|
|
8
|
+
const HELP = `responsivelint <url | folder> [options]
|
|
9
|
+
|
|
10
|
+
Checks a page at every width and in every state it can reach, and reports where the layout breaks.
|
|
11
|
+
|
|
12
|
+
--mode quick|normal|aggressive effort (default normal: 320–1920 px every 48 px, up to 8 states)
|
|
13
|
+
--only text,overflow,… rule packs or rules to check (text, overlap, visibility, overflow, sweep)
|
|
14
|
+
--skip sweep,… rule packs or rules to leave out
|
|
15
|
+
--from 320 --to 1920 --step 48 the widths to sweep
|
|
16
|
+
--states 8 how many discovered states to check (0 = default state only)
|
|
17
|
+
--route '#/settings' start from this path or hash route of the target
|
|
18
|
+
--storage key=value set a localStorage value before loading (repeatable)
|
|
19
|
+
--json file --html file also write a JSON or HTML report
|
|
20
|
+
--evidence 12 screenshots for the first N findings (HTML report)
|
|
21
|
+
--min-confidence high|medium hide less certain findings
|
|
22
|
+
--strict exit with status 1 on warnings as well as errors
|
|
23
|
+
--allow-remote allow a host that is not local or a test host
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const args = process.argv.slice(2);
|
|
27
|
+
if (!args.length || args.includes('--help') || args.includes('-h')) { console.log(HELP); process.exit(0); }
|
|
28
|
+
const opt = {storage: {}};
|
|
29
|
+
let target = null;
|
|
30
|
+
for (let i = 0; i < args.length; i++) {
|
|
31
|
+
const a = args[i], v = () => args[++i];
|
|
32
|
+
if (!a.startsWith('--')) { target = a; continue; }
|
|
33
|
+
switch (a) {
|
|
34
|
+
case '--mode': opt.mode = v(); break;
|
|
35
|
+
case '--only': opt.only = v().split(','); break;
|
|
36
|
+
case '--skip': opt.skip = v().split(','); break;
|
|
37
|
+
case '--from': opt.from = +v(); break;
|
|
38
|
+
case '--to': opt.to = +v(); break;
|
|
39
|
+
case '--step': opt.step = +v(); break;
|
|
40
|
+
case '--states': opt.states = +v(); break;
|
|
41
|
+
case '--json': opt.json = v(); break;
|
|
42
|
+
case '--html': opt.html = v(); break;
|
|
43
|
+
case '--evidence': opt.evidence = +v(); break;
|
|
44
|
+
case '--min-confidence': opt.minConfidence = v(); break;
|
|
45
|
+
case '--strict': opt.strict = true; break;
|
|
46
|
+
case '--allow-remote': opt.allowRemote = true; break;
|
|
47
|
+
case '--wait': opt.wait = +v(); break;
|
|
48
|
+
case '--route': opt.route = v(); break;
|
|
49
|
+
case '--storage': { const s = v(); const k = s.indexOf('='); opt.storage[s.slice(0, k)] = s.slice(k + 1); break; }
|
|
50
|
+
default: console.error(`Unknown option ${a}\n\n${HELP}`); process.exit(2);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!Object.keys(opt.storage).length) delete opt.storage;
|
|
54
|
+
if (opt.html && opt.evidence == null) opt.evidence = 12;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const report = await check(target, {...opt, log: (s) => process.stderr.write(s + '\n')});
|
|
58
|
+
console.log(terminalReport(report));
|
|
59
|
+
for (const [file, body] of [[opt.json, () => JSON.stringify(report, null, 2)], [opt.html, () => htmlReport(report)]]) {
|
|
60
|
+
if (!file) continue;
|
|
61
|
+
await mkdir(dirname(file), {recursive: true});
|
|
62
|
+
await writeFile(file, body());
|
|
63
|
+
process.stderr.write(`Wrote ${file}\n`);
|
|
64
|
+
}
|
|
65
|
+
const bad = report.findings.filter((f) => f.severity === 'error' || (opt.strict && f.severity === 'warning'));
|
|
66
|
+
process.exit(bad.length ? 1 : 0);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
if (e.message.startsWith("browserType.launch: Executable doesn't exist")) {
|
|
69
|
+
console.error('ResponsiveLint could not find Chromium. Run: npx playwright install chromium');
|
|
70
|
+
} else {
|
|
71
|
+
console.error(e.message);
|
|
72
|
+
}
|
|
73
|
+
process.exit(2);
|
|
74
|
+
}
|