cypress-annotate 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/AGENTS.md +65 -0
- package/DOCS/pipeline.md +258 -0
- package/LICENSE +21 -0
- package/README.md +360 -0
- package/dist/annotate-image.d.ts +60 -0
- package/dist/annotate-image.d.ts.map +1 -0
- package/dist/annotate-image.js +160 -0
- package/dist/annotate.d.ts +9 -0
- package/dist/annotate.d.ts.map +1 -0
- package/dist/annotate.js +82 -0
- package/dist/browser/collect-elements.js +158 -0
- package/dist/browser/measure-target.js +69 -0
- package/dist/claude-reasoner.d.ts +17 -0
- package/dist/claude-reasoner.d.ts.map +1 -0
- package/dist/claude-reasoner.js +192 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +74 -0
- package/dist/cypress/commands.d.ts +50 -0
- package/dist/cypress/commands.d.ts.map +1 -0
- package/dist/cypress/commands.js +68 -0
- package/dist/cypress/failure-explainer.d.ts +45 -0
- package/dist/cypress/failure-explainer.d.ts.map +1 -0
- package/dist/cypress/failure-explainer.js +123 -0
- package/dist/cypress/failure-hook.d.ts +30 -0
- package/dist/cypress/failure-hook.d.ts.map +1 -0
- package/dist/cypress/failure-hook.js +148 -0
- package/dist/cypress/failure-report.d.ts +41 -0
- package/dist/cypress/failure-report.d.ts.map +1 -0
- package/dist/cypress/failure-report.js +14 -0
- package/dist/cypress/failure-selector.d.ts +45 -0
- package/dist/cypress/failure-selector.d.ts.map +1 -0
- package/dist/cypress/failure-selector.js +107 -0
- package/dist/cypress/measure-dom.d.ts +52 -0
- package/dist/cypress/measure-dom.d.ts.map +1 -0
- package/dist/cypress/measure-dom.js +132 -0
- package/dist/cypress/scroll-into-view.d.ts +15 -0
- package/dist/cypress/scroll-into-view.d.ts.map +1 -0
- package/dist/cypress/scroll-into-view.js +17 -0
- package/dist/cypress/task.d.ts +47 -0
- package/dist/cypress/task.d.ts.map +1 -0
- package/dist/cypress/task.js +69 -0
- package/dist/draw.d.ts +19 -0
- package/dist/draw.d.ts.map +1 -0
- package/dist/draw.js +177 -0
- package/dist/finder.d.ts +68 -0
- package/dist/finder.d.ts.map +1 -0
- package/dist/finder.js +64 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/inventory.d.ts +33 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +88 -0
- package/dist/measure.d.ts +11 -0
- package/dist/measure.d.ts.map +1 -0
- package/dist/measure.js +145 -0
- package/dist/pipeline.d.ts +60 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +115 -0
- package/dist/types.d.ts +115 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +113 -0
- package/skills/annotate-bug/SKILL.md +121 -0
- package/skills/cypress-annotate/SKILL.md +154 -0
- package/src/browser/collect-elements.js +158 -0
- package/src/browser/measure-target.js +69 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export function readMetrics(win) {
|
|
2
|
+
const doc = win.document.documentElement;
|
|
3
|
+
const body = win.document.body;
|
|
4
|
+
return {
|
|
5
|
+
devicePixelRatio: win.devicePixelRatio,
|
|
6
|
+
scrollX: win.scrollX,
|
|
7
|
+
scrollY: win.scrollY,
|
|
8
|
+
// innerWidth/Height rather than documentElement.clientWidth/Height: on a
|
|
9
|
+
// page with no doctype the root element reports the content size, not the
|
|
10
|
+
// viewport.
|
|
11
|
+
viewportWidth: win.innerWidth,
|
|
12
|
+
viewportHeight: win.innerHeight,
|
|
13
|
+
documentWidth: Math.max(doc.scrollWidth, body ? body.scrollWidth : 0),
|
|
14
|
+
documentHeight: Math.max(doc.scrollHeight, body ? body.scrollHeight : 0),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const REF_ATTR = 'data-annot-ref';
|
|
18
|
+
const INTERACTIVE = new Set(['a', 'button', 'input', 'select', 'textarea', 'label', 'summary', 'option']);
|
|
19
|
+
const STRUCTURAL = new Set(['header', 'nav', 'main', 'footer', 'aside', 'form', 'table', 'img', 'svg', 'video', 'dialog']);
|
|
20
|
+
const HEADING = /^h[1-6]$/;
|
|
21
|
+
function accessibleName(el) {
|
|
22
|
+
const aria = el.getAttribute('aria-label');
|
|
23
|
+
if (aria)
|
|
24
|
+
return aria.trim();
|
|
25
|
+
const alt = el.getAttribute('alt');
|
|
26
|
+
if (alt)
|
|
27
|
+
return alt.trim();
|
|
28
|
+
const placeholder = el.getAttribute('placeholder');
|
|
29
|
+
if (placeholder)
|
|
30
|
+
return `placeholder: ${placeholder.trim()}`;
|
|
31
|
+
if (el.tagName === 'INPUT' && el.value) {
|
|
32
|
+
return `value: ${el.value.trim()}`;
|
|
33
|
+
}
|
|
34
|
+
return (el.textContent ?? '').replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
35
|
+
}
|
|
36
|
+
function isTextLeaf(el) {
|
|
37
|
+
if (!(el.textContent ?? '').trim())
|
|
38
|
+
return false;
|
|
39
|
+
for (const child of Array.from(el.children)) {
|
|
40
|
+
if ((child.textContent ?? '').trim())
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Collect elements worth showing to Claude, for the case where no single
|
|
47
|
+
* selector could be recovered from the failure. Same "interesting element"
|
|
48
|
+
* heuristic as src/browser/collect-elements.js (the MCP-facing version), but
|
|
49
|
+
* written directly against `Window` rather than serialized as a string: in
|
|
50
|
+
* Cypress there is no eval boundary to cross, so there is nothing to duplicate
|
|
51
|
+
* that trick for.
|
|
52
|
+
*/
|
|
53
|
+
export function collectInventory(win, limit = 120) {
|
|
54
|
+
const doc = win.document;
|
|
55
|
+
const items = [];
|
|
56
|
+
let counter = 0;
|
|
57
|
+
for (const el of Array.from(doc.querySelectorAll('*'))) {
|
|
58
|
+
if (items.length >= limit)
|
|
59
|
+
break;
|
|
60
|
+
const tag = el.tagName.toLowerCase();
|
|
61
|
+
if (tag === 'script' || tag === 'style' || tag === 'meta' || tag === 'link')
|
|
62
|
+
continue;
|
|
63
|
+
const style = win.getComputedStyle(el);
|
|
64
|
+
if (style.visibility === 'hidden' || style.display === 'none')
|
|
65
|
+
continue;
|
|
66
|
+
if (parseFloat(style.opacity) < 0.05)
|
|
67
|
+
continue;
|
|
68
|
+
const rect = el.getBoundingClientRect();
|
|
69
|
+
if (rect.width < 8 || rect.height < 8)
|
|
70
|
+
continue;
|
|
71
|
+
const interesting = INTERACTIVE.has(tag) ||
|
|
72
|
+
STRUCTURAL.has(tag) ||
|
|
73
|
+
HEADING.test(tag) ||
|
|
74
|
+
el.hasAttribute('role') ||
|
|
75
|
+
el.hasAttribute('id') ||
|
|
76
|
+
isTextLeaf(el);
|
|
77
|
+
if (!interesting)
|
|
78
|
+
continue;
|
|
79
|
+
const ref = `e${++counter}`;
|
|
80
|
+
el.setAttribute(REF_ATTR, ref);
|
|
81
|
+
items.push({
|
|
82
|
+
ref,
|
|
83
|
+
tag,
|
|
84
|
+
name: accessibleName(el),
|
|
85
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return items;
|
|
89
|
+
}
|
|
90
|
+
export function refSelector(ref) {
|
|
91
|
+
return `[${REF_ATTR}="${ref}"]`;
|
|
92
|
+
}
|
|
93
|
+
export function measureTargets(win, selectors) {
|
|
94
|
+
const metrics = readMetrics(win);
|
|
95
|
+
const targets = selectors.map((selector) => {
|
|
96
|
+
let matches;
|
|
97
|
+
try {
|
|
98
|
+
matches = win.document.querySelectorAll(selector);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
selector,
|
|
103
|
+
found: false,
|
|
104
|
+
error: `invalid selector: ${error instanceof Error ? error.message : String(error)}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (matches.length === 0)
|
|
108
|
+
return { selector, found: false, error: 'no element matched' };
|
|
109
|
+
const el = matches[0];
|
|
110
|
+
const r = el.getBoundingClientRect();
|
|
111
|
+
// An element inside a fixed subtree does not move with document scroll, so
|
|
112
|
+
// it has no meaningful document-space position.
|
|
113
|
+
let isFixed = false;
|
|
114
|
+
for (let node = el; node; node = node.parentElement) {
|
|
115
|
+
if (win.getComputedStyle(node).position === 'fixed') {
|
|
116
|
+
isFixed = true;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
selector,
|
|
122
|
+
found: true,
|
|
123
|
+
matchCount: matches.length,
|
|
124
|
+
tag: el.tagName.toLowerCase(),
|
|
125
|
+
text: (el.textContent ?? '').replace(/\s+/g, ' ').trim().slice(0, 80),
|
|
126
|
+
isFixed,
|
|
127
|
+
rect: { x: r.x, y: r.y, width: r.width, height: r.height },
|
|
128
|
+
inViewport: r.bottom > 0 && r.right > 0 && r.top < win.innerHeight && r.left < win.innerWidth,
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
return { metrics, targets };
|
|
132
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Fully on-screen, not merely intersecting - the bar cy.annotate() and the failure hook both use. */
|
|
2
|
+
export declare function isFullyVisible(rect: {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}, win: Window): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Scroll `selector` into view only if it genuinely is not fully visible, and
|
|
10
|
+
* leave clearance above it so a fixed header does not end up covering the very
|
|
11
|
+
* thing being annotated. Cypress's own `scrollIntoView()` scrolls
|
|
12
|
+
* unconditionally and flush to the top, which is wrong for both cases.
|
|
13
|
+
*/
|
|
14
|
+
export declare function scrollIntoViewIfNeeded(selector: string, offset?: number): Cypress.Chainable<JQuery<HTMLElement>>;
|
|
15
|
+
//# sourceMappingURL=scroll-into-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-into-view.d.ts","sourceRoot":"","sources":["../../src/cypress/scroll-into-view.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,wBAAgB,cAAc,CAC5B,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7D,GAAG,EAAE,MAAM,GACV,OAAO,CAOT;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,SAAM,GACX,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAExC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
/** Fully on-screen, not merely intersecting - the bar cy.annotate() and the failure hook both use. */
|
|
3
|
+
export function isFullyVisible(rect, win) {
|
|
4
|
+
return (rect.y >= 0 &&
|
|
5
|
+
rect.x >= 0 &&
|
|
6
|
+
rect.y + rect.height <= win.innerHeight &&
|
|
7
|
+
rect.x + rect.width <= win.innerWidth);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Scroll `selector` into view only if it genuinely is not fully visible, and
|
|
11
|
+
* leave clearance above it so a fixed header does not end up covering the very
|
|
12
|
+
* thing being annotated. Cypress's own `scrollIntoView()` scrolls
|
|
13
|
+
* unconditionally and flush to the top, which is wrong for both cases.
|
|
14
|
+
*/
|
|
15
|
+
export function scrollIntoViewIfNeeded(selector, offset = 120) {
|
|
16
|
+
return cy.get(selector, { log: false }).first().scrollIntoView({ log: false, offset: { top: -offset, left: 0 } });
|
|
17
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AnnotationStyle, PixelRect, ShapeKind } from '../types.js';
|
|
2
|
+
import type { DomMeasurement } from './measure-dom.js';
|
|
3
|
+
/**
|
|
4
|
+
* The Node half of the Cypress plugin.
|
|
5
|
+
*
|
|
6
|
+
* Cypress tests run in the browser, where `sharp` cannot go, so compositing
|
|
7
|
+
* happens here via cy.task(). All the coordinate maths is `annotateImage`, the
|
|
8
|
+
* same code the Playwright and agent paths use.
|
|
9
|
+
*/
|
|
10
|
+
export interface AnnotateTaskArgs {
|
|
11
|
+
screenshotPath: string;
|
|
12
|
+
measurement: DomMeasurement;
|
|
13
|
+
labels?: (string | undefined)[];
|
|
14
|
+
capture?: 'viewport' | 'fullPage';
|
|
15
|
+
crop?: boolean;
|
|
16
|
+
cropPadding?: number;
|
|
17
|
+
shape?: ShapeKind;
|
|
18
|
+
style?: AnnotationStyle;
|
|
19
|
+
/** Defaults to overwriting the screenshot, so reports show the annotated one. */
|
|
20
|
+
outPath?: string;
|
|
21
|
+
/** Also keep the un-annotated pixels, at `<out>.raw.png`. */
|
|
22
|
+
keepRaw?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface AnnotateTaskResult {
|
|
25
|
+
outPath: string;
|
|
26
|
+
rawPath: string | null;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
scale: number;
|
|
30
|
+
drawnRects: PixelRect[];
|
|
31
|
+
warnings: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare function annotateScreenshot(args: AnnotateTaskArgs): Promise<AnnotateTaskResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Cypress's `on` is a set of overloads, one per event. Naming it precisely
|
|
36
|
+
* would mean depending on Cypress's types, which this file deliberately avoids
|
|
37
|
+
* so the task can be imported anywhere. A fully permissive signature accepts
|
|
38
|
+
* any of those overloads; the narrowing cast is contained below.
|
|
39
|
+
*/
|
|
40
|
+
export type CypressPluginOn = (...args: never[]) => unknown;
|
|
41
|
+
/**
|
|
42
|
+
* Register in cypress.config setupNodeEvents:
|
|
43
|
+
*
|
|
44
|
+
* setupNodeEvents(on) { registerAnnotateTasks(on); }
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerAnnotateTasks(on: CypressPluginOn): void;
|
|
47
|
+
//# sourceMappingURL=task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/cypress/task.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,cAAc,CAAC;IAC5B,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8D5F;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAI5D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,eAAe,GAAG,IAAI,CAQ/D"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { annotateImage } from '../annotate-image.js';
|
|
3
|
+
import { appendFailureRecord } from './failure-report.js';
|
|
4
|
+
export async function annotateScreenshot(args) {
|
|
5
|
+
const { screenshotPath, measurement } = args;
|
|
6
|
+
if (!screenshotPath)
|
|
7
|
+
throw new Error('annotateScreenshot: screenshotPath is required.');
|
|
8
|
+
if (!measurement?.metrics)
|
|
9
|
+
throw new Error('annotateScreenshot: measurement.metrics is required.');
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const targets = [];
|
|
12
|
+
measurement.targets.forEach((target, i) => {
|
|
13
|
+
if (!target.found || !target.rect) {
|
|
14
|
+
warnings.push(`Selector "${target.selector}" was not measured: ${target.error ?? 'not found'}.`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if ((target.matchCount ?? 1) > 1) {
|
|
18
|
+
warnings.push(`Selector "${target.selector}" matched ${target.matchCount} elements; annotated the first.`);
|
|
19
|
+
}
|
|
20
|
+
if (target.inViewport === false && (args.capture ?? 'viewport') === 'viewport') {
|
|
21
|
+
warnings.push(`Selector "${target.selector}" was outside the viewport when measured; its box will be clipped.`);
|
|
22
|
+
}
|
|
23
|
+
targets.push({
|
|
24
|
+
viewportRect: target.rect,
|
|
25
|
+
isFixed: target.isFixed,
|
|
26
|
+
label: args.labels?.[i],
|
|
27
|
+
shape: args.shape,
|
|
28
|
+
describe: `Element "${target.selector}"`,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
if (targets.length === 0) {
|
|
32
|
+
throw new Error(`annotateScreenshot: nothing to annotate. ${warnings.join(' ')}`);
|
|
33
|
+
}
|
|
34
|
+
const image = await readFile(screenshotPath);
|
|
35
|
+
const result = await annotateImage(image, targets, {
|
|
36
|
+
metrics: measurement.metrics,
|
|
37
|
+
capture: args.capture ?? 'viewport',
|
|
38
|
+
crop: args.crop,
|
|
39
|
+
cropPadding: args.cropPadding,
|
|
40
|
+
style: args.style,
|
|
41
|
+
});
|
|
42
|
+
const outPath = args.outPath ?? screenshotPath;
|
|
43
|
+
let rawPath = null;
|
|
44
|
+
if (args.keepRaw) {
|
|
45
|
+
rawPath = outPath.replace(/\.png$/i, '') + '.raw.png';
|
|
46
|
+
await writeFile(rawPath, result.rawImage);
|
|
47
|
+
}
|
|
48
|
+
await writeFile(outPath, result.image);
|
|
49
|
+
return {
|
|
50
|
+
outPath,
|
|
51
|
+
rawPath,
|
|
52
|
+
width: result.width,
|
|
53
|
+
height: result.height,
|
|
54
|
+
scale: result.scale,
|
|
55
|
+
drawnRects: result.drawnRects,
|
|
56
|
+
warnings: [...warnings, ...result.warnings],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Register in cypress.config setupNodeEvents:
|
|
61
|
+
*
|
|
62
|
+
* setupNodeEvents(on) { registerAnnotateTasks(on); }
|
|
63
|
+
*/
|
|
64
|
+
export function registerAnnotateTasks(on) {
|
|
65
|
+
on('task', {
|
|
66
|
+
annotateScreenshot: ((args) => annotateScreenshot(args)),
|
|
67
|
+
appendFailureRecord: ((args) => appendFailureRecord(args)),
|
|
68
|
+
});
|
|
69
|
+
}
|
package/dist/draw.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PixelRect, ShapeKind } from './types.js';
|
|
2
|
+
/** Style values already converted to image pixels. */
|
|
3
|
+
export interface ResolvedStyle {
|
|
4
|
+
color: string;
|
|
5
|
+
strokeWidth: number;
|
|
6
|
+
radius: number;
|
|
7
|
+
dimOutside: number;
|
|
8
|
+
labelFontSize: number;
|
|
9
|
+
labelColor: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DrawSpec {
|
|
12
|
+
rect: PixelRect;
|
|
13
|
+
label?: string;
|
|
14
|
+
shape: ShapeKind;
|
|
15
|
+
style: ResolvedStyle;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildOverlaySvg(width: number, height: number, specs: DrawSpec[]): string;
|
|
18
|
+
export declare function compositeOverlay(screenshot: Buffer, svg: string): Promise<Buffer>;
|
|
19
|
+
//# sourceMappingURL=draw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../src/draw.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;CACtB;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAsCxF;AAED,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKvF"}
|
package/dist/draw.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import sharp from 'sharp';
|
|
2
|
+
const FONT_STACK = "-apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif";
|
|
3
|
+
function escapeXml(text) {
|
|
4
|
+
return text.replace(/[<>&'"]/g, (c) => {
|
|
5
|
+
switch (c) {
|
|
6
|
+
case '<': return '<';
|
|
7
|
+
case '>': return '>';
|
|
8
|
+
case '&': return '&';
|
|
9
|
+
case "'": return ''';
|
|
10
|
+
default: return '"';
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function round(n) {
|
|
15
|
+
return (Math.round(n * 100) / 100).toString();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Approximate rendered text width. librsvg gives us no measurement API, so the
|
|
19
|
+
* label pill is sized from an average glyph ratio and generous padding.
|
|
20
|
+
*/
|
|
21
|
+
function estimateTextWidth(text, fontSize) {
|
|
22
|
+
return text.length * fontSize * 0.58;
|
|
23
|
+
}
|
|
24
|
+
function dimPath(width, height, holes) {
|
|
25
|
+
const outer = `M0 0 H${round(width)} V${round(height)} H0 Z`;
|
|
26
|
+
const inner = holes
|
|
27
|
+
.map((r) => `M${round(r.x)} ${round(r.y)} H${round(r.x + r.width)} V${round(r.y + r.height)} H${round(r.x)} Z`)
|
|
28
|
+
.join(' ');
|
|
29
|
+
return `${outer} ${inner}`;
|
|
30
|
+
}
|
|
31
|
+
function boxShape(rect, style) {
|
|
32
|
+
// Inset by half the stroke so the outline's outer edge lands on the rect.
|
|
33
|
+
const half = style.strokeWidth / 2;
|
|
34
|
+
return (`<rect x="${round(rect.x + half)}" y="${round(rect.y + half)}" ` +
|
|
35
|
+
`width="${round(Math.max(0, rect.width - style.strokeWidth))}" ` +
|
|
36
|
+
`height="${round(Math.max(0, rect.height - style.strokeWidth))}" ` +
|
|
37
|
+
`rx="${round(style.radius)}" fill="none" ` +
|
|
38
|
+
`stroke="${escapeXml(style.color)}" stroke-width="${round(style.strokeWidth)}" />`);
|
|
39
|
+
}
|
|
40
|
+
function circleShape(rect, style) {
|
|
41
|
+
// Semi-axes scaled by sqrt(2) so the ellipse circumscribes the rectangle.
|
|
42
|
+
const cx = rect.x + rect.width / 2;
|
|
43
|
+
const cy = rect.y + rect.height / 2;
|
|
44
|
+
const rx = (rect.width / 2) * Math.SQRT2;
|
|
45
|
+
const ry = (rect.height / 2) * Math.SQRT2;
|
|
46
|
+
return (`<ellipse cx="${round(cx)}" cy="${round(cy)}" rx="${round(rx)}" ry="${round(ry)}" ` +
|
|
47
|
+
`fill="none" stroke="${escapeXml(style.color)}" stroke-width="${round(style.strokeWidth)}" />`);
|
|
48
|
+
}
|
|
49
|
+
function arrowShape(rect, style, imageWidth, imageHeight) {
|
|
50
|
+
const length = style.strokeWidth * 22;
|
|
51
|
+
const tipX = rect.x + rect.width / 2;
|
|
52
|
+
const tipY = rect.y;
|
|
53
|
+
// Prefer approaching from above-left; flip whichever axis has no room.
|
|
54
|
+
let dx = -length * 0.7;
|
|
55
|
+
let dy = -length;
|
|
56
|
+
if (tipY + dy < style.strokeWidth * 4)
|
|
57
|
+
dy = rect.height + length;
|
|
58
|
+
if (tipX + dx < style.strokeWidth * 4)
|
|
59
|
+
dx = length * 0.7;
|
|
60
|
+
const tailX = Math.min(Math.max(tipX + dx, 0), imageWidth);
|
|
61
|
+
const tailY = Math.min(Math.max(dy > 0 ? rect.y + rect.height + length : tipY + dy, 0), imageHeight);
|
|
62
|
+
const anchorY = dy > 0 ? rect.y + rect.height : tipY;
|
|
63
|
+
const angle = Math.atan2(anchorY - tailY, tipX - tailX);
|
|
64
|
+
const head = style.strokeWidth * 5;
|
|
65
|
+
const spread = Math.PI / 7;
|
|
66
|
+
const p1x = tipX - head * Math.cos(angle - spread);
|
|
67
|
+
const p1y = anchorY - head * Math.sin(angle - spread);
|
|
68
|
+
const p2x = tipX - head * Math.cos(angle + spread);
|
|
69
|
+
const p2y = anchorY - head * Math.sin(angle + spread);
|
|
70
|
+
return {
|
|
71
|
+
svg: `<line x1="${round(tailX)}" y1="${round(tailY)}" x2="${round(tipX - Math.cos(angle) * head * 0.6)}" ` +
|
|
72
|
+
`y2="${round(anchorY - Math.sin(angle) * head * 0.6)}" stroke="${escapeXml(style.color)}" ` +
|
|
73
|
+
`stroke-width="${round(style.strokeWidth)}" stroke-linecap="round" />` +
|
|
74
|
+
`<polygon points="${round(tipX)},${round(anchorY)} ${round(p1x)},${round(p1y)} ${round(p2x)},${round(p2y)}" ` +
|
|
75
|
+
`fill="${escapeXml(style.color)}" />`,
|
|
76
|
+
tail: { x: tailX, y: tailY },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function labelShape(text, rect, style, imageWidth, imageHeight, centerOnAnchor = false) {
|
|
80
|
+
const fontSize = style.labelFontSize;
|
|
81
|
+
const padX = fontSize * 0.55;
|
|
82
|
+
const padY = fontSize * 0.35;
|
|
83
|
+
const lineHeight = fontSize * 1.28;
|
|
84
|
+
const gap = style.strokeWidth * 1.5;
|
|
85
|
+
// Bug descriptions are sentences, not captions, so the label has to wrap or
|
|
86
|
+
// it runs off the edge of a cropped screenshot.
|
|
87
|
+
const maxTextWidth = Math.max(fontSize * 8, imageWidth * 0.92 - padX * 2);
|
|
88
|
+
const lines = wrapText(text, fontSize, maxTextWidth, 3);
|
|
89
|
+
const pillHeight = lines.length * lineHeight + padY * 2;
|
|
90
|
+
const pillWidth = Math.max(...lines.map((line) => estimateTextWidth(line, fontSize))) + padX * 2;
|
|
91
|
+
let pillX = centerOnAnchor ? rect.x + rect.width / 2 - pillWidth / 2 : rect.x;
|
|
92
|
+
let pillY = rect.y - pillHeight - gap;
|
|
93
|
+
if (pillY < 0) {
|
|
94
|
+
// No room above: try below, then fall back to sitting inside the top edge.
|
|
95
|
+
pillY = rect.y + rect.height + gap;
|
|
96
|
+
if (pillY + pillHeight > imageHeight)
|
|
97
|
+
pillY = Math.max(0, rect.y + gap);
|
|
98
|
+
}
|
|
99
|
+
pillX = Math.min(Math.max(0, pillX), Math.max(0, imageWidth - pillWidth));
|
|
100
|
+
const firstBaseline = pillY + padY + fontSize * 0.82;
|
|
101
|
+
const tspans = lines
|
|
102
|
+
.map((line, i) => `<tspan x="${round(pillX + padX)}" y="${round(firstBaseline + i * lineHeight)}">${escapeXml(line)}</tspan>`)
|
|
103
|
+
.join('');
|
|
104
|
+
return (`<rect x="${round(pillX)}" y="${round(pillY)}" width="${round(pillWidth)}" height="${round(pillHeight)}" ` +
|
|
105
|
+
`rx="${round(Math.min(pillHeight / 2, fontSize * 0.5))}" fill="${escapeXml(style.color)}" />` +
|
|
106
|
+
`<text font-family="${FONT_STACK}" font-size="${round(fontSize)}" font-weight="600" ` +
|
|
107
|
+
`fill="${escapeXml(style.labelColor)}" xml:space="preserve">${tspans}</text>`);
|
|
108
|
+
}
|
|
109
|
+
/** Greedy word wrap against the same glyph-ratio estimate used for the pill. */
|
|
110
|
+
function wrapText(text, fontSize, maxWidth, maxLines) {
|
|
111
|
+
const words = text.split(/\s+/).filter(Boolean);
|
|
112
|
+
if (words.length === 0)
|
|
113
|
+
return [''];
|
|
114
|
+
const lines = [];
|
|
115
|
+
let current = '';
|
|
116
|
+
for (const word of words) {
|
|
117
|
+
const candidate = current ? `${current} ${word}` : word;
|
|
118
|
+
if (estimateTextWidth(candidate, fontSize) <= maxWidth || !current) {
|
|
119
|
+
current = candidate;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
lines.push(current);
|
|
123
|
+
current = word;
|
|
124
|
+
if (lines.length === maxLines)
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (lines.length < maxLines && current)
|
|
129
|
+
lines.push(current);
|
|
130
|
+
if (lines.length === maxLines) {
|
|
131
|
+
// Signal that text was dropped rather than silently truncating a sentence.
|
|
132
|
+
const consumed = lines.join(' ').split(/\s+/).length;
|
|
133
|
+
if (consumed < words.length) {
|
|
134
|
+
const last = lines[maxLines - 1] ?? '';
|
|
135
|
+
lines[maxLines - 1] = `${last.replace(/[,;:]?$/, '')}…`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return lines;
|
|
139
|
+
}
|
|
140
|
+
export function buildOverlaySvg(width, height, specs) {
|
|
141
|
+
const parts = [];
|
|
142
|
+
const dimmed = specs.filter((s) => s.style.dimOutside > 0);
|
|
143
|
+
if (dimmed.length > 0) {
|
|
144
|
+
const opacity = Math.max(...dimmed.map((s) => s.style.dimOutside));
|
|
145
|
+
parts.push(`<path d="${dimPath(width, height, specs.map((s) => s.rect))}" fill-rule="evenodd" ` +
|
|
146
|
+
`fill="#000" fill-opacity="${round(opacity)}" />`);
|
|
147
|
+
}
|
|
148
|
+
for (const spec of specs) {
|
|
149
|
+
// An arrow's label belongs at the tail; anywhere else it covers the thing
|
|
150
|
+
// the arrow is pointing at.
|
|
151
|
+
let labelAnchor = spec.rect;
|
|
152
|
+
let centerLabel = false;
|
|
153
|
+
if (spec.shape === 'box') {
|
|
154
|
+
parts.push(boxShape(spec.rect, spec.style));
|
|
155
|
+
}
|
|
156
|
+
else if (spec.shape === 'circle') {
|
|
157
|
+
parts.push(circleShape(spec.rect, spec.style));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const arrow = arrowShape(spec.rect, spec.style, width, height);
|
|
161
|
+
parts.push(arrow.svg);
|
|
162
|
+
labelAnchor = { x: arrow.tail.x, y: arrow.tail.y, width: 0, height: 0 };
|
|
163
|
+
centerLabel = true;
|
|
164
|
+
}
|
|
165
|
+
if (spec.label) {
|
|
166
|
+
parts.push(labelShape(spec.label, labelAnchor, spec.style, width, height, centerLabel));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return (`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" ` +
|
|
170
|
+
`viewBox="0 0 ${width} ${height}">${parts.join('')}</svg>`);
|
|
171
|
+
}
|
|
172
|
+
export async function compositeOverlay(screenshot, svg) {
|
|
173
|
+
return sharp(screenshot)
|
|
174
|
+
.composite([{ input: Buffer.from(svg), top: 0, left: 0 }])
|
|
175
|
+
.png()
|
|
176
|
+
.toBuffer();
|
|
177
|
+
}
|
package/dist/finder.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Page } from 'playwright';
|
|
2
|
+
import { type InventoryItem } from './inventory.js';
|
|
3
|
+
import type { Annotation, Region } from './types.js';
|
|
4
|
+
export type Severity = 'blocker' | 'major' | 'minor' | 'cosmetic';
|
|
5
|
+
export interface BugFinding {
|
|
6
|
+
description: string;
|
|
7
|
+
/** Inventory handle, e.g. "e12". Null when the model could not pick one. */
|
|
8
|
+
ref: string | null;
|
|
9
|
+
/** Percentage fallback, used only when `ref` is null. */
|
|
10
|
+
region: Region | null;
|
|
11
|
+
severity: Severity;
|
|
12
|
+
/** What the model saw that made it call this a bug. */
|
|
13
|
+
evidence: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The reasoning step is an interface so the pipeline can be exercised with a
|
|
17
|
+
* recorded response, and so a different backend (computer use, an MCP server)
|
|
18
|
+
* can be dropped in without touching the annotation code.
|
|
19
|
+
*
|
|
20
|
+
* This file deliberately has no dependency on `@anthropic-ai/sdk` - see
|
|
21
|
+
* claude-reasoner.ts, which implements this interface and is the only file
|
|
22
|
+
* that does. Keeping them separate means importing anything here (from the
|
|
23
|
+
* package's root barrel) never forces the SDK to be installed.
|
|
24
|
+
*/
|
|
25
|
+
export interface Reasoner {
|
|
26
|
+
propose(input: ReasonerInput): Promise<BugFinding[]>;
|
|
27
|
+
}
|
|
28
|
+
export interface ReasonerInput {
|
|
29
|
+
screenshotPng: Buffer;
|
|
30
|
+
inventory: InventoryItem[];
|
|
31
|
+
ticket: string;
|
|
32
|
+
url: string;
|
|
33
|
+
}
|
|
34
|
+
/** A reasoner backed by a recorded response, for tests and offline runs. */
|
|
35
|
+
export declare class ReplayReasoner implements Reasoner {
|
|
36
|
+
private readonly findings;
|
|
37
|
+
constructor(findings: BugFinding[]);
|
|
38
|
+
propose(): Promise<BugFinding[]>;
|
|
39
|
+
}
|
|
40
|
+
export declare const SEVERITY_COLORS: Record<Severity, string>;
|
|
41
|
+
export interface ResolvedFinding {
|
|
42
|
+
finding: BugFinding;
|
|
43
|
+
annotation: Annotation;
|
|
44
|
+
/** Present when the finding resolved through an inventory handle. */
|
|
45
|
+
item?: InventoryItem;
|
|
46
|
+
/**
|
|
47
|
+
* Stable identity for de-duplicating the same bug seen in overlapping
|
|
48
|
+
* viewport passes. Inventory handles are re-issued on every pass, so this is
|
|
49
|
+
* keyed on the readable selector instead.
|
|
50
|
+
*/
|
|
51
|
+
key: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ResolvedFindings {
|
|
54
|
+
resolved: ResolvedFinding[];
|
|
55
|
+
/** Findings that named neither a valid ref nor a usable region. */
|
|
56
|
+
unresolved: {
|
|
57
|
+
finding: BugFinding;
|
|
58
|
+
reason: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Turn model findings into annotations. A ref is looked up in the inventory,
|
|
63
|
+
* which is what guarantees the selector resolves; a region is passed through;
|
|
64
|
+
* anything else is reported as unresolved rather than silently dropped.
|
|
65
|
+
*/
|
|
66
|
+
export declare function findingsToAnnotations(findings: BugFinding[], inventory: InventoryItem[]): ResolvedFindings;
|
|
67
|
+
export declare function gatherReasonerInput(page: Page, ticket: string, viewportOnly?: boolean): Promise<ReasonerInput>;
|
|
68
|
+
//# sourceMappingURL=finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../src/finder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AAElE,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,yDAAyD;IACzD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,QAAQ,CAAC;IACnB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,4EAA4E;AAC5E,qBAAa,cAAe,YAAW,QAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,UAAU,EAAE;IAC7C,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAGvC;AAED,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAKpD,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,UAAU,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,qEAAqE;IACrE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,mEAAmE;IACnE,UAAU,EAAE;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,UAAU,EAAE,EACtB,SAAS,EAAE,aAAa,EAAE,GACzB,gBAAgB,CAyClB;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,YAAY,UAAO,GAClB,OAAO,CAAC,aAAa,CAAC,CAIxB"}
|
package/dist/finder.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { collectInventory } from './inventory.js';
|
|
2
|
+
/** A reasoner backed by a recorded response, for tests and offline runs. */
|
|
3
|
+
export class ReplayReasoner {
|
|
4
|
+
findings;
|
|
5
|
+
constructor(findings) {
|
|
6
|
+
this.findings = findings;
|
|
7
|
+
}
|
|
8
|
+
async propose() {
|
|
9
|
+
return this.findings;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const SEVERITY_COLORS = {
|
|
13
|
+
blocker: '#FF2D2D',
|
|
14
|
+
major: '#FF6A00',
|
|
15
|
+
minor: '#F5A623',
|
|
16
|
+
cosmetic: '#3D7BFF',
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Turn model findings into annotations. A ref is looked up in the inventory,
|
|
20
|
+
* which is what guarantees the selector resolves; a region is passed through;
|
|
21
|
+
* anything else is reported as unresolved rather than silently dropped.
|
|
22
|
+
*/
|
|
23
|
+
export function findingsToAnnotations(findings, inventory) {
|
|
24
|
+
const byRef = new Map(inventory.map((item) => [item.ref, item]));
|
|
25
|
+
const resolved = [];
|
|
26
|
+
const unresolved = [];
|
|
27
|
+
for (const finding of findings) {
|
|
28
|
+
const style = { color: SEVERITY_COLORS[finding.severity] };
|
|
29
|
+
const label = `${finding.severity}: ${finding.description}`;
|
|
30
|
+
if (finding.ref) {
|
|
31
|
+
const item = byRef.get(finding.ref);
|
|
32
|
+
if (item) {
|
|
33
|
+
resolved.push({
|
|
34
|
+
finding,
|
|
35
|
+
annotation: { selector: item.target, label, style },
|
|
36
|
+
item,
|
|
37
|
+
key: `sel:${item.reportSelector}`,
|
|
38
|
+
});
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// A hallucinated handle is recoverable if a region came with it.
|
|
42
|
+
if (!finding.region) {
|
|
43
|
+
unresolved.push({ finding, reason: `ref "${finding.ref}" is not in the inventory` });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (finding.region) {
|
|
48
|
+
const r = finding.region;
|
|
49
|
+
resolved.push({
|
|
50
|
+
finding,
|
|
51
|
+
annotation: { region: r, label, style },
|
|
52
|
+
key: `region:${Math.round(r.xPct)},${Math.round(r.yPct)},${Math.round(r.widthPct)},${Math.round(r.heightPct)}`,
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
unresolved.push({ finding, reason: 'no ref and no region' });
|
|
57
|
+
}
|
|
58
|
+
return { resolved, unresolved };
|
|
59
|
+
}
|
|
60
|
+
export async function gatherReasonerInput(page, ticket, viewportOnly = true) {
|
|
61
|
+
const inventory = await collectInventory(page, { viewportOnly });
|
|
62
|
+
const screenshotPng = await page.screenshot({ animations: 'disabled', caret: 'hide', type: 'png' });
|
|
63
|
+
return { screenshotPng, inventory, ticket, url: page.url() };
|
|
64
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Annotation, AnnotateOptions, AnnotateResult } from './types.js';
|
|
2
|
+
import type { LaunchOptions } from 'playwright';
|
|
3
|
+
export { annotate } from './annotate.js';
|
|
4
|
+
export { annotateImage, resolveScale, type AnnotateImageOptions, type AnnotateImageResult, type MeasuredTarget, } from './annotate-image.js';
|
|
5
|
+
export { measureElement, measureRegion, readPageMetrics } from './measure.js';
|
|
6
|
+
export { buildOverlaySvg, compositeOverlay } from './draw.js';
|
|
7
|
+
export { collectInventory, renderInventory, type InventoryItem } from './inventory.js';
|
|
8
|
+
export { findingsToAnnotations, gatherReasonerInput, ReplayReasoner, SEVERITY_COLORS, type BugFinding, type Reasoner, type ReasonerInput, type ResolvedFinding, type ResolvedFindings, type Severity, } from './finder.js';
|
|
9
|
+
export { runBugHunt, type BugHuntOptions, type BugHuntResult } from './pipeline.js';
|
|
10
|
+
export type * from './types.js';
|
|
11
|
+
export interface CaptureOptions extends AnnotateOptions {
|
|
12
|
+
viewport?: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
deviceScaleFactor?: number;
|
|
17
|
+
headless?: boolean;
|
|
18
|
+
/** Extra settling time after load, in ms, for pages that animate in. */
|
|
19
|
+
settleMs?: number;
|
|
20
|
+
launch?: LaunchOptions;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One-shot: open a URL, annotate it, close the browser.
|
|
24
|
+
*
|
|
25
|
+
* Playwright is loaded lazily, on the first call, rather than imported at the
|
|
26
|
+
* top of this file. `playwright` is an optional peer dependency - a consumer
|
|
27
|
+
* who only wants annotateImage()/the Cypress plugin (neither of which touch a
|
|
28
|
+
* browser at all) should never be forced to have it installed just because
|
|
29
|
+
* this function exists somewhere else in the same package.
|
|
30
|
+
*/
|
|
31
|
+
export declare function captureAnnotated(url: string, annotations: Annotation[], options?: CaptureOptions): Promise<AnnotateResult>;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|