viewprobe 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 +177 -2
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +79 -0
- package/dist/cli.js.map +1 -0
- package/dist/cropper.d.ts +18 -0
- package/dist/cropper.d.ts.map +1 -0
- package/dist/cropper.js +53 -0
- package/dist/cropper.js.map +1 -0
- package/dist/engine.d.ts +10 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +137 -0
- package/dist/engine.js.map +1 -0
- package/dist/formatter.d.ts +15 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +85 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/injector.d.ts +9 -0
- package/dist/injector.d.ts.map +1 -0
- package/dist/injector.js +165 -0
- package/dist/injector.js.map +1 -0
- package/dist/mcp-server.d.ts +13 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +164 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/scanner.d.ts +27 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +184 -0
- package/dist/scanner.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Umang Kumar
|
|
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,178 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ViewProbe
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Headless layout verification engine for AI coding agents.**
|
|
4
|
+
|
|
5
|
+
ViewProbe gives coding agents a fast, deterministic way to catch CSS and layout bugs — overflow, broken responsive layouts, truncated text, undersized tap targets — without relying on expensive vision models or manual human review.
|
|
6
|
+
|
|
7
|
+
It runs headless Chromium, performs geometric analysis on the rendered DOM, and returns compact, structured diagnostics that an LLM can parse in a single turn. When something breaks, it tells the agent *exactly which element* and *which CSS properties* caused the problem, along with an optional micro-crop screenshot of just the broken region.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
AI coding agents (Cursor, Claude Code, Cline, Aider, etc.) are surprisingly good at writing logic but consistently bad at CSS. They produce layouts that overflow on mobile, text that clips without ellipsis, and buttons too small to tap. The human developer ends up as a visual QA layer, manually checking every UI change.
|
|
12
|
+
|
|
13
|
+
ViewProbe closes that feedback loop. The agent writes the code, ViewProbe checks the layout across viewports in under a second, and if something breaks, the agent gets back the exact selector and computed styles needed to fix it — no guessing, no print-statement debugging.
|
|
14
|
+
|
|
15
|
+
## Visual Verification in Action
|
|
16
|
+
|
|
17
|
+
### Autonomous Self-Healing on Mobile Viewports
|
|
18
|
+
|
|
19
|
+
When an agent introduces a CSS defect (such as a rigid `min-width` that overflows on mobile, or text clipping without ellipsis), ViewProbe identifies the exact culprit and verifies the fix:
|
|
20
|
+
|
|
21
|
+
| Before Fix (Broken Layout) | After Fix (Self-Healed) |
|
|
22
|
+
| :---: | :---: |
|
|
23
|
+
| <img src=".github/assets/before-fix.png" width="340" alt="Mobile layout before fix: card overflows viewport by 23px" /> | <img src=".github/assets/after-fix.png" width="340" alt="Mobile layout after fix: responsive fluid bounds" /> |
|
|
24
|
+
| ❌ *Card overflows 375px screen by 23px, text clipped, 22px button* | ✅ *Fluid responsive bounds, clean ellipsis, 44px accessible touch target* |
|
|
25
|
+
|
|
26
|
+
## How ViewProbe Compares
|
|
27
|
+
|
|
28
|
+
Most developers currently try to verify agent UI changes using raw browser screenshots, DOM dumps, or visual regression dashboards. Here is why those approaches fail autonomous coding agents:
|
|
29
|
+
|
|
30
|
+
| Feature / Approach | Full Screenshots (`page.screenshot`) | Raw DOM / HTML Dumps | Visual Regression (Percy / Chromatic) | **ViewProbe** |
|
|
31
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
32
|
+
| **Token Cost per Turn** | ~1,500 – 3,000 vision tokens | 20,000+ text tokens | N/A (Web UI only) | **~80 tokens** (micro-crop + JSON) |
|
|
33
|
+
| **Identifies CSS Culprit** | ❌ No (Agent must guess) | ❌ No (Markup only) | ❌ No (Pixel diff only) | ✅ **Yes** (Exact computed style & selector) |
|
|
34
|
+
| **Deterministic Math** | ❌ No (Probabilistic vision) | ❌ No (No geometry data) | ⚠️ Partial (Pixel threshold) | ✅ **Yes** (DOM geometry & viewport math) |
|
|
35
|
+
| **Autonomous Agent Loop** | ⚠️ High latency & cost | ❌ Context window blowup | ❌ Human review required | ✅ **Native MCP & CLI tool-calling** |
|
|
36
|
+
| **Execution Environment** | ✅ Local | ✅ Local | ❌ Paid Cloud / SaaS | ✅ **100% Local & Free** |
|
|
37
|
+
|
|
38
|
+
### Why Existing Approaches Fall Short:
|
|
39
|
+
|
|
40
|
+
* **vs. Raw Full Screenshots (`page.screenshot()`)**: Full-screen vision prompts burn 1,500+ tokens per viewport turn. Furthermore, vision models are probabilistic—they frequently hallucinate alignment, miss 15px mobile overflows, and cannot tell the agent *which* CSS rule (`min-width: 420px;`) caused the problem.
|
|
41
|
+
* **vs. Raw DOM / Accessibility Tree Dumps**: Dumping 50,000 characters of HTML into an LLM context wastes tokens on unchanged markup and completely ignores the rendered layout, CSS cascade, media queries, and flexbox wrapping.
|
|
42
|
+
* **vs. Traditional Visual Regression (Percy, Chromatic)**: Designed for human reviewers to click "Approve / Reject" on pixel diffs in a web dashboard. They don't output machine-readable remediation diagnostics for LLM tool-calling.
|
|
43
|
+
* **vs. Accessibility Linters (axe-core, Lighthouse)**: A11y linters check semantic HTML, ARIA roles, and contrast, but are completely blind to responsive layout breakage, clipped text, and broken flex containers.
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# install
|
|
49
|
+
npm install -g viewprobe
|
|
50
|
+
|
|
51
|
+
# scan a running page across mobile and desktop
|
|
52
|
+
viewprobe check http://localhost:3000
|
|
53
|
+
|
|
54
|
+
# scan specific viewports
|
|
55
|
+
viewprobe check http://localhost:3000 -v mobile,tablet,desktop
|
|
56
|
+
|
|
57
|
+
# get markdown report instead of JSON
|
|
58
|
+
viewprobe check http://localhost:3000 -f markdown
|
|
59
|
+
|
|
60
|
+
# focus on specific elements
|
|
61
|
+
viewprobe check http://localhost:3000 -s ".hero,.pricing-grid"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What It Catches
|
|
65
|
+
|
|
66
|
+
| Check | Severity | Description |
|
|
67
|
+
|-------|----------|-------------|
|
|
68
|
+
| **Horizontal Overflow** | error | Elements wider than their container or the viewport, causing unwanted horizontal scroll |
|
|
69
|
+
| **Text Truncation** | warning | Text content clipped without `text-overflow: ellipsis` |
|
|
70
|
+
| **Tap Target Sizing** | warning | Interactive elements smaller than 44×44px (WCAG 2.5.8) |
|
|
71
|
+
| **Body Scroll** | error | Page-level horizontal scroll caused by elements breaking out of the viewport |
|
|
72
|
+
|
|
73
|
+
## Output Formats
|
|
74
|
+
|
|
75
|
+
### Agent format (default)
|
|
76
|
+
|
|
77
|
+
Compact JSON designed for LLM consumption:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"status": "FAIL",
|
|
82
|
+
"url": "http://localhost:3000",
|
|
83
|
+
"duration": "340ms",
|
|
84
|
+
"summary": "Found 1 error and 1 warning across 2 viewports.",
|
|
85
|
+
"violations": [
|
|
86
|
+
{
|
|
87
|
+
"type": "HORIZONTAL_OVERFLOW",
|
|
88
|
+
"severity": "error",
|
|
89
|
+
"viewport": "mobile",
|
|
90
|
+
"message": "Element extends 24px beyond viewport edge",
|
|
91
|
+
"selector": "div.pricing-grid > div:nth-child(2) > button",
|
|
92
|
+
"culpritStyles": [
|
|
93
|
+
"min-width: 400px",
|
|
94
|
+
"flex-shrink: 0"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Markdown format
|
|
102
|
+
|
|
103
|
+
Human-readable report with severity badges, bounding box data, and computed style blocks. Good for PR comments or documentation.
|
|
104
|
+
|
|
105
|
+
### One-liner format
|
|
106
|
+
|
|
107
|
+
Single line for CI pipelines: `FAIL: 1 layout error(s) — Element extends 24px beyond viewport edge`
|
|
108
|
+
|
|
109
|
+
## MCP Server
|
|
110
|
+
|
|
111
|
+
ViewProbe ships as an MCP server so any MCP-compatible agent can use it as a tool:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"viewprobe": {
|
|
117
|
+
"command": "node",
|
|
118
|
+
"args": ["path/to/viewprobe/dist/mcp-server.js"]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Tools
|
|
125
|
+
|
|
126
|
+
**`viewprobe_check`** — Scan a URL for layout violations.
|
|
127
|
+
|
|
128
|
+
| Parameter | Type | Required | Description |
|
|
129
|
+
|-----------|------|----------|-------------|
|
|
130
|
+
| `url` | string | yes | URL to scan |
|
|
131
|
+
| `viewports` | string | no | Comma-separated: mobile, tablet, desktop, wide |
|
|
132
|
+
| `selectors` | string | no | CSS selectors to focus on |
|
|
133
|
+
| `skipSelectors` | string | no | CSS selectors to skip |
|
|
134
|
+
| `microCrops` | boolean | no | Attach cropped violation screenshots (default: true) |
|
|
135
|
+
|
|
136
|
+
**`viewprobe_viewports`** — List available viewport presets with dimensions.
|
|
137
|
+
|
|
138
|
+
## Micro-Crops (~80 tokens vs ~1,500 tokens)
|
|
139
|
+
|
|
140
|
+
Instead of sending a full-page screenshot (1,500+ vision tokens), ViewProbe computes the exact screen-space bounding box of the violation, highlights it with a red debug border, and crops only that region (~80 tokens):
|
|
141
|
+
|
|
142
|
+
<p align="center">
|
|
143
|
+
<img src=".github/assets/micro-crop-overflow.jpg" width="460" alt="ViewProbe Micro-Crop with Red Highlight Box" />
|
|
144
|
+
</p>
|
|
145
|
+
|
|
146
|
+
You can disable micro-crops with `--no-crops` or `microCrops: false` in the MCP call.
|
|
147
|
+
|
|
148
|
+
## Programmatic API
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { ProbeEngine, formatForAgent } from "viewprobe";
|
|
152
|
+
|
|
153
|
+
const engine = new ProbeEngine();
|
|
154
|
+
const result = await engine.probe({
|
|
155
|
+
url: "http://localhost:3000",
|
|
156
|
+
viewports: [
|
|
157
|
+
{ name: "mobile", width: 375, height: 812 },
|
|
158
|
+
{ name: "desktop", width: 1280, height: 900 },
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
console.log(formatForAgent(result));
|
|
163
|
+
await engine.close();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
git clone https://github.com/Umang-sudo-su/ViewProbe.git
|
|
170
|
+
cd ViewProbe
|
|
171
|
+
npm install
|
|
172
|
+
npm run build
|
|
173
|
+
npm test
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { ProbeEngine } from "./engine.js";
|
|
5
|
+
import { formatForAgent, formatAsMarkdown, formatAsOneLiner } from "./formatter.js";
|
|
6
|
+
import { DEFAULT_VIEWPORTS } from "./types.js";
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program
|
|
9
|
+
.name("viewprobe")
|
|
10
|
+
.description("Headless layout verification for AI coding agents")
|
|
11
|
+
.version("0.1.0");
|
|
12
|
+
program
|
|
13
|
+
.command("check")
|
|
14
|
+
.description("Scan a URL for layout violations across viewports")
|
|
15
|
+
.argument("<url>", "URL to scan (e.g. http://localhost:3000)")
|
|
16
|
+
.option("-v, --viewports <viewports>", "Comma-separated viewport names: mobile,tablet,desktop,wide", "mobile,desktop")
|
|
17
|
+
.option("-f, --format <format>", "Output format: agent, markdown, oneline", "agent")
|
|
18
|
+
.option("-s, --selectors <selectors>", "Comma-separated CSS selectors to focus on")
|
|
19
|
+
.option("--skip <selectors>", "Comma-separated CSS selectors to skip")
|
|
20
|
+
.option("--no-crops", "Disable micro-crop screenshots")
|
|
21
|
+
.option("--timeout <ms>", "Page load timeout in milliseconds", "10000")
|
|
22
|
+
.option("--wait-for <selector>", "Wait for this selector before scanning")
|
|
23
|
+
.action(async (url, opts) => {
|
|
24
|
+
const viewportNames = opts.viewports.split(",").map((s) => s.trim());
|
|
25
|
+
const viewports = viewportNames
|
|
26
|
+
.map((name) => DEFAULT_VIEWPORTS.find((v) => v.name === name))
|
|
27
|
+
.filter(Boolean);
|
|
28
|
+
if (viewports.length === 0) {
|
|
29
|
+
console.error(chalk.red(`Unknown viewport names: ${opts.viewports}`));
|
|
30
|
+
console.error(`Available: ${DEFAULT_VIEWPORTS.map((v) => v.name).join(", ")}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const config = {
|
|
34
|
+
url,
|
|
35
|
+
viewports,
|
|
36
|
+
selectors: opts.selectors?.split(",").map((s) => s.trim()),
|
|
37
|
+
skipSelectors: opts.skip?.split(",").map((s) => s.trim()),
|
|
38
|
+
microCrops: opts.crops !== false,
|
|
39
|
+
timeout: parseInt(opts.timeout, 10),
|
|
40
|
+
waitForSelector: opts.waitFor,
|
|
41
|
+
};
|
|
42
|
+
const engine = new ProbeEngine();
|
|
43
|
+
try {
|
|
44
|
+
console.error(chalk.dim(`Scanning ${url} across ${viewports.map((v) => v.name).join(", ")}...`));
|
|
45
|
+
const result = await engine.probe(config);
|
|
46
|
+
switch (opts.format) {
|
|
47
|
+
case "agent":
|
|
48
|
+
console.log(formatForAgent(result));
|
|
49
|
+
break;
|
|
50
|
+
case "markdown":
|
|
51
|
+
console.log(formatAsMarkdown(result));
|
|
52
|
+
break;
|
|
53
|
+
case "oneline":
|
|
54
|
+
console.log(formatAsOneLiner(result));
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
console.log(formatForAgent(result));
|
|
58
|
+
}
|
|
59
|
+
process.exit(result.passed ? 0 : 1);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
console.error(chalk.red(`Scan failed: ${err.message}`));
|
|
63
|
+
process.exit(2);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await engine.close();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
program
|
|
70
|
+
.command("viewports")
|
|
71
|
+
.description("List available viewport presets")
|
|
72
|
+
.action(() => {
|
|
73
|
+
console.log(chalk.bold("Available viewports:\n"));
|
|
74
|
+
for (const vp of DEFAULT_VIEWPORTS) {
|
|
75
|
+
console.log(` ${chalk.cyan(vp.name.padEnd(10))} ${vp.width}\u00D7${vp.height}`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
program.parse();
|
|
79
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAmC,MAAM,YAAY,CAAC;AAEhF,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,mDAAmD,CAAC;KAChE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,mDAAmD,CAAC;KAChE,QAAQ,CAAC,OAAO,EAAE,0CAA0C,CAAC;KAC7D,MAAM,CACL,6BA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AAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,gBAAiB,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,iCAAiC,CAAC;KAC9C,MAAM,CAAC,GAAG,EAAE;IACX,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC;IAClD,KAAK,MAAM,EAAE,IAAI,iBAAiB,EAAE,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;IACnF,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page } from "playwright";
|
|
2
|
+
import type { BoundingBox } from "./types.js";
|
|
3
|
+
interface CropOptions {
|
|
4
|
+
padding: number;
|
|
5
|
+
quality: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Captures a small region around a violation bounding box and returns
|
|
9
|
+
* a base64-encoded JPEG. Uses Playwright's native clipping for fast,
|
|
10
|
+
* dependency-free cropping.
|
|
11
|
+
*/
|
|
12
|
+
export declare function cropViolation(page: Page, bounds: BoundingBox, options: CropOptions): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Draws a red debug outline around a violation on the page.
|
|
15
|
+
*/
|
|
16
|
+
export declare function highlightViolation(page: Page, selector: string): Promise<void>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=cropper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cropper.d.ts","sourceRoot":"","sources":["../src/cropper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CA+BjB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
package/dist/cropper.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Captures a small region around a violation bounding box and returns
|
|
3
|
+
* a base64-encoded JPEG. Uses Playwright's native clipping for fast,
|
|
4
|
+
* dependency-free cropping.
|
|
5
|
+
*/
|
|
6
|
+
export async function cropViolation(page, bounds, options) {
|
|
7
|
+
const viewport = page.viewportSize();
|
|
8
|
+
if (!viewport) {
|
|
9
|
+
throw new Error("Page has no viewport set");
|
|
10
|
+
}
|
|
11
|
+
const pad = options.padding;
|
|
12
|
+
const clip = {
|
|
13
|
+
x: Math.max(0, bounds.x - pad),
|
|
14
|
+
y: Math.max(0, bounds.y - pad),
|
|
15
|
+
width: Math.min(bounds.width + pad * 2, viewport.width - Math.max(0, bounds.x - pad)),
|
|
16
|
+
height: Math.min(bounds.height + pad * 2, viewport.height - Math.max(0, bounds.y - pad)),
|
|
17
|
+
};
|
|
18
|
+
clip.width = Math.max(clip.width, 48);
|
|
19
|
+
clip.height = Math.max(clip.height, 48);
|
|
20
|
+
const buffer = await page.screenshot({
|
|
21
|
+
clip,
|
|
22
|
+
type: "jpeg",
|
|
23
|
+
quality: options.quality,
|
|
24
|
+
});
|
|
25
|
+
return buffer.toString("base64");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Draws a red debug outline around a violation on the page.
|
|
29
|
+
*/
|
|
30
|
+
export async function highlightViolation(page, selector) {
|
|
31
|
+
await page.evaluate((sel) => {
|
|
32
|
+
const el = document.querySelector(sel);
|
|
33
|
+
if (!el)
|
|
34
|
+
return;
|
|
35
|
+
const overlay = document.createElement("div");
|
|
36
|
+
const rect = el.getBoundingClientRect();
|
|
37
|
+
Object.assign(overlay.style, {
|
|
38
|
+
position: "fixed",
|
|
39
|
+
top: `${rect.y}px`,
|
|
40
|
+
left: `${rect.x}px`,
|
|
41
|
+
width: `${rect.width}px`,
|
|
42
|
+
height: `${rect.height}px`,
|
|
43
|
+
border: "3px solid #ff2d55",
|
|
44
|
+
borderRadius: "2px",
|
|
45
|
+
pointerEvents: "none",
|
|
46
|
+
zIndex: "999999",
|
|
47
|
+
boxShadow: "0 0 8px rgba(255, 45, 85, 0.5)",
|
|
48
|
+
});
|
|
49
|
+
overlay.setAttribute("data-viewprobe-highlight", "true");
|
|
50
|
+
document.body.appendChild(overlay);
|
|
51
|
+
}, selector);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=cropper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cropper.js","sourceRoot":"","sources":["../src/cropper.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAU,EACV,MAAmB,EACnB,OAAoB;IAEpB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;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EhB,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAW,EAAE,EAAE;QAClC,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,CAAC,EAAE;YAAE,OAAO;QAEhB,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;QAExC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;YAC3B,QAAQ,EAAE,OAAO;YACjB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI;YAClB,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI;YACnB,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI;YACxB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI;YAC1B,MAAM,EAAE,mBAAmB;YAC3B,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,MAAM;YACrB,MAAM,EAAE,QAAQ;YAChB,SAAS,EAAE,gCAAgC;SAC5C,CAAC,CAAC;QAEH,OAAO,CAAC,YAAY,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;QACzD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACf,CAAC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProbeConfig, type ProbeResult } from "./types.js";
|
|
2
|
+
export declare class ProbeEngine {
|
|
3
|
+
private browser;
|
|
4
|
+
launch(): Promise<void>;
|
|
5
|
+
close(): Promise<void>;
|
|
6
|
+
probe(config: ProbeConfig): Promise<ProbeResult>;
|
|
7
|
+
private scanViewport;
|
|
8
|
+
private deduplicateViolations;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,WAAW,EAKjB,MAAM,YAAY,CAAC;AAGpB,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAwB;IAEjC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;YA0CxC,YAAY;IAoE1B,OAAO,CAAC,qBAAqB;CAW9B"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { chromium } from "playwright";
|
|
2
|
+
import { cropViolation, highlightViolation } from "./cropper.js";
|
|
3
|
+
import { DEFAULT_VIEWPORTS, DEFAULT_CONFIG, } from "./types.js";
|
|
4
|
+
import { getScannerSource } from "./injector.js";
|
|
5
|
+
export class ProbeEngine {
|
|
6
|
+
browser = null;
|
|
7
|
+
async launch() {
|
|
8
|
+
try {
|
|
9
|
+
this.browser = await chromium.launch({ headless: true });
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
const msg = err?.message ?? "";
|
|
13
|
+
if (msg.includes("Executable doesn't exist") ||
|
|
14
|
+
msg.includes("looks like Playwright was just installed")) {
|
|
15
|
+
try {
|
|
16
|
+
this.browser = await chromium.launch({
|
|
17
|
+
channel: "chrome",
|
|
18
|
+
headless: true,
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error("Chromium browser not found. Please install Playwright browsers with:\n npx playwright install chromium");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async close() {
|
|
30
|
+
if (this.browser) {
|
|
31
|
+
await this.browser.close();
|
|
32
|
+
this.browser = null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async probe(config) {
|
|
36
|
+
if (!this.browser) {
|
|
37
|
+
await this.launch();
|
|
38
|
+
}
|
|
39
|
+
const mergedConfig = { ...DEFAULT_CONFIG, ...config };
|
|
40
|
+
const viewports = mergedConfig.viewports ?? DEFAULT_VIEWPORTS;
|
|
41
|
+
const allViolations = [];
|
|
42
|
+
const startTime = Date.now();
|
|
43
|
+
for (const viewport of viewports) {
|
|
44
|
+
const violations = await this.scanViewport(mergedConfig, viewport);
|
|
45
|
+
allViolations.push(...violations);
|
|
46
|
+
}
|
|
47
|
+
const duration = Date.now() - startTime;
|
|
48
|
+
const deduped = this.deduplicateViolations(allViolations);
|
|
49
|
+
const passed = deduped.filter((v) => v.severity === "error").length === 0;
|
|
50
|
+
const errorCount = deduped.filter((v) => v.severity === "error").length;
|
|
51
|
+
const warnCount = deduped.filter((v) => v.severity === "warning").length;
|
|
52
|
+
let summary;
|
|
53
|
+
if (passed && warnCount === 0) {
|
|
54
|
+
summary = `All clean \u2014 no layout issues found across ${viewports.length} viewport${viewports.length > 1 ? "s" : ""}.`;
|
|
55
|
+
}
|
|
56
|
+
else if (passed) {
|
|
57
|
+
summary = `Passed with ${warnCount} warning${warnCount > 1 ? "s" : ""}. No blocking layout errors.`;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
summary = `Found ${errorCount} error${errorCount > 1 ? "s" : ""} and ${warnCount} warning${warnCount > 1 ? "s" : ""} across ${viewports.length} viewport${viewports.length > 1 ? "s" : ""}.`;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
url: config.url,
|
|
64
|
+
timestamp: new Date().toISOString(),
|
|
65
|
+
duration,
|
|
66
|
+
viewportsChecked: viewports,
|
|
67
|
+
violations: deduped,
|
|
68
|
+
passed,
|
|
69
|
+
summary,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async scanViewport(config, viewport) {
|
|
73
|
+
const page = await this.browser.newPage({
|
|
74
|
+
viewport: { width: viewport.width, height: viewport.height },
|
|
75
|
+
});
|
|
76
|
+
try {
|
|
77
|
+
// Inject the scanner function before navigation
|
|
78
|
+
const scannerSrc = getScannerSource();
|
|
79
|
+
await page.addInitScript({ content: scannerSrc });
|
|
80
|
+
await page.goto(config.url, {
|
|
81
|
+
waitUntil: "networkidle",
|
|
82
|
+
timeout: config.timeout,
|
|
83
|
+
});
|
|
84
|
+
if (config.waitForSelector) {
|
|
85
|
+
await page.waitForSelector(config.waitForSelector, {
|
|
86
|
+
timeout: config.timeout,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const rawViolations = await page.evaluate((opts) => {
|
|
90
|
+
return window.__viewprobe_scan(opts);
|
|
91
|
+
}, {
|
|
92
|
+
skipSelectors: config.skipSelectors,
|
|
93
|
+
targetSelectors: config.selectors,
|
|
94
|
+
});
|
|
95
|
+
const violations = [];
|
|
96
|
+
for (const raw of rawViolations) {
|
|
97
|
+
const violation = {
|
|
98
|
+
type: raw.type,
|
|
99
|
+
severity: raw.severity,
|
|
100
|
+
viewport,
|
|
101
|
+
message: raw.message,
|
|
102
|
+
selector: raw.selector,
|
|
103
|
+
bounds: raw.bounds,
|
|
104
|
+
culpritStyles: raw.styles,
|
|
105
|
+
};
|
|
106
|
+
if (config.microCrops) {
|
|
107
|
+
try {
|
|
108
|
+
await highlightViolation(page, raw.selector);
|
|
109
|
+
violation.microCrop = await cropViolation(page, raw.bounds, {
|
|
110
|
+
padding: config.cropPadding ?? 20,
|
|
111
|
+
quality: config.cropQuality ?? 60,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// cropping is best-effort
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
violations.push(violation);
|
|
119
|
+
}
|
|
120
|
+
return violations;
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
await page.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
deduplicateViolations(violations) {
|
|
127
|
+
const seen = new Set();
|
|
128
|
+
return violations.filter((v) => {
|
|
129
|
+
const key = `${v.type}::${v.selector}::${v.viewport.name}`;
|
|
130
|
+
if (seen.has(key))
|
|
131
|
+
return false;
|
|
132
|
+
seen.add(key);
|
|
133
|
+
return true;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA2B,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAKL,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,OAAO,WAAW;IACd,OAAO,GAAmB,IAAI,CAAC;IAEvC,KAAK,CAAC,MAAM;QACV,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,GAAG,GAAI,GAAa,EAAE,OAAO,IAAI,EAAE,CAAC;YAC1C,IACE,GAAG,CAAC,QAAQ,CAAC,0BAA0B,CAAC;gBACxC,GAAG,CAAC,QAAQ,CAAC,0CAA0C,CAAC,EACxD,CAAC;gBACD,IAAI,CAAC;oBACH,IAAI,CAAC,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;wBACnC,OAAO,EAAE,QAAQ;wBACjB,QAAQ,EAAE,IAAI;qBACf,CAAC,CAAC;oBACH,OAAO;gBACT,CAAC;gBAAC,MAAM,CAAC;oBACP,MAAM,IAAI,KAAK,CACb,yGAAyG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AAI,CAAC;wBACH,MAAM,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;wBAC7C,SAAS,CAAC,SAAS,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE;4BAC1D,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;4BACjC,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;yBAClC,CAAC,CAAC;oBACL,CAAC;oBAAC,MAAM,CAAC;wBACP,0BAA0B;oBAC5B,CAAC;gBACH,CAAC;gBAED,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAEO,qBAAqB,CAC3B,UAA6B;QAE7B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC3D,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,KAAK,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProbeResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compact JSON optimized for LLM consumption.
|
|
4
|
+
* Strips micro-crops from text output.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatForAgent(result: ProbeResult): string;
|
|
7
|
+
/**
|
|
8
|
+
* Human-readable Markdown report.
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatAsMarkdown(result: ProbeResult): string;
|
|
11
|
+
/**
|
|
12
|
+
* Single-line status for CI environments.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatAsOneLiner(result: ProbeResult): string;
|
|
15
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAmB1D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAsC5D;AA6BD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAQ5D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact JSON optimized for LLM consumption.
|
|
3
|
+
* Strips micro-crops from text output.
|
|
4
|
+
*/
|
|
5
|
+
export function formatForAgent(result) {
|
|
6
|
+
const compact = {
|
|
7
|
+
status: result.passed ? "PASS" : "FAIL",
|
|
8
|
+
url: result.url,
|
|
9
|
+
duration: `${result.duration}ms`,
|
|
10
|
+
summary: result.summary,
|
|
11
|
+
violations: result.violations.map((v) => ({
|
|
12
|
+
type: v.type,
|
|
13
|
+
severity: v.severity,
|
|
14
|
+
viewport: v.viewport.name,
|
|
15
|
+
message: v.message,
|
|
16
|
+
selector: v.selector,
|
|
17
|
+
culpritStyles: v.culpritStyles.map((s) => `${s.property}: ${s.value}`),
|
|
18
|
+
})),
|
|
19
|
+
};
|
|
20
|
+
return JSON.stringify(compact, null, 2);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Human-readable Markdown report.
|
|
24
|
+
*/
|
|
25
|
+
export function formatAsMarkdown(result) {
|
|
26
|
+
const lines = [];
|
|
27
|
+
const icon = result.passed ? "\u2705" : "\u274C";
|
|
28
|
+
lines.push(`# ${icon} ViewProbe Report`);
|
|
29
|
+
lines.push("");
|
|
30
|
+
lines.push(`**URL:** ${result.url}`);
|
|
31
|
+
lines.push(`**Scanned:** ${result.timestamp}`);
|
|
32
|
+
lines.push(`**Duration:** ${result.duration}ms`);
|
|
33
|
+
lines.push(`**Viewports:** ${result.viewportsChecked.map((v) => v.name).join(", ")}`);
|
|
34
|
+
lines.push("");
|
|
35
|
+
lines.push(`## Summary`);
|
|
36
|
+
lines.push(result.summary);
|
|
37
|
+
lines.push("");
|
|
38
|
+
if (result.violations.length === 0) {
|
|
39
|
+
lines.push("No issues detected. Ship it. \uD83D\uDE80");
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
const errors = result.violations.filter((v) => v.severity === "error");
|
|
43
|
+
const warnings = result.violations.filter((v) => v.severity === "warning");
|
|
44
|
+
if (errors.length > 0) {
|
|
45
|
+
lines.push(`## Errors (${errors.length})`);
|
|
46
|
+
lines.push("");
|
|
47
|
+
errors.forEach((v, i) => formatViolation(v, i + 1, lines));
|
|
48
|
+
}
|
|
49
|
+
if (warnings.length > 0) {
|
|
50
|
+
lines.push(`## Warnings (${warnings.length})`);
|
|
51
|
+
lines.push("");
|
|
52
|
+
warnings.forEach((v, i) => formatViolation(v, i + 1, lines));
|
|
53
|
+
}
|
|
54
|
+
return lines.join("\n");
|
|
55
|
+
}
|
|
56
|
+
function formatViolation(v, idx, lines) {
|
|
57
|
+
const badge = v.severity === "error" ? "\uD83D\uDD34" : "\uD83D\uDFE1";
|
|
58
|
+
lines.push(`### ${badge} ${idx}. ${v.type} (${v.viewport.name})`);
|
|
59
|
+
lines.push("");
|
|
60
|
+
lines.push(`> ${v.message}`);
|
|
61
|
+
lines.push("");
|
|
62
|
+
lines.push("**Element:** `" + v.selector + "`");
|
|
63
|
+
lines.push(`**Bounding Box:** ${v.bounds.width}\u00D7${v.bounds.height} at (${v.bounds.x}, ${v.bounds.y})`);
|
|
64
|
+
lines.push("");
|
|
65
|
+
if (v.culpritStyles.length > 0) {
|
|
66
|
+
lines.push("**Computed Styles:**");
|
|
67
|
+
lines.push("```css");
|
|
68
|
+
v.culpritStyles.forEach((s) => {
|
|
69
|
+
lines.push(`${s.property}: ${s.value};`);
|
|
70
|
+
});
|
|
71
|
+
lines.push("```");
|
|
72
|
+
lines.push("");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Single-line status for CI environments.
|
|
77
|
+
*/
|
|
78
|
+
export function formatAsOneLiner(result) {
|
|
79
|
+
if (result.passed) {
|
|
80
|
+
return `PASS: ${result.summary}`;
|
|
81
|
+
}
|
|
82
|
+
const errorCount = result.violations.filter((v) => v.severity === "error").length;
|
|
83
|
+
return `FAIL: ${errorCount} layout error(s) \u2014 ${result.violations[0]?.message ?? "unknown"}`;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=formatter.js.map
|