@mizchi/vlmkit-core 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/a11y-semantic.d.mts +34 -0
- package/dist/a11y-semantic.mjs +261 -0
- package/dist/arg-reader.d.mts +52 -0
- package/dist/arg-reader.mjs +129 -0
- package/dist/auth-state.d.mts +30 -0
- package/dist/auth-state.mjs +82 -0
- package/dist/authored-style-capture.d.mts +42 -0
- package/dist/authored-style-capture.mjs +117 -0
- package/dist/authored-style-diff.d.mts +15 -0
- package/dist/authored-style-diff.mjs +16 -0
- package/dist/cli-args.d.mts +35 -0
- package/dist/cli-args.mjs +63 -0
- package/dist/cli-error.d.mts +12 -0
- package/dist/cli-error.mjs +71 -0
- package/dist/computed-style-capture.d.mts +41 -0
- package/dist/computed-style-capture.mjs +589 -0
- package/dist/computed-style-diff.d.mts +83 -0
- package/dist/computed-style-diff.mjs +123 -0
- package/dist/diff-regions.d.mts +8 -0
- package/dist/diff-regions.mjs +52 -0
- package/dist/dom-equivalence.d.mts +51 -0
- package/dist/dom-equivalence.mjs +91 -0
- package/dist/dom-position-styles.d.mts +166 -0
- package/dist/dom-position-styles.mjs +296 -0
- package/dist/element-compare.d.mts +71 -0
- package/dist/element-compare.mjs +269 -0
- package/dist/gate-config.d.mts +116 -0
- package/dist/gate-config.mjs +169 -0
- package/dist/gate-exit.d.mts +45 -0
- package/dist/gate-exit.mjs +25 -0
- package/dist/heatmap-regions.d.mts +57 -0
- package/dist/heatmap-regions.mjs +158 -0
- package/dist/heatmap.d.mts +86 -0
- package/dist/heatmap.mjs +510 -0
- package/dist/image-resize.d.mts +34 -0
- package/dist/image-resize.mjs +92 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.mjs +14 -0
- package/dist/legacy-names.d.mts +48 -0
- package/dist/legacy-names.mjs +134 -0
- package/dist/mask.d.mts +18 -0
- package/dist/mask.mjs +27 -0
- package/dist/navigation-redirect.d.mts +28 -0
- package/dist/navigation-redirect.mjs +47 -0
- package/dist/page-open.d.mts +102 -0
- package/dist/page-open.mjs +133 -0
- package/dist/png-utils.d.mts +30 -0
- package/dist/png-utils.mjs +80 -0
- package/dist/region-shift.d.mts +20 -0
- package/dist/region-shift.mjs +128 -0
- package/dist/run-ledger.d.mts +14 -0
- package/dist/run-ledger.mjs +31 -0
- package/dist/terminal-colors.d.mts +12 -0
- package/dist/terminal-colors.mjs +14 -0
- package/dist/text-rows.d.mts +121 -0
- package/dist/text-rows.mjs +246 -0
- package/{src/types.ts → dist/types.d.mts} +88 -206
- package/dist/types.mjs +1 -0
- package/package.json +17 -5
- package/src/a11y-semantic.ts +0 -384
- package/src/authored-style-capture.ts +0 -185
- package/src/authored-style-diff.ts +0 -32
- package/src/cli-args.ts +0 -29
- package/src/cli-error.ts +0 -85
- package/src/computed-style-capture.ts +0 -717
- package/src/computed-style-diff.ts +0 -192
- package/src/diff-regions.ts +0 -70
- package/src/dom-equivalence.ts +0 -158
- package/src/dom-position-styles.ts +0 -457
- package/src/element-compare.ts +0 -354
- package/src/heatmap-regions.ts +0 -245
- package/src/heatmap.ts +0 -670
- package/src/image-resize.ts +0 -112
- package/src/index.ts +0 -105
- package/src/mask.ts +0 -41
- package/src/png-utils.ts +0 -86
- package/src/region-shift.ts +0 -173
- package/src/run-ledger.ts +0 -39
- package/src/terminal-colors.ts +0 -13
- package/src/text-rows.ts +0 -412
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//#region src/computed-style-diff.ts
|
|
2
|
+
/**
|
|
3
|
+
* Roll up N per-viewport CSD results into a single per-viewport report,
|
|
4
|
+
* surfacing which pairs apply universally vs. which are breakpoint-gated.
|
|
5
|
+
*
|
|
6
|
+
* Stable iteration order: results are taken in the input array's order,
|
|
7
|
+
* which is the same order migration-compare captures viewports (small →
|
|
8
|
+
* large or whatever the caller chose).
|
|
9
|
+
*/
|
|
10
|
+
function aggregateCsdByViewport(perViewport) {
|
|
11
|
+
const totalViewports = perViewport.length;
|
|
12
|
+
const pairToEntry = /* @__PURE__ */ new Map();
|
|
13
|
+
const byViewport = [];
|
|
14
|
+
for (const { viewport, result } of perViewport) {
|
|
15
|
+
byViewport.push({
|
|
16
|
+
viewport,
|
|
17
|
+
count: result.entries.length
|
|
18
|
+
});
|
|
19
|
+
for (const entry of result.entries) {
|
|
20
|
+
const key = `${entry.selector}|${entry.property}`;
|
|
21
|
+
const existing = pairToEntry.get(key);
|
|
22
|
+
if (existing) {
|
|
23
|
+
existing.viewports.push(viewport);
|
|
24
|
+
existing.samples.push({
|
|
25
|
+
viewport,
|
|
26
|
+
baseline: entry.baseline,
|
|
27
|
+
variant: entry.variant
|
|
28
|
+
});
|
|
29
|
+
} else pairToEntry.set(key, {
|
|
30
|
+
selector: entry.selector,
|
|
31
|
+
property: entry.property,
|
|
32
|
+
viewports: [viewport],
|
|
33
|
+
samples: [{
|
|
34
|
+
viewport,
|
|
35
|
+
baseline: entry.baseline,
|
|
36
|
+
variant: entry.variant
|
|
37
|
+
}]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const bySelectorProperty = [...pairToEntry.values()].sort((a, b) => {
|
|
42
|
+
if (b.viewports.length !== a.viewports.length) return b.viewports.length - a.viewports.length;
|
|
43
|
+
if (a.selector !== b.selector) return a.selector.localeCompare(b.selector);
|
|
44
|
+
return a.property.localeCompare(b.property);
|
|
45
|
+
});
|
|
46
|
+
const universalPairs = [];
|
|
47
|
+
const breakpointGatedPairs = [];
|
|
48
|
+
for (const entry of bySelectorProperty) {
|
|
49
|
+
const token = `${entry.selector}|${entry.property}`;
|
|
50
|
+
if (totalViewports > 0 && entry.viewports.length === totalViewports) universalPairs.push(token);
|
|
51
|
+
else breakpointGatedPairs.push(token);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
totalDiffs: byViewport.reduce((sum, e) => sum + e.count, 0),
|
|
55
|
+
byViewport,
|
|
56
|
+
bySelectorProperty,
|
|
57
|
+
universalPairs,
|
|
58
|
+
breakpointGatedPairs
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const EMPTY = {
|
|
62
|
+
entries: [],
|
|
63
|
+
totalDiffs: 0,
|
|
64
|
+
byProperty: [],
|
|
65
|
+
bySelector: [],
|
|
66
|
+
selectorsOnlyInBaseline: [],
|
|
67
|
+
selectorsOnlyInVariant: []
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Diff two computed-style snapshots. Both inputs are
|
|
71
|
+
* `Record<selector, Record<property, value>>`; produced by
|
|
72
|
+
* `captureComputedStyleSnapshotInDom`.
|
|
73
|
+
*/
|
|
74
|
+
function diffComputedStyles(baseline, variant) {
|
|
75
|
+
if (!baseline || !variant) return EMPTY;
|
|
76
|
+
const entries = [];
|
|
77
|
+
const byProperty = /* @__PURE__ */ new Map();
|
|
78
|
+
const bySelector = /* @__PURE__ */ new Map();
|
|
79
|
+
const baselineSelectors = new Set(Object.keys(baseline));
|
|
80
|
+
const variantSelectors = new Set(Object.keys(variant));
|
|
81
|
+
const shared = [...baselineSelectors].filter((s) => variantSelectors.has(s));
|
|
82
|
+
for (const selector of shared) {
|
|
83
|
+
const b = baseline[selector] ?? {};
|
|
84
|
+
const v = variant[selector] ?? {};
|
|
85
|
+
const props = new Set([...Object.keys(b), ...Object.keys(v)]);
|
|
86
|
+
for (const property of props) {
|
|
87
|
+
const bv = b[property] ?? "";
|
|
88
|
+
const vv = v[property] ?? "";
|
|
89
|
+
if (bv !== vv) {
|
|
90
|
+
entries.push({
|
|
91
|
+
selector,
|
|
92
|
+
property,
|
|
93
|
+
baseline: bv,
|
|
94
|
+
variant: vv
|
|
95
|
+
});
|
|
96
|
+
byProperty.set(property, (byProperty.get(property) ?? 0) + 1);
|
|
97
|
+
bySelector.set(selector, (bySelector.get(selector) ?? 0) + 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const selectorsOnlyInBaseline = [...baselineSelectors].filter((s) => !variantSelectors.has(s));
|
|
102
|
+
const selectorsOnlyInVariant = [...variantSelectors].filter((s) => !baselineSelectors.has(s));
|
|
103
|
+
const sortMap = (m) => [...m.entries()].map(([k, count]) => ({
|
|
104
|
+
key: k,
|
|
105
|
+
count
|
|
106
|
+
})).sort((a, b) => b.count - a.count || a.key.localeCompare(b.key));
|
|
107
|
+
return {
|
|
108
|
+
entries,
|
|
109
|
+
totalDiffs: entries.length,
|
|
110
|
+
byProperty: sortMap(byProperty).map(({ key, count }) => ({
|
|
111
|
+
property: key,
|
|
112
|
+
count
|
|
113
|
+
})),
|
|
114
|
+
bySelector: sortMap(bySelector).map(({ key, count }) => ({
|
|
115
|
+
selector: key,
|
|
116
|
+
count
|
|
117
|
+
})),
|
|
118
|
+
selectorsOnlyInBaseline,
|
|
119
|
+
selectorsOnlyInVariant
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { aggregateCsdByViewport, diffComputedStyles };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DiffRegion, VrtDiff } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/diff-regions.d.ts
|
|
4
|
+
declare function normalizeVrtDiffRegions(diff: VrtDiff): DiffRegion[];
|
|
5
|
+
declare function normalizeVrtDiffRegionPixels(diff: VrtDiff): number[];
|
|
6
|
+
declare function createScopedVrtDiff(diff: VrtDiff, region: DiffRegion): VrtDiff;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/diff-regions.ts
|
|
2
|
+
function normalizeVrtDiffRegions(diff) {
|
|
3
|
+
const normalizedPixels = normalizeVrtDiffRegionPixels(diff);
|
|
4
|
+
return diff.regions.map((region, index) => ({
|
|
5
|
+
...region,
|
|
6
|
+
diffPixelCount: normalizedPixels[index] ?? 0
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
function normalizeVrtDiffRegionPixels(diff) {
|
|
10
|
+
if (diff.regions.length === 0) return [];
|
|
11
|
+
const target = Math.max(0, Math.round(diff.diffPixels));
|
|
12
|
+
const rawWeights = diff.regions.map((region) => Math.max(0, Math.round(region.diffPixelCount)));
|
|
13
|
+
const totalWeight = rawWeights.reduce((sum, weight) => sum + weight, 0);
|
|
14
|
+
if (target === 0) return rawWeights.map(() => 0);
|
|
15
|
+
if (totalWeight === target) return rawWeights;
|
|
16
|
+
if (totalWeight === 0) return distributeEvenly(target, diff.regions.length);
|
|
17
|
+
const exactShares = rawWeights.map((weight) => target * weight / totalWeight);
|
|
18
|
+
const normalized = exactShares.map((share) => Math.floor(share));
|
|
19
|
+
let remainder = target - normalized.reduce((sum, value) => sum + value, 0);
|
|
20
|
+
const byFraction = exactShares.map((share, index) => ({
|
|
21
|
+
index,
|
|
22
|
+
fraction: share - Math.floor(share)
|
|
23
|
+
})).sort((left, right) => right.fraction - left.fraction);
|
|
24
|
+
for (const entry of byFraction) {
|
|
25
|
+
if (remainder <= 0) break;
|
|
26
|
+
normalized[entry.index]++;
|
|
27
|
+
remainder--;
|
|
28
|
+
}
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
function createScopedVrtDiff(diff, region) {
|
|
32
|
+
return {
|
|
33
|
+
...diff,
|
|
34
|
+
diffPixels: region.diffPixelCount,
|
|
35
|
+
diffRatio: region.diffPixelCount / Math.max(diff.totalPixels, 1),
|
|
36
|
+
regions: [region],
|
|
37
|
+
heatmapPath: void 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function distributeEvenly(total, count) {
|
|
41
|
+
const base = Math.floor(total / count);
|
|
42
|
+
let remainder = total - base * count;
|
|
43
|
+
return Array.from({ length: count }, () => {
|
|
44
|
+
if (remainder > 0) {
|
|
45
|
+
remainder--;
|
|
46
|
+
return base + 1;
|
|
47
|
+
}
|
|
48
|
+
return base;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/dom-equivalence.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* DOM equivalence preflight for `migration-compare`.
|
|
4
|
+
*
|
|
5
|
+
* Catches the failure mode from `docs/reports/2026-05-12-dogfood-shadcn-luna.md`:
|
|
6
|
+
* an agent edits the *body* of the variant HTML (rename a heading, drop a
|
|
7
|
+
* button, change input values) and the run blames `layout-shift` because
|
|
8
|
+
* the renders diverge structurally rather than stylistically.
|
|
9
|
+
*
|
|
10
|
+
* The preflight captures three lightweight fingerprints per document:
|
|
11
|
+
* - heading texts in document order (h1..h6)
|
|
12
|
+
* - button texts in document order
|
|
13
|
+
* - input/textarea/select value sequence
|
|
14
|
+
*
|
|
15
|
+
* Both pure helpers (sequence diff) and a browser-side capture script live
|
|
16
|
+
* here; migration-compare evaluates the script with `page.evaluate()`
|
|
17
|
+
* and feeds the results into `evaluateDomEquivalence`.
|
|
18
|
+
*/
|
|
19
|
+
interface DomFingerprint {
|
|
20
|
+
headingTexts: string[];
|
|
21
|
+
buttonTexts: string[];
|
|
22
|
+
inputValues: string[];
|
|
23
|
+
elementCount: number;
|
|
24
|
+
}
|
|
25
|
+
interface DomEquivalenceWarning {
|
|
26
|
+
code: "heading-mismatch" | "button-mismatch" | "input-mismatch" | "element-count-mismatch";
|
|
27
|
+
message: string;
|
|
28
|
+
baseline: string[];
|
|
29
|
+
variant: string[];
|
|
30
|
+
}
|
|
31
|
+
interface DomEquivalenceResult {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
warnings: DomEquivalenceWarning[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Verify structural DOM equivalence between two captured fingerprints.
|
|
37
|
+
*
|
|
38
|
+
* @since 0.5.0 — replaces `evaluateDomEquivalence`.
|
|
39
|
+
*/
|
|
40
|
+
declare function verifyDomEquivalence(baseline: DomFingerprint, variant: DomFingerprint): DomEquivalenceResult;
|
|
41
|
+
/**
|
|
42
|
+
* Browser-side capture script. Designed to be passed verbatim to
|
|
43
|
+
* `page.evaluate()`; produces a {@link DomFingerprint}.
|
|
44
|
+
*/
|
|
45
|
+
declare const DOM_FINGERPRINT_BROWSER_SCRIPT = "(() => {\n const norm = (s) => (s || \"\").replace(/\\s+/g, \" \").trim();\n const headingTexts = Array.from(document.querySelectorAll(\"h1, h2, h3, h4, h5, h6\")).map((el) => norm(el.textContent));\n const buttonTexts = Array.from(document.querySelectorAll(\"button\")).map((el) => norm(el.textContent));\n const inputValues = Array.from(document.querySelectorAll(\"input, textarea, select\")).map((el) => {\n const v = el.value != null ? el.value : el.getAttribute(\"value\") || \"\";\n return norm(v);\n });\n const elementCount = document.querySelectorAll(\"*\").length;\n return { headingTexts, buttonTexts, inputValues, elementCount };\n})()";
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated since 0.5.0 — use `verifyDomEquivalence` instead. Removed in 1.0.0.
|
|
48
|
+
*/
|
|
49
|
+
declare const evaluateDomEquivalence: typeof verifyDomEquivalence;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { DOM_FINGERPRINT_BROWSER_SCRIPT, DomEquivalenceResult, DomEquivalenceWarning, DomFingerprint, evaluateDomEquivalence, verifyDomEquivalence };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region src/dom-equivalence.ts
|
|
2
|
+
function normalize(s) {
|
|
3
|
+
return s.replace(/\s+/g, " ").trim();
|
|
4
|
+
}
|
|
5
|
+
function diffSequence(a, b) {
|
|
6
|
+
const aNorm = a.map(normalize);
|
|
7
|
+
const bNorm = b.map(normalize);
|
|
8
|
+
const aSet = new Set(aNorm);
|
|
9
|
+
const bSet = new Set(bNorm);
|
|
10
|
+
const added = bNorm.filter((x) => !aSet.has(x));
|
|
11
|
+
const removed = aNorm.filter((x) => !bSet.has(x));
|
|
12
|
+
return {
|
|
13
|
+
added,
|
|
14
|
+
removed,
|
|
15
|
+
reordered: added.length === 0 && removed.length === 0 && aNorm.join("|") !== bNorm.join("|")
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function makeMismatchMessage(kind, diff) {
|
|
19
|
+
if (diff.reordered) return `${kind} reordered between baseline and variant`;
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (diff.removed.length > 0) parts.push(`missing in variant: [${diff.removed.map((s) => `"${s}"`).join(", ")}]`);
|
|
22
|
+
if (diff.added.length > 0) parts.push(`extra in variant: [${diff.added.map((s) => `"${s}"`).join(", ")}]`);
|
|
23
|
+
return `${kind} differ — ${parts.join("; ")}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Threshold: 5% element-count drift before flagging. Single-element drift on
|
|
27
|
+
* small fixtures is noise; large additions/removals are usually a real
|
|
28
|
+
* DOM edit.
|
|
29
|
+
*/
|
|
30
|
+
const ELEMENT_COUNT_DRIFT_THRESHOLD = .05;
|
|
31
|
+
/**
|
|
32
|
+
* Verify structural DOM equivalence between two captured fingerprints.
|
|
33
|
+
*
|
|
34
|
+
* @since 0.5.0 — replaces `evaluateDomEquivalence`.
|
|
35
|
+
*/
|
|
36
|
+
function verifyDomEquivalence(baseline, variant) {
|
|
37
|
+
const warnings = [];
|
|
38
|
+
const headingDiff = diffSequence(baseline.headingTexts, variant.headingTexts);
|
|
39
|
+
if (headingDiff.added.length > 0 || headingDiff.removed.length > 0 || headingDiff.reordered) warnings.push({
|
|
40
|
+
code: "heading-mismatch",
|
|
41
|
+
message: makeMismatchMessage("headings", headingDiff),
|
|
42
|
+
baseline: baseline.headingTexts,
|
|
43
|
+
variant: variant.headingTexts
|
|
44
|
+
});
|
|
45
|
+
const buttonDiff = diffSequence(baseline.buttonTexts, variant.buttonTexts);
|
|
46
|
+
if (buttonDiff.added.length > 0 || buttonDiff.removed.length > 0 || buttonDiff.reordered) warnings.push({
|
|
47
|
+
code: "button-mismatch",
|
|
48
|
+
message: makeMismatchMessage("buttons", buttonDiff),
|
|
49
|
+
baseline: baseline.buttonTexts,
|
|
50
|
+
variant: variant.buttonTexts
|
|
51
|
+
});
|
|
52
|
+
const inputDiff = diffSequence(baseline.inputValues, variant.inputValues);
|
|
53
|
+
if (inputDiff.added.length > 0 || inputDiff.removed.length > 0 || inputDiff.reordered) warnings.push({
|
|
54
|
+
code: "input-mismatch",
|
|
55
|
+
message: makeMismatchMessage("inputs", inputDiff),
|
|
56
|
+
baseline: baseline.inputValues,
|
|
57
|
+
variant: variant.inputValues
|
|
58
|
+
});
|
|
59
|
+
const drift = baseline.elementCount === 0 ? 0 : Math.abs(baseline.elementCount - variant.elementCount) / baseline.elementCount;
|
|
60
|
+
if (drift > ELEMENT_COUNT_DRIFT_THRESHOLD) warnings.push({
|
|
61
|
+
code: "element-count-mismatch",
|
|
62
|
+
message: `total element count differs by ${(drift * 100).toFixed(1)}% (baseline: ${baseline.elementCount}, variant: ${variant.elementCount})`,
|
|
63
|
+
baseline: [String(baseline.elementCount)],
|
|
64
|
+
variant: [String(variant.elementCount)]
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
ok: warnings.length === 0,
|
|
68
|
+
warnings
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Browser-side capture script. Designed to be passed verbatim to
|
|
73
|
+
* `page.evaluate()`; produces a {@link DomFingerprint}.
|
|
74
|
+
*/
|
|
75
|
+
const DOM_FINGERPRINT_BROWSER_SCRIPT = `(() => {
|
|
76
|
+
const norm = (s) => (s || "").replace(/\\s+/g, " ").trim();
|
|
77
|
+
const headingTexts = Array.from(document.querySelectorAll("h1, h2, h3, h4, h5, h6")).map((el) => norm(el.textContent));
|
|
78
|
+
const buttonTexts = Array.from(document.querySelectorAll("button")).map((el) => norm(el.textContent));
|
|
79
|
+
const inputValues = Array.from(document.querySelectorAll("input, textarea, select")).map((el) => {
|
|
80
|
+
const v = el.value != null ? el.value : el.getAttribute("value") || "";
|
|
81
|
+
return norm(v);
|
|
82
|
+
});
|
|
83
|
+
const elementCount = document.querySelectorAll("*").length;
|
|
84
|
+
return { headingTexts, buttonTexts, inputValues, elementCount };
|
|
85
|
+
})()`;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated since 0.5.0 — use `verifyDomEquivalence` instead. Removed in 1.0.0.
|
|
88
|
+
*/
|
|
89
|
+
const evaluateDomEquivalence = verifyDomEquivalence;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { DOM_FINGERPRINT_BROWSER_SCRIPT, evaluateDomEquivalence, verifyDomEquivalence };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//#region src/dom-position-styles.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* DOM-position-based selector alignment for migration diffs.
|
|
4
|
+
*
|
|
5
|
+
* Addresses the killer finding from `docs/reports/2026-05-12-subagent-eval.md`:
|
|
6
|
+
* the migration-VRT scenario is class renames (`.card` → `.luna-panel`),
|
|
7
|
+
* but `diffComputedStyles` matches selectors by literal string and so
|
|
8
|
+
* produces zero verified entries for the entire rename. The subagent
|
|
9
|
+
* eval showed this blind spot lets a fresh agent plateau at 10–24%
|
|
10
|
+
* diff because it has to guess values from PNGs.
|
|
11
|
+
*
|
|
12
|
+
* This module captures `{ path, tag, classes, styles }` per
|
|
13
|
+
* "interesting" element on each page, then matches across baseline and
|
|
14
|
+
* variant by the position `path` (e.g. `main[0]>section[1]>article[0]>div[0]`),
|
|
15
|
+
* which is invariant under class renames. Diff output names both
|
|
16
|
+
* class strings + the property delta so the agent can rewrite the
|
|
17
|
+
* variant's CSS class against the baseline's rendered values.
|
|
18
|
+
*
|
|
19
|
+
* Pure module. The browser-side capture script ships as a string fed
|
|
20
|
+
* to `page.evaluate()`.
|
|
21
|
+
*/
|
|
22
|
+
interface PositionedElement {
|
|
23
|
+
/** DOM path: `tag[childIndex]>tag[childIndex]>...` rooted at body. */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Tag name (lower-case). */
|
|
26
|
+
tag: string;
|
|
27
|
+
/** Class string verbatim (or "" when absent). */
|
|
28
|
+
classes: string;
|
|
29
|
+
/** Tracked computed-style values. */
|
|
30
|
+
styles: Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Parent element's computed `display`. Used to annotate `display`-property
|
|
33
|
+
* diffs where the value looks different but is actually flex/grid-item
|
|
34
|
+
* coercion (CSS blockifies inline children of flex/grid containers).
|
|
35
|
+
*/
|
|
36
|
+
parentDisplay?: string;
|
|
37
|
+
}
|
|
38
|
+
interface DpEntry {
|
|
39
|
+
path: string;
|
|
40
|
+
tag: string;
|
|
41
|
+
baselineClasses: string;
|
|
42
|
+
variantClasses: string;
|
|
43
|
+
property: string;
|
|
44
|
+
baseline: string;
|
|
45
|
+
variant: string;
|
|
46
|
+
/**
|
|
47
|
+
* For em-relative properties (`letter-spacing`, `line-height` etc.),
|
|
48
|
+
* the value divided by the element's own font-size — exposes when a
|
|
49
|
+
* single `em` rule produces several different px values across
|
|
50
|
+
* elements with different font sizes.
|
|
51
|
+
*/
|
|
52
|
+
baselineEm?: number;
|
|
53
|
+
variantEm?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Set on `display`-property rows when the parent on either side is a
|
|
56
|
+
* flex/grid container. Helps the agent realize the difference may be
|
|
57
|
+
* flex-item coercion (`inline-flex` → `flex`) rather than a real
|
|
58
|
+
* source-CSS mismatch.
|
|
59
|
+
*/
|
|
60
|
+
parentDisplayContext?: {
|
|
61
|
+
baselineParent: string;
|
|
62
|
+
variantParent: string; /** True when at least one parent is flex/grid/inline-flex/inline-grid. */
|
|
63
|
+
isFlexOrGridItem: boolean;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
interface DpResult {
|
|
67
|
+
entries: DpEntry[];
|
|
68
|
+
totalDiffs: number;
|
|
69
|
+
/** path strings that appear only in one side (DOM structure drift). */
|
|
70
|
+
pathsOnlyInBaseline: string[];
|
|
71
|
+
pathsOnlyInVariant: string[];
|
|
72
|
+
/** by-property + by-path aggregates, sorted desc. */
|
|
73
|
+
byProperty: Array<{
|
|
74
|
+
property: string;
|
|
75
|
+
count: number;
|
|
76
|
+
}>;
|
|
77
|
+
byPath: Array<{
|
|
78
|
+
path: string;
|
|
79
|
+
baselineClasses: string;
|
|
80
|
+
variantClasses: string;
|
|
81
|
+
count: number;
|
|
82
|
+
}>;
|
|
83
|
+
}
|
|
84
|
+
declare function diffDomPositionStyles(baseline: PositionedElement[], variant: PositionedElement[]): DpResult;
|
|
85
|
+
/**
|
|
86
|
+
* Browser-side capture script: walks the DOM from `<body>`, emits
|
|
87
|
+
* `{path, tag, classes, styles}` for every element that has a class
|
|
88
|
+
* attribute or is one of the semantic / interactive tags listed below.
|
|
89
|
+
* `path` uses 0-based child indices among ALL children, so it's stable
|
|
90
|
+
* across class renames as long as the tree shape is the same.
|
|
91
|
+
*/
|
|
92
|
+
declare const DOM_POSITION_STYLES_BROWSER_SCRIPT: string;
|
|
93
|
+
declare function parseDomPositionStyles(value: unknown): PositionedElement[];
|
|
94
|
+
interface DpEntryWithViewport extends DpEntry {
|
|
95
|
+
viewport: string;
|
|
96
|
+
}
|
|
97
|
+
interface DpSample {
|
|
98
|
+
viewport: string;
|
|
99
|
+
baseline: string;
|
|
100
|
+
variant: string;
|
|
101
|
+
/** Em-normalized values when the property is em-relative. */
|
|
102
|
+
baselineEm?: number;
|
|
103
|
+
variantEm?: number;
|
|
104
|
+
}
|
|
105
|
+
interface DpPerViewportResult {
|
|
106
|
+
/** All per-viewport diff tuples (entries[i] carries its viewport). */
|
|
107
|
+
entries: DpEntryWithViewport[];
|
|
108
|
+
/** Total tuples across all viewports (before any caller-side cap). */
|
|
109
|
+
totalDiffs: number;
|
|
110
|
+
/**
|
|
111
|
+
* Compact verification index: `${variantClassToken}::${property}` strings
|
|
112
|
+
* for every real delta. Used by `diff-for-agent` to gate heuristic
|
|
113
|
+
* fix-candidate ✓/✗ marks. Stored unconditionally (cheap; tens of KB
|
|
114
|
+
* worst-case) so verification stays accurate even when `entries` and
|
|
115
|
+
* `byPathProperty` are capped for report-size reasons.
|
|
116
|
+
*/
|
|
117
|
+
verifiedPairs: string[];
|
|
118
|
+
/**
|
|
119
|
+
* (path, property) → viewport-list. Same property at same position can
|
|
120
|
+
* differ on some viewports and not others (media-query-gated rules).
|
|
121
|
+
* Sorted by number of viewports descending.
|
|
122
|
+
*/
|
|
123
|
+
byPathProperty: Array<{
|
|
124
|
+
path: string;
|
|
125
|
+
property: string;
|
|
126
|
+
baselineClasses: string;
|
|
127
|
+
variantClasses: string;
|
|
128
|
+
viewports: string[];
|
|
129
|
+
samples: DpSample[]; /** Set on `display`-property pairs when at least one parent is flex/grid. */
|
|
130
|
+
parentDisplayContext?: {
|
|
131
|
+
baselineParent: string;
|
|
132
|
+
variantParent: string;
|
|
133
|
+
isFlexOrGridItem: boolean;
|
|
134
|
+
};
|
|
135
|
+
}>;
|
|
136
|
+
/** Per-viewport tally so the caller can see which viewport is worst. */
|
|
137
|
+
byViewport: Array<{
|
|
138
|
+
viewport: string;
|
|
139
|
+
count: number;
|
|
140
|
+
}>;
|
|
141
|
+
/** Property → total viewport-occurrences, sorted desc. */
|
|
142
|
+
byProperty: Array<{
|
|
143
|
+
property: string;
|
|
144
|
+
count: number;
|
|
145
|
+
}>;
|
|
146
|
+
/** Path → total viewport-occurrences + class names, sorted desc. */
|
|
147
|
+
byPath: Array<{
|
|
148
|
+
path: string;
|
|
149
|
+
baselineClasses: string;
|
|
150
|
+
variantClasses: string;
|
|
151
|
+
count: number;
|
|
152
|
+
}>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Diff DOM-position style captures across N viewports.
|
|
156
|
+
*
|
|
157
|
+
* Inputs are maps of viewport-label → captured element list. Each viewport
|
|
158
|
+
* is diffed independently (same `diffDomPositionStyles` per-viewport
|
|
159
|
+
* semantics), then results are merged with a viewport label per tuple and
|
|
160
|
+
* a (path, property) cross-viewport aggregate so the agent can spot
|
|
161
|
+
* "this delta appears at every viewport" vs "this delta only appears at
|
|
162
|
+
* mobile" (the latter usually means a missing or wrong media query).
|
|
163
|
+
*/
|
|
164
|
+
declare function diffPositionStylesAcrossViewports(baselineByVp: Map<string, PositionedElement[]> | Record<string, PositionedElement[]>, variantByVp: Map<string, PositionedElement[]> | Record<string, PositionedElement[]>): DpPerViewportResult;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { DOM_POSITION_STYLES_BROWSER_SCRIPT, DpEntry, DpEntryWithViewport, DpPerViewportResult, DpResult, DpSample, PositionedElement, diffDomPositionStyles, diffPositionStylesAcrossViewports, parseDomPositionStyles };
|