@mizchi/vlmkit-core 0.9.0 → 0.9.1

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  VRT diff engine and shared types. Pure-TypeScript image / DOM / a11y / visual
4
4
  comparison primitives — no Playwright required for the lightweight surface.
5
5
 
6
- Part of the [`vlmkit`](https://github.com/mizchi/vrt) monorepo.
6
+ Part of the [`vlmkit`](https://github.com/mizchi/vlmkit) monorepo.
7
7
 
8
8
  ## Install
9
9
 
@@ -13,13 +13,8 @@ declare function diffA11yTrees(baseline: A11ySnapshot, current: A11ySnapshot): A
13
13
  * Walks the tree and returns issues such as missing labels on
14
14
  * interactive elements and missing alt text on images.
15
15
  *
16
- * @since 0.5.0 — replaces `checkA11yTree`.
17
16
  */
18
17
  declare function verifyA11yTree(tree: A11yNode): A11yIssue[];
19
- /**
20
- * @deprecated since 0.5.0 — use `verifyA11yTree` instead. Removed in 1.0.0.
21
- */
22
- declare const checkA11yTree: typeof verifyA11yTree;
23
18
  interface A11yIssue {
24
19
  path: string;
25
20
  rule: string;
@@ -31,4 +26,4 @@ interface A11yIssue {
31
26
  */
32
27
  declare function parsePlaywrightA11ySnapshot(testId: string, testTitle: string, raw: Record<string, unknown>): A11ySnapshot;
33
28
  //#endregion
34
- export { A11yIssue, INTERACTIVE_ROLES, LANDMARK_ROLES, checkA11yTree, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree };
29
+ export { A11yIssue, INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree };
@@ -205,17 +205,12 @@ function isInteractive(node) {
205
205
  * Walks the tree and returns issues such as missing labels on
206
206
  * interactive elements and missing alt text on images.
207
207
  *
208
- * @since 0.5.0 — replaces `checkA11yTree`.
209
208
  */
210
209
  function verifyA11yTree(tree) {
211
210
  const issues = [];
212
211
  walkTree(tree, "", issues);
213
212
  return issues;
214
213
  }
215
- /**
216
- * @deprecated since 0.5.0 — use `verifyA11yTree` instead. Removed in 1.0.0.
217
- */
218
- const checkA11yTree = verifyA11yTree;
219
214
  function walkTree(node, path, issues) {
220
215
  const nodePath = path ? `${path} > ${nodeLabel(node)}` : nodeLabel(node);
221
216
  if (isInteractive(node) && !node.name) issues.push({
@@ -258,4 +253,4 @@ function normalizeA11yNode(raw) {
258
253
  };
259
254
  }
260
255
  //#endregion
261
- export { INTERACTIVE_ROLES, LANDMARK_ROLES, checkA11yTree, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree };
256
+ export { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree };
@@ -20,6 +20,8 @@ declare function hasFlag(argv: readonly string[], name: string): boolean;
20
20
  * repeated. Throws when the value is missing or is another flag.
21
21
  */
22
22
  declare function readFlag(argv: readonly string[], name: string): string | undefined;
23
+ /** Read a string flag whose public contract is a closed set of values. */
24
+ declare function readChoice<const T extends readonly string[]>(argv: readonly string[], name: string, choices: T): T[number] | undefined;
23
25
  /** Every occurrence, for repeatable flags (`--gate`, `--only`, `--pages`). */
24
26
  declare function readAll(argv: readonly string[], name: string): string[];
25
27
  interface NumberFlagOptions {
@@ -49,4 +51,4 @@ declare function readPositionals(argv: readonly string[], valueFlags?: readonly
49
51
  */
50
52
  declare function tokenizeCommand(command: string): string[];
51
53
  //#endregion
52
- export { NumberFlagOptions, hasFlag, readAll, readFlag, readInt, readNumber, readPositionals, tokenizeCommand };
54
+ export { NumberFlagOptions, hasFlag, readAll, readChoice, readFlag, readInt, readNumber, readPositionals, tokenizeCommand };
@@ -34,6 +34,13 @@ function readFlag(argv, name) {
34
34
  if (looksLikeFlag(value)) throw new UsageError(`${flag} needs a value, got the next flag ${value}`);
35
35
  return value;
36
36
  }
37
+ /** Read a string flag whose public contract is a closed set of values. */
38
+ function readChoice(argv, name, choices) {
39
+ const value = readFlag(argv, name);
40
+ if (value === void 0) return void 0;
41
+ if (choices.includes(value)) return value;
42
+ throw new UsageError(`${flagName(name)} must be one of ${choices.join(", ")}, got ${JSON.stringify(value)}`);
43
+ }
37
44
  /** Every occurrence, for repeatable flags (`--gate`, `--only`, `--pages`). */
38
45
  function readAll(argv, name) {
39
46
  const flag = flagName(name);
@@ -126,4 +133,4 @@ function tokenizeCommand(command) {
126
133
  return out;
127
134
  }
128
135
  //#endregion
129
- export { hasFlag, readAll, readFlag, readInt, readNumber, readPositionals, tokenizeCommand };
136
+ export { hasFlag, readAll, readChoice, readFlag, readInt, readNumber, readPositionals, tokenizeCommand };
@@ -26,10 +26,5 @@ declare function getArgValues(name: string): string[];
26
26
  declare function getPositionalArgs(valueFlags?: readonly string[]): string[];
27
27
  /** Raw argv tail, for callers doing their own scanning. */
28
28
  declare function getRawArgs(): string[];
29
- /**
30
- * @deprecated Captured at import time, so it is empty or stale in a leaf loaded
31
- * through the dispatcher. Use `getRawArgs()`.
32
- */
33
- declare const args: string[];
34
29
  //#endregion
35
- export { args, getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
30
+ export { getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
package/dist/cli-args.mjs CHANGED
@@ -54,10 +54,5 @@ function getPositionalArgs(valueFlags = []) {
54
54
  function getRawArgs() {
55
55
  return argv();
56
56
  }
57
- /**
58
- * @deprecated Captured at import time, so it is empty or stale in a leaf loaded
59
- * through the dispatcher. Use `getRawArgs()`.
60
- */
61
- const args = argv();
62
57
  //#endregion
63
- export { args, getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
58
+ export { getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
@@ -7,6 +7,12 @@
7
7
  declare class UsageError extends Error {
8
8
  readonly name = "UsageError";
9
9
  }
10
+ interface PlaywrightInstallTarget {
11
+ version: string;
12
+ cliPath: string;
13
+ nodePath: string;
14
+ }
15
+ declare function formatMissingPlaywrightBrowserError(error: unknown, target?: PlaywrightInstallTarget | null): string | null;
10
16
  declare function handleCliError(e: unknown): never;
11
17
  //#endregion
12
- export { UsageError, handleCliError };
18
+ export { PlaywrightInstallTarget, UsageError, formatMissingPlaywrightBrowserError, handleCliError };
@@ -1,4 +1,6 @@
1
- import { statSync } from "node:fs";
1
+ import { createRequire } from "node:module";
2
+ import { readFileSync, statSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
2
4
  //#region src/cli-error.ts
3
5
  /**
4
6
  * Shared CLI error-prettifier. Recognizes common error shapes that
@@ -17,6 +19,35 @@ import { statSync } from "node:fs";
17
19
  var UsageError = class extends Error {
18
20
  name = "UsageError";
19
21
  };
22
+ function shellArg(value) {
23
+ return /^[A-Za-z0-9_./:@+-]+$/.test(value) ? value : JSON.stringify(value);
24
+ }
25
+ function resolvePlaywrightInstallTarget() {
26
+ try {
27
+ const manifestPath = createRequire(import.meta.url).resolve("playwright/package.json");
28
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
29
+ if (!manifest.version) return null;
30
+ return {
31
+ version: manifest.version,
32
+ cliPath: join(dirname(manifestPath), "cli.js"),
33
+ nodePath: process.execPath
34
+ };
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+ function formatMissingPlaywrightBrowserError(error, target = resolvePlaywrightInstallTarget()) {
40
+ const message = String(error?.message ?? error);
41
+ if (!/browserType\.launch:[\s\S]*Executable doesn't exist at/i.test(message)) return null;
42
+ if (!target) return "error: Playwright browser executable is not installed; reinstall the browser for vlmkit's resolved Playwright.";
43
+ const command = [
44
+ target.nodePath,
45
+ target.cliPath,
46
+ "install",
47
+ "chromium"
48
+ ].map(shellArg).join(" ");
49
+ return `error: Playwright ${target.version} browser executable is not installed.\n run: ${command}`;
50
+ }
20
51
  function handleCliError(e) {
21
52
  const err = e;
22
53
  const msg = String(err?.message ?? e);
@@ -36,6 +67,11 @@ function handleCliError(e) {
36
67
  process.stderr.write(`error: expected an HTML file, got a directory: ${path}\n${hint}\n`);
37
68
  process.exit(1);
38
69
  }
70
+ const missingBrowser = formatMissingPlaywrightBrowserError(e);
71
+ if (missingBrowser) {
72
+ process.stderr.write(`${missingBrowser}\n`);
73
+ process.exit(1);
74
+ }
39
75
  if (/net::ERR_NAME_NOT_RESOLVED/i.test(msg) || /net::ERR_CONNECTION_REFUSED/i.test(msg) || /Cannot navigate to invalid URL/i.test(msg)) {
40
76
  const url = msg.match(/Navigating to ([^,]+)/i)?.[1] ?? msg.match(/(https?:\/\/[^\s"]+)/)?.[1] ?? "the URL";
41
77
  let reason = "failed to load";
@@ -68,4 +104,4 @@ function findDirectoryArg() {
68
104
  }
69
105
  }
70
106
  //#endregion
71
- export { UsageError, handleCliError };
107
+ export { UsageError, formatMissingPlaywrightBrowserError, handleCliError };
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * Both pure helpers (sequence diff) and a browser-side capture script live
16
16
  * here; migration-compare evaluates the script with `page.evaluate()`
17
- * and feeds the results into `evaluateDomEquivalence`.
17
+ * and feeds the results into `verifyDomEquivalence`.
18
18
  */
19
19
  interface DomFingerprint {
20
20
  headingTexts: string[];
@@ -35,7 +35,6 @@ interface DomEquivalenceResult {
35
35
  /**
36
36
  * Verify structural DOM equivalence between two captured fingerprints.
37
37
  *
38
- * @since 0.5.0 — replaces `evaluateDomEquivalence`.
39
38
  */
40
39
  declare function verifyDomEquivalence(baseline: DomFingerprint, variant: DomFingerprint): DomEquivalenceResult;
41
40
  /**
@@ -43,9 +42,5 @@ declare function verifyDomEquivalence(baseline: DomFingerprint, variant: DomFing
43
42
  * `page.evaluate()`; produces a {@link DomFingerprint}.
44
43
  */
45
44
  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
45
  //#endregion
51
- export { DOM_FINGERPRINT_BROWSER_SCRIPT, DomEquivalenceResult, DomEquivalenceWarning, DomFingerprint, evaluateDomEquivalence, verifyDomEquivalence };
46
+ export { DOM_FINGERPRINT_BROWSER_SCRIPT, DomEquivalenceResult, DomEquivalenceWarning, DomFingerprint, verifyDomEquivalence };
@@ -31,7 +31,6 @@ const ELEMENT_COUNT_DRIFT_THRESHOLD = .05;
31
31
  /**
32
32
  * Verify structural DOM equivalence between two captured fingerprints.
33
33
  *
34
- * @since 0.5.0 — replaces `evaluateDomEquivalence`.
35
34
  */
36
35
  function verifyDomEquivalence(baseline, variant) {
37
36
  const warnings = [];
@@ -83,9 +82,5 @@ const DOM_FINGERPRINT_BROWSER_SCRIPT = `(() => {
83
82
  const elementCount = document.querySelectorAll("*").length;
84
83
  return { headingTexts, buttonTexts, inputValues, elementCount };
85
84
  })()`;
86
- /**
87
- * @deprecated since 0.5.0 — use `verifyDomEquivalence` instead. Removed in 1.0.0.
88
- */
89
- const evaluateDomEquivalence = verifyDomEquivalence;
90
85
  //#endregion
91
- export { DOM_FINGERPRINT_BROWSER_SCRIPT, evaluateDomEquivalence, verifyDomEquivalence };
86
+ export { DOM_FINGERPRINT_BROWSER_SCRIPT, verifyDomEquivalence };
@@ -261,7 +261,7 @@ async function main() {
261
261
  console.log(` ${DIM}Report: ${reportPath}${RESET}`);
262
262
  console.log();
263
263
  }
264
- if (process.env.__VRT_DISPATCHER_LEAF__ === "element-compare" || process.argv[1]?.endsWith("element-compare.ts")) main().catch((e) => {
264
+ if (process.env.__VLMKIT_DISPATCHER_LEAF__ === "element-compare" || process.argv[1]?.endsWith("element-compare.ts")) main().catch((e) => {
265
265
  console.error(e);
266
266
  process.exit(1);
267
267
  });
package/dist/index.d.mts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, HtmlSource, IntrospectResult, Language, LoopScore, NlAssertion, PageExpectation, PageIntrospection, PageSpec, PlaywrightReport, ProjectConfig, QualityCheckResult, QualityCheckType, ScoreDetail, ShiftRegion, SpecCheckType, SpecInvariant, TestAttempt, TestError, TestResult, TestSpec, TestSuite, UiSpec, UnifiedAgentContext, VisualChangeType, VisualExpectation, VisualSemanticChange, VisualSemanticDiff, VrtDiff, VrtExpectation, VrtSnapshot, VrtVerdict } from "./types.mjs";
2
- import { INTERACTIVE_ROLES, LANDMARK_ROLES, checkA11yTree, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
2
+ import { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
3
3
  import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
4
4
  import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
5
5
  import { diffComputedStyles } from "./computed-style-diff.mjs";
6
6
  import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
7
7
  import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
8
- import { evaluateDomEquivalence, verifyDomEquivalence } from "./dom-equivalence.mjs";
8
+ import { verifyDomEquivalence } from "./dom-equivalence.mjs";
9
9
  import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
10
10
  import { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.mjs";
11
11
  import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
12
12
  import { compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport } from "./heatmap.mjs";
13
13
  import { RESOLUTION_PRESETS, getImageDimensions, resizePngBuffer, resolveResolutionForViewport } from "./image-resize.mjs";
14
14
  import { compareRowTypography, computeRowGapDeltas, extractTextRowsFromFile, extractTextRowsFromRgba, matchTextRows } from "./text-rows.mjs";
15
- export { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AUTHORED_PROPERTIES, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, HtmlSource, INTERACTIVE_ROLES, IntrospectResult, LANDMARK_ROLES, Language, LoopScore, NlAssertion, PageExpectation, PageIntrospection, PageSpec, PlaywrightReport, ProjectConfig, QualityCheckResult, QualityCheckType, RESOLUTION_PRESETS, ScoreDetail, ShiftRegion, SpecCheckType, SpecInvariant, TRACKED_PROPERTIES, TestAttempt, TestError, TestResult, TestSpec, TestSuite, UiSpec, UnifiedAgentContext, VisualChangeType, VisualExpectation, VisualSemanticChange, VisualSemanticDiff, VrtDiff, VrtExpectation, VrtSnapshot, VrtVerdict, aggregateAuthoredStyleByViewport, checkA11yTree, compareRowTypography, compareScreenshots, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, evaluateDomEquivalence, extractTextRowsFromFile, extractTextRowsFromRgba, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence };
15
+ export { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AUTHORED_PROPERTIES, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, HtmlSource, INTERACTIVE_ROLES, IntrospectResult, LANDMARK_ROLES, Language, LoopScore, NlAssertion, PageExpectation, PageIntrospection, PageSpec, PlaywrightReport, ProjectConfig, QualityCheckResult, QualityCheckType, RESOLUTION_PRESETS, ScoreDetail, ShiftRegion, SpecCheckType, SpecInvariant, TRACKED_PROPERTIES, TestAttempt, TestError, TestResult, TestSpec, TestSuite, UiSpec, UnifiedAgentContext, VisualChangeType, VisualExpectation, VisualSemanticChange, VisualSemanticDiff, VrtDiff, VrtExpectation, VrtSnapshot, VrtVerdict, aggregateAuthoredStyleByViewport, compareRowTypography, compareScreenshots, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, extractTextRowsFromFile, extractTextRowsFromRgba, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence };
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import { INTERACTIVE_ROLES, LANDMARK_ROLES, checkA11yTree, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
1
+ import { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
2
2
  import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
3
3
  import { diffComputedStyles } from "./computed-style-diff.mjs";
4
4
  import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
5
5
  import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
6
6
  import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
7
- import { evaluateDomEquivalence, verifyDomEquivalence } from "./dom-equivalence.mjs";
7
+ import { verifyDomEquivalence } from "./dom-equivalence.mjs";
8
8
  import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
9
9
  import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
10
10
  import { compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport } from "./heatmap.mjs";
11
11
  import { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.mjs";
12
12
  import { RESOLUTION_PRESETS, getImageDimensions, resizePngBuffer, resolveResolutionForViewport } from "./image-resize.mjs";
13
13
  import { compareRowTypography, computeRowGapDeltas, extractTextRowsFromFile, extractTextRowsFromRgba, matchTextRows } from "./text-rows.mjs";
14
- export { AUTHORED_PROPERTIES, INTERACTIVE_ROLES, LANDMARK_ROLES, RESOLUTION_PRESETS, TRACKED_PROPERTIES, aggregateAuthoredStyleByViewport, checkA11yTree, compareRowTypography, compareScreenshots, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, evaluateDomEquivalence, extractTextRowsFromFile, extractTextRowsFromRgba, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence };
14
+ export { AUTHORED_PROPERTIES, INTERACTIVE_ROLES, LANDMARK_ROLES, RESOLUTION_PRESETS, TRACKED_PROPERTIES, aggregateAuthoredStyleByViewport, compareRowTypography, compareScreenshots, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, extractTextRowsFromFile, extractTextRowsFromRgba, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence };
@@ -0,0 +1,12 @@
1
+ //#region src/project-config.d.ts
2
+ declare const STATE_DIR = ".vlmkit";
3
+ declare const CONFIG_FILE = "vlmkit.config.json";
4
+ declare const CONFIG_CANDIDATES: readonly ["vlmkit.config.json", "vlmkit.config.toml"];
5
+ /** Resolve a project-owned state entry below the canonical state directory. */
6
+ declare function resolveStatePath(cwd: string, entry: string): string;
7
+ /** Read a canonical VLMKIT_* environment variable. */
8
+ declare function readEnv(suffix: string): string | undefined;
9
+ declare function debugEnabled(): boolean;
10
+ declare const ENV_SUFFIXES: readonly ["BASE_URL", "CAPTURE_BACKEND", "CONFIG_FILE", "CONFIG_PATH", "LLM_MODEL", "LLM_PROVIDER", "PROJECT_ROOT", "VLM_MODEL"];
11
+ //#endregion
12
+ export { CONFIG_CANDIDATES, CONFIG_FILE, ENV_SUFFIXES, STATE_DIR, debugEnabled, readEnv, resolveStatePath };
@@ -0,0 +1,28 @@
1
+ import { resolve } from "node:path";
2
+ //#region src/project-config.ts
3
+ const STATE_DIR = ".vlmkit";
4
+ const CONFIG_FILE = "vlmkit.config.json";
5
+ const CONFIG_CANDIDATES = [CONFIG_FILE, "vlmkit.config.toml"];
6
+ /** Resolve a project-owned state entry below the canonical state directory. */
7
+ function resolveStatePath(cwd, entry) {
8
+ return resolve(cwd, STATE_DIR, entry);
9
+ }
10
+ /** Read a canonical VLMKIT_* environment variable. */
11
+ function readEnv(suffix) {
12
+ return process.env[`VLMKIT_${suffix}`] || void 0;
13
+ }
14
+ function debugEnabled() {
15
+ return Boolean(process.env.DEBUG_VLMKIT);
16
+ }
17
+ const ENV_SUFFIXES = [
18
+ "BASE_URL",
19
+ "CAPTURE_BACKEND",
20
+ "CONFIG_FILE",
21
+ "CONFIG_PATH",
22
+ "LLM_MODEL",
23
+ "LLM_PROVIDER",
24
+ "PROJECT_ROOT",
25
+ "VLM_MODEL"
26
+ ];
27
+ //#endregion
28
+ export { CONFIG_CANDIDATES, CONFIG_FILE, ENV_SUFFIXES, STATE_DIR, debugEnabled, readEnv, resolveStatePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mizchi/vlmkit-core",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "VRT diff engine + shared types — pure image / DOM / a11y / visual comparison primitives.",
5
5
  "license": "MIT",
6
6
  "author": "mizchi",
@@ -37,9 +37,11 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "pixelmatch": "^7.1.0",
40
- "playwright": "^1.61.1",
41
40
  "pngjs": "^7.0.0"
42
41
  },
42
+ "peerDependencies": {
43
+ "playwright": ">=1.61 <2"
44
+ },
43
45
  "scripts": {
44
46
  "build": "pnpm --dir ../.. exec tsdown --config tsdown.packages.config.ts --filter @mizchi/vlmkit-core",
45
47
  "test": "node --test 'src/**/*.test.ts'"
@@ -1,48 +0,0 @@
1
- //#region src/legacy-names.d.ts
2
- declare const STATE_DIR = ".vlmkit";
3
- declare const LEGACY_STATE_DIR = ".vrt";
4
- declare const CONFIG_FILE = "vlmkit.config.json";
5
- declare const LEGACY_CONFIG_FILE = "vrt.config.json";
6
- declare function noteLegacyName(oldName: string, newName: string, detail?: string): void;
7
- /** Reset between tests. */
8
- declare function resetLegacyNotices(): void;
9
- /**
10
- * Absolute path for a state entry, preferring `.vlmkit/<entry>` and falling back
11
- * to an existing `.vrt/<entry>`.
12
- *
13
- * Writers get the new path unless the old one is already populated, so a
14
- * project keeps appending where its history is instead of starting a second,
15
- * half-empty baseline set beside it.
16
- */
17
- declare function resolveStatePath(cwd: string, entry: string): string;
18
- /**
19
- * Config filenames in search order: new before old, JSON before TOML (JSON wins
20
- * when both exist, which was the pre-rename behaviour). `legacy: true` entries
21
- * are what `findConfigPath` reports a notice for.
22
- *
23
- * Exported as data rather than a resolver because the caller also has to name
24
- * every candidate in its "not found" error — listing only the new one would
25
- * tell a project with a working `vrt.config.json` that it has no config.
26
- */
27
- declare const CONFIG_CANDIDATES: readonly {
28
- name: string;
29
- legacy: boolean;
30
- }[];
31
- /**
32
- * `VLMKIT_FOO`, falling back to `VRT_FOO`.
33
- *
34
- * Pass the suffix, not the whole name, so a call site cannot mismatch the two
35
- * halves — `readEnv("LLM_MODEL")` reads `VLMKIT_LLM_MODEL` then `VRT_LLM_MODEL`.
36
- * An empty string counts as unset, matching how the previous `process.env.X ||`
37
- * reads behaved.
38
- */
39
- declare function readEnv(suffix: string): string | undefined;
40
- /**
41
- * `DEBUG_VLMKIT`, falling back to `DEBUG_VRT`. Separate from `readEnv` because
42
- * this one is a prefix, not a suffix — `DEBUG_VRT`, not `VRT_DEBUG`.
43
- */
44
- declare function debugEnabled(): boolean;
45
- /** Every env suffix that has both spellings, so the docs and tests can enumerate. */
46
- declare const ENV_SUFFIXES: readonly ["BASE_URL", "CAPTURE_BACKEND", "CONFIG_FILE", "CONFIG_PATH", "LLM_MODEL", "LLM_PROVIDER", "PROJECT_ROOT", "VLM_MODEL"];
47
- //#endregion
48
- export { CONFIG_CANDIDATES, CONFIG_FILE, ENV_SUFFIXES, LEGACY_CONFIG_FILE, LEGACY_STATE_DIR, STATE_DIR, debugEnabled, noteLegacyName, readEnv, resetLegacyNotices, resolveStatePath };
@@ -1,134 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
- //#region src/legacy-names.ts
4
- /**
5
- * Backward compatibility for the `vrt` → `vlmkit` rename of things that are not
6
- * text: the state directory, the config filename, and the environment
7
- * variables.
8
- *
9
- * The command-name rename was pure text — nothing on disk moved. These three
10
- * are different: rename them without a fallback and every existing project
11
- * silently loses its approved baselines, stops finding its config, and drops
12
- * whatever its CI exports. So each new name is preferred, each old name still
13
- * works, and using an old one prints one line saying so.
14
- *
15
- * ## Why per-subpath and not per-directory
16
- *
17
- * `.vlmkit/` already exists in any project that has run a gate — the run
18
- * ledger, `gates`, `markup-loop` and `copy-review` all live there, while
19
- * `baselines`, `runs` and `last-diff-for-agent.json` were still under `.vrt/`.
20
- * So "if `.vlmkit/` is missing, use `.vrt/`" would resolve to the new directory
21
- * immediately and lose the baselines anyway. The check has to be on the
22
- * specific entry: `.vlmkit/baselines` vs `.vrt/baselines`.
23
- *
24
- * ## What is deliberately NOT here
25
- *
26
- * Values that leave this process or land in someone else's file — the
27
- * `X-Title` header sent to OpenRouter, the Playwright `projectName` that
28
- * appears inside snapshot paths, the plan schema's `vrt?:` field, the published
29
- * OpenAPI title. Those are wire and data formats, not local state, and moving
30
- * them is a separate decision.
31
- */
32
- const STATE_DIR = ".vlmkit";
33
- const LEGACY_STATE_DIR = ".vrt";
34
- const CONFIG_FILE = "vlmkit.config.json";
35
- const LEGACY_CONFIG_FILE = "vrt.config.json";
36
- /** One notice per distinct old name per process — a loop must not spam. */
37
- const announced = /* @__PURE__ */ new Set();
38
- function noteLegacyName(oldName, newName, detail = "") {
39
- if (announced.has(oldName)) return;
40
- announced.add(oldName);
41
- const tag = !process.env.NO_COLOR && process.stderr.isTTY ? "\x1B[33m[vlmkit legacy]\x1B[0m" : "[vlmkit legacy]";
42
- process.stderr.write(`${tag} using ${oldName} — rename to ${newName}; support ends in 1.0.0${detail ? `. ${detail}` : ""}\n`);
43
- }
44
- /** Reset between tests. */
45
- function resetLegacyNotices() {
46
- announced.clear();
47
- }
48
- /**
49
- * Absolute path for a state entry, preferring `.vlmkit/<entry>` and falling back
50
- * to an existing `.vrt/<entry>`.
51
- *
52
- * Writers get the new path unless the old one is already populated, so a
53
- * project keeps appending where its history is instead of starting a second,
54
- * half-empty baseline set beside it.
55
- */
56
- function resolveStatePath(cwd, entry) {
57
- const next = resolve(cwd, join(STATE_DIR, entry));
58
- if (existsSync(next)) return next;
59
- const legacy = resolve(cwd, join(LEGACY_STATE_DIR, entry));
60
- if (existsSync(legacy)) {
61
- noteLegacyName(`${LEGACY_STATE_DIR}/${entry}`, `${STATE_DIR}/${entry}`, "move it to keep using one location");
62
- return legacy;
63
- }
64
- return next;
65
- }
66
- /**
67
- * Config filenames in search order: new before old, JSON before TOML (JSON wins
68
- * when both exist, which was the pre-rename behaviour). `legacy: true` entries
69
- * are what `findConfigPath` reports a notice for.
70
- *
71
- * Exported as data rather than a resolver because the caller also has to name
72
- * every candidate in its "not found" error — listing only the new one would
73
- * tell a project with a working `vrt.config.json` that it has no config.
74
- */
75
- const CONFIG_CANDIDATES = [
76
- {
77
- name: CONFIG_FILE,
78
- legacy: false
79
- },
80
- {
81
- name: "vlmkit.config.toml",
82
- legacy: false
83
- },
84
- {
85
- name: LEGACY_CONFIG_FILE,
86
- legacy: true
87
- },
88
- {
89
- name: "vrt.config.toml",
90
- legacy: true
91
- }
92
- ];
93
- /**
94
- * `VLMKIT_FOO`, falling back to `VRT_FOO`.
95
- *
96
- * Pass the suffix, not the whole name, so a call site cannot mismatch the two
97
- * halves — `readEnv("LLM_MODEL")` reads `VLMKIT_LLM_MODEL` then `VRT_LLM_MODEL`.
98
- * An empty string counts as unset, matching how the previous `process.env.X ||`
99
- * reads behaved.
100
- */
101
- function readEnv(suffix) {
102
- const next = process.env[`VLMKIT_${suffix}`];
103
- if (next) return next;
104
- const legacy = process.env[`VRT_${suffix}`];
105
- if (legacy) {
106
- noteLegacyName(`VRT_${suffix}`, `VLMKIT_${suffix}`);
107
- return legacy;
108
- }
109
- }
110
- /**
111
- * `DEBUG_VLMKIT`, falling back to `DEBUG_VRT`. Separate from `readEnv` because
112
- * this one is a prefix, not a suffix — `DEBUG_VRT`, not `VRT_DEBUG`.
113
- */
114
- function debugEnabled() {
115
- if (process.env.DEBUG_VLMKIT) return true;
116
- if (process.env.DEBUG_VRT) {
117
- noteLegacyName("DEBUG_VRT", "DEBUG_VLMKIT");
118
- return true;
119
- }
120
- return false;
121
- }
122
- /** Every env suffix that has both spellings, so the docs and tests can enumerate. */
123
- const ENV_SUFFIXES = [
124
- "BASE_URL",
125
- "CAPTURE_BACKEND",
126
- "CONFIG_FILE",
127
- "CONFIG_PATH",
128
- "LLM_MODEL",
129
- "LLM_PROVIDER",
130
- "PROJECT_ROOT",
131
- "VLM_MODEL"
132
- ];
133
- //#endregion
134
- export { CONFIG_CANDIDATES, CONFIG_FILE, ENV_SUFFIXES, LEGACY_CONFIG_FILE, LEGACY_STATE_DIR, STATE_DIR, debugEnabled, noteLegacyName, readEnv, resetLegacyNotices, resolveStatePath };