@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,117 @@
|
|
|
1
|
+
//#region src/authored-style-capture.ts
|
|
2
|
+
/**
|
|
3
|
+
* Properties tracked by default. These are the ones whose computed
|
|
4
|
+
* representation differs structurally from the authored source — anything
|
|
5
|
+
* already faithful in `getComputedStyle` does not need this channel.
|
|
6
|
+
*/
|
|
7
|
+
const AUTHORED_PROPERTIES = [
|
|
8
|
+
"grid-template",
|
|
9
|
+
"grid-template-columns",
|
|
10
|
+
"grid-template-rows",
|
|
11
|
+
"grid-template-areas",
|
|
12
|
+
"grid-auto-columns",
|
|
13
|
+
"grid-auto-rows",
|
|
14
|
+
"grid-auto-flow",
|
|
15
|
+
"grid-column",
|
|
16
|
+
"grid-row",
|
|
17
|
+
"grid",
|
|
18
|
+
"flex",
|
|
19
|
+
"transform",
|
|
20
|
+
"clip-path",
|
|
21
|
+
"mask",
|
|
22
|
+
"mask-image"
|
|
23
|
+
];
|
|
24
|
+
const MEDIA_SEPARATOR = " :: ";
|
|
25
|
+
/**
|
|
26
|
+
* Format a "scoped" selector key. When `mediaCondition` is empty, returns
|
|
27
|
+
* the bare selector text. When non-empty, the key reads
|
|
28
|
+
* `@media (min-width: 768px) :: .shell` so the diff treats the same
|
|
29
|
+
* selector inside a different `@media` block as a distinct row.
|
|
30
|
+
*/
|
|
31
|
+
function buildScopedSelectorKey(selector, mediaCondition) {
|
|
32
|
+
const trimmedMedia = mediaCondition.trim();
|
|
33
|
+
if (!trimmedMedia) return selector;
|
|
34
|
+
return `@media ${trimmedMedia}${MEDIA_SEPARATOR}${selector}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Browser-context capture. Walks all same-origin stylesheets and nested
|
|
38
|
+
* `@media` / `@supports` rules, collecting authored `value` strings for
|
|
39
|
+
* each (scoped-selector, property) pair listed in `props`. Last
|
|
40
|
+
* declaration wins per pair (mirrors authoring order; sufficient for
|
|
41
|
+
* static diff use cases).
|
|
42
|
+
*
|
|
43
|
+
* Selectors are comma-split so `.a, .b { grid-template-columns: ... }`
|
|
44
|
+
* fans out into both `.a` and `.b` entries.
|
|
45
|
+
*/
|
|
46
|
+
function captureAuthoredStyleSnapshotInDom(props) {
|
|
47
|
+
const trackedProps = new Set(props);
|
|
48
|
+
const results = {};
|
|
49
|
+
function visit(rule, mediaCondition) {
|
|
50
|
+
if (!rule || typeof rule !== "object") return;
|
|
51
|
+
const ruleObj = rule;
|
|
52
|
+
const conditionFromMedia = typeof ruleObj.media?.mediaText === "string" ? ruleObj.media.mediaText : "";
|
|
53
|
+
const conditionFromAt = typeof ruleObj.conditionText === "string" ? ruleObj.conditionText : "";
|
|
54
|
+
const additionalCondition = conditionFromMedia || conditionFromAt;
|
|
55
|
+
const nestedMedia = additionalCondition ? mediaCondition ? `${mediaCondition} and ${additionalCondition}` : additionalCondition : mediaCondition;
|
|
56
|
+
if (ruleObj.cssRules && typeof ruleObj.cssRules.length === "number") {
|
|
57
|
+
const nested = ruleObj.cssRules;
|
|
58
|
+
for (let i = 0; i < nested.length; i++) visit(nested[i], nestedMedia);
|
|
59
|
+
if (!ruleObj.selectorText) return;
|
|
60
|
+
}
|
|
61
|
+
if (typeof ruleObj.selectorText !== "string") return;
|
|
62
|
+
const style = ruleObj.style;
|
|
63
|
+
if (!style || typeof style.getPropertyValue !== "function") return;
|
|
64
|
+
for (const rawSelector of ruleObj.selectorText.split(",")) {
|
|
65
|
+
const selector = rawSelector.trim();
|
|
66
|
+
if (!selector) continue;
|
|
67
|
+
const key = buildScopedSelectorKey(selector, mediaCondition);
|
|
68
|
+
for (const prop of trackedProps) {
|
|
69
|
+
const value = style.getPropertyValue(prop);
|
|
70
|
+
if (!value) continue;
|
|
71
|
+
const bucket = results[key] ?? (results[key] = {});
|
|
72
|
+
bucket[prop] = value.trim();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const styleSheets = document.styleSheets;
|
|
77
|
+
if (!styleSheets) return results;
|
|
78
|
+
for (const sheet of Array.from(styleSheets)) try {
|
|
79
|
+
const rules = sheet.cssRules;
|
|
80
|
+
for (const rule of Array.from(rules)) visit(rule, "");
|
|
81
|
+
} catch {}
|
|
82
|
+
return results;
|
|
83
|
+
}
|
|
84
|
+
const ESBUILD_NAME_POLYFILL = "var __name = typeof __name !== 'undefined' ? __name : function(fn) { return fn; };";
|
|
85
|
+
function buildAuthoredStyleCaptureExpression(props = AUTHORED_PROPERTIES) {
|
|
86
|
+
return `(function(){ ${ESBUILD_NAME_POLYFILL} return (${captureAuthoredStyleSnapshotInDom.toString()})(${JSON.stringify(props)}); })()`;
|
|
87
|
+
}
|
|
88
|
+
function buildAuthoredStyleCaptureJsonExpression(props = AUTHORED_PROPERTIES) {
|
|
89
|
+
return `JSON.stringify(${buildAuthoredStyleCaptureExpression(props)})`;
|
|
90
|
+
}
|
|
91
|
+
function parseAuthoredStyleSnapshot(value) {
|
|
92
|
+
const candidate = typeof value === "string" ? safeJsonParse(value) : value;
|
|
93
|
+
if (!isRecord(candidate)) return {};
|
|
94
|
+
const snapshot = {};
|
|
95
|
+
for (const [selector, props] of Object.entries(candidate)) {
|
|
96
|
+
if (!isRecord(props)) continue;
|
|
97
|
+
const normalized = {};
|
|
98
|
+
for (const [prop, propValue] of Object.entries(props)) normalized[prop] = typeof propValue === "string" ? propValue : String(propValue ?? "");
|
|
99
|
+
snapshot[selector] = normalized;
|
|
100
|
+
}
|
|
101
|
+
return snapshot;
|
|
102
|
+
}
|
|
103
|
+
function hasMeaningfulAuthoredStyleSnapshot(snapshot) {
|
|
104
|
+
return Object.values(snapshot).some((props) => Object.values(props).some((value) => value.trim().length > 0));
|
|
105
|
+
}
|
|
106
|
+
function safeJsonParse(value) {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(value);
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function isRecord(value) {
|
|
114
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { AUTHORED_PROPERTIES, buildAuthoredStyleCaptureExpression, buildAuthoredStyleCaptureJsonExpression, captureAuthoredStyleSnapshotInDom, hasMeaningfulAuthoredStyleSnapshot, parseAuthoredStyleSnapshot };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthoredStyleSnapshot } from "./authored-style-capture.mjs";
|
|
2
|
+
import { CsdEntry, CsdPerViewportEntry, CsdPerViewportResult, CsdResult } from "./computed-style-diff.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/authored-style-diff.d.ts
|
|
5
|
+
type AuthoredStyleEntry = CsdEntry;
|
|
6
|
+
type AuthoredStyleDiffResult = CsdResult;
|
|
7
|
+
type AuthoredStylePerViewportEntry = CsdPerViewportEntry;
|
|
8
|
+
type AuthoredStylePerViewportResult = CsdPerViewportResult;
|
|
9
|
+
declare function diffAuthoredStyles(baseline: AuthoredStyleSnapshot, variant: AuthoredStyleSnapshot): AuthoredStyleDiffResult;
|
|
10
|
+
declare function aggregateAuthoredStyleByViewport(perViewport: ReadonlyArray<{
|
|
11
|
+
viewport: string;
|
|
12
|
+
result: AuthoredStyleDiffResult;
|
|
13
|
+
}>): AuthoredStylePerViewportResult;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { AuthoredStyleDiffResult, AuthoredStyleEntry, AuthoredStylePerViewportEntry, AuthoredStylePerViewportResult, aggregateAuthoredStyleByViewport, diffAuthoredStyles };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { aggregateCsdByViewport, diffComputedStyles } from "./computed-style-diff.mjs";
|
|
2
|
+
//#region src/authored-style-diff.ts
|
|
3
|
+
/**
|
|
4
|
+
* Authored-style diff. Same shape as `computed-style-diff` (a snapshot is
|
|
5
|
+
* `Record<scopedSelector, Record<property, value>>` in both cases), so the
|
|
6
|
+
* heavy lifting reuses `diffComputedStyles` — only the snapshot type
|
|
7
|
+
* label differs.
|
|
8
|
+
*/
|
|
9
|
+
function diffAuthoredStyles(baseline, variant) {
|
|
10
|
+
return diffComputedStyles(baseline, variant);
|
|
11
|
+
}
|
|
12
|
+
function aggregateAuthoredStyleByViewport(perViewport) {
|
|
13
|
+
return aggregateCsdByViewport(perViewport);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { aggregateAuthoredStyleByViewport, diffAuthoredStyles };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/cli-args.d.ts
|
|
2
|
+
declare function getArg(name: string, fallback: string): string;
|
|
3
|
+
declare function getArg(name: string): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Numeric flags, validated. Callers used to write `parseInt(getArg(n, d), 10)`,
|
|
6
|
+
* which is where a bad value became `NaN` — far from the flag that caused it.
|
|
7
|
+
*/
|
|
8
|
+
declare function getIntArg(name: string, fallback: number, options?: {
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
}): number;
|
|
12
|
+
declare function getFloatArg(name: string, fallback: number, options?: {
|
|
13
|
+
min?: number;
|
|
14
|
+
max?: number;
|
|
15
|
+
}): number;
|
|
16
|
+
declare function hasFlag(name: string): boolean;
|
|
17
|
+
declare function getArgValues(name: string): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Positional arguments.
|
|
20
|
+
*
|
|
21
|
+
* `valueFlags` names the flags that consume the next argument — required,
|
|
22
|
+
* because argv alone cannot tell `--limit 30` from `--md model-name`. The old
|
|
23
|
+
* implementation assumed *every* flag takes a value, which silently dropped a
|
|
24
|
+
* positional that happened to follow a boolean flag.
|
|
25
|
+
*/
|
|
26
|
+
declare function getPositionalArgs(valueFlags?: readonly string[]): string[];
|
|
27
|
+
/** Raw argv tail, for callers doing their own scanning. */
|
|
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
|
+
//#endregion
|
|
35
|
+
export { args, getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { hasFlag as hasFlag$1, readAll, readFlag, readNumber, readPositionals } from "./arg-reader.mjs";
|
|
2
|
+
//#region src/cli-args.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared CLI argument helpers, kept as the ergonomic `process.argv`-bound
|
|
5
|
+
* facade over `arg-reader.ts`.
|
|
6
|
+
*
|
|
7
|
+
* This used to be a standalone implementation, and it silently produced wrong
|
|
8
|
+
* values. `getArg("seed", fallback)` returned whatever followed the flag, so
|
|
9
|
+
* `fix-loop --seed --mode selector` yielded `"--mode"`, and the caller's
|
|
10
|
+
* `parseInt` turned that into a `NaN` seed with no complaint. Every reader here
|
|
11
|
+
* now delegates to `arg-reader`, which treats a flag-shaped value and a
|
|
12
|
+
* non-numeric number as errors.
|
|
13
|
+
*
|
|
14
|
+
* `argv()` is read per call rather than captured at import time, so a leaf
|
|
15
|
+
* reached through the CLI dispatcher — which rewrites `process.argv` before
|
|
16
|
+
* loading the leaf — sees the arguments it was actually given.
|
|
17
|
+
*/
|
|
18
|
+
const argv = () => process.argv.slice(2);
|
|
19
|
+
function getArg(name, fallback) {
|
|
20
|
+
const value = readFlag(argv(), name);
|
|
21
|
+
return value === void 0 || value === "" ? fallback : value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Numeric flags, validated. Callers used to write `parseInt(getArg(n, d), 10)`,
|
|
25
|
+
* which is where a bad value became `NaN` — far from the flag that caused it.
|
|
26
|
+
*/
|
|
27
|
+
function getIntArg(name, fallback, options = {}) {
|
|
28
|
+
return readNumber(argv(), name, {
|
|
29
|
+
...options,
|
|
30
|
+
integer: true
|
|
31
|
+
}) ?? fallback;
|
|
32
|
+
}
|
|
33
|
+
function getFloatArg(name, fallback, options = {}) {
|
|
34
|
+
return readNumber(argv(), name, options) ?? fallback;
|
|
35
|
+
}
|
|
36
|
+
function hasFlag(name) {
|
|
37
|
+
return hasFlag$1(argv(), name);
|
|
38
|
+
}
|
|
39
|
+
function getArgValues(name) {
|
|
40
|
+
return readAll(argv(), name);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Positional arguments.
|
|
44
|
+
*
|
|
45
|
+
* `valueFlags` names the flags that consume the next argument — required,
|
|
46
|
+
* because argv alone cannot tell `--limit 30` from `--md model-name`. The old
|
|
47
|
+
* implementation assumed *every* flag takes a value, which silently dropped a
|
|
48
|
+
* positional that happened to follow a boolean flag.
|
|
49
|
+
*/
|
|
50
|
+
function getPositionalArgs(valueFlags = []) {
|
|
51
|
+
return readPositionals(argv(), valueFlags);
|
|
52
|
+
}
|
|
53
|
+
/** Raw argv tail, for callers doing their own scanning. */
|
|
54
|
+
function getRawArgs() {
|
|
55
|
+
return argv();
|
|
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
|
+
//#endregion
|
|
63
|
+
export { args, getArg, getArgValues, getFloatArg, getIntArg, getPositionalArgs, getRawArgs, hasFlag };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/cli-error.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A bad flag or missing argument — the caller's typo, not a defect. Thrown by
|
|
4
|
+
* `arg-reader` and printed as one line, because a stack trace for
|
|
5
|
+
* `--concurrency abc` buries the one sentence that fixes it.
|
|
6
|
+
*/
|
|
7
|
+
declare class UsageError extends Error {
|
|
8
|
+
readonly name = "UsageError";
|
|
9
|
+
}
|
|
10
|
+
declare function handleCliError(e: unknown): never;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { UsageError, handleCliError };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
//#region src/cli-error.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared CLI error-prettifier. Recognizes common error shapes that
|
|
5
|
+
* make `vlmkit` look user-hostile (ENOENT stack traces, Playwright
|
|
6
|
+
* navigation errors with absolute source paths) and rewrites them
|
|
7
|
+
* to a one-line message.
|
|
8
|
+
*
|
|
9
|
+
* Use:
|
|
10
|
+
* main().catch(handleCliError);
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A bad flag or missing argument — the caller's typo, not a defect. Thrown by
|
|
14
|
+
* `arg-reader` and printed as one line, because a stack trace for
|
|
15
|
+
* `--concurrency abc` buries the one sentence that fixes it.
|
|
16
|
+
*/
|
|
17
|
+
var UsageError = class extends Error {
|
|
18
|
+
name = "UsageError";
|
|
19
|
+
};
|
|
20
|
+
function handleCliError(e) {
|
|
21
|
+
const err = e;
|
|
22
|
+
const msg = String(err?.message ?? e);
|
|
23
|
+
if (err?.name === "UsageError") {
|
|
24
|
+
process.stderr.write(`error: ${msg}\n`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
if (err?.code === "ENOENT") {
|
|
28
|
+
const path = err.path ?? msg.match(/ENOENT: no such file or directory[^']*'([^']+)'/)?.[1] ?? "?";
|
|
29
|
+
process.stderr.write(`error: file not found: ${path}\n`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
if (err?.code === "EISDIR") {
|
|
33
|
+
const argvDir = findDirectoryArg();
|
|
34
|
+
const path = err.path ?? msg.match(/EISDIR:[^']*'([^']+)'/)?.[1] ?? argvDir ?? "?";
|
|
35
|
+
const hint = path === "?" ? " hint: pass the path to a specific .html file." : ` hint: pass the path to a specific .html file inside it (e.g. ${path}/page.html).`;
|
|
36
|
+
process.stderr.write(`error: expected an HTML file, got a directory: ${path}\n${hint}\n`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
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
|
+
const url = msg.match(/Navigating to ([^,]+)/i)?.[1] ?? msg.match(/(https?:\/\/[^\s"]+)/)?.[1] ?? "the URL";
|
|
41
|
+
let reason = "failed to load";
|
|
42
|
+
if (/ERR_NAME_NOT_RESOLVED/i.test(msg)) reason = "host could not be resolved (check the URL)";
|
|
43
|
+
else if (/ERR_CONNECTION_REFUSED/i.test(msg)) reason = "connection refused (is the server running?)";
|
|
44
|
+
else if (/invalid URL/i.test(msg)) reason = "not a valid URL";
|
|
45
|
+
process.stderr.write(`error: cannot load ${url}: ${reason}\n`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
if (/Timeout \d+ms exceeded/i.test(msg)) {
|
|
49
|
+
process.stderr.write(`error: page load timed out (${msg.match(/Timeout \d+ms exceeded[^.]*/i)?.[0] ?? msg})\n`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
console.error(e);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* EISDIR fallback: Node's `fsPromises.readFile` doesn't attach `.path`
|
|
57
|
+
* to the error, and the message string doesn't include the path
|
|
58
|
+
* either. Scan argv for the first positional that exists as a
|
|
59
|
+
* directory — close enough since most vlmkit subcommands take exactly
|
|
60
|
+
* one path argument and the failure happens during the initial read.
|
|
61
|
+
*/
|
|
62
|
+
function findDirectoryArg() {
|
|
63
|
+
for (const arg of process.argv.slice(2)) {
|
|
64
|
+
if (arg.startsWith("-")) continue;
|
|
65
|
+
try {
|
|
66
|
+
if (statSync(arg).isDirectory()) return arg;
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { UsageError, handleCliError };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/computed-style-capture.d.ts
|
|
2
|
+
type ComputedStyleSnapshot = Record<string, Record<string, string>>;
|
|
3
|
+
type InteractionType = "hover" | "focus" | "active";
|
|
4
|
+
/** Pseudo-class state names that CDP `CSS.forcePseudoState` accepts. */
|
|
5
|
+
type ForcedPseudoState = "hover" | "focus" | "focus-visible" | "focus-within" | "active";
|
|
6
|
+
interface InteractionTargetPlan {
|
|
7
|
+
selector: string;
|
|
8
|
+
normalizedSelector: string;
|
|
9
|
+
/**
|
|
10
|
+
* Primary interaction kind, kept for legacy fallback ordering:
|
|
11
|
+
* `:active` collapses to "active", any `:focus*` to "focus", else "hover".
|
|
12
|
+
*/
|
|
13
|
+
interaction: InteractionType;
|
|
14
|
+
/**
|
|
15
|
+
* The actual pseudo-class names extracted from the selector — preserves
|
|
16
|
+
* the full set (e.g. `:hover:active` → ["hover", "active"]) so Crater and
|
|
17
|
+
* the CDP-driven Playwright fallback can force identical states.
|
|
18
|
+
*/
|
|
19
|
+
forcedStates: ForcedPseudoState[];
|
|
20
|
+
}
|
|
21
|
+
declare const TRACKED_PROPERTIES: string[];
|
|
22
|
+
declare function normalizeInteractionSelector(selector: string): string;
|
|
23
|
+
declare function buildInteractionTargetPlans(selectors: string[]): InteractionTargetPlan[];
|
|
24
|
+
declare function selectInteractionFallbackPlans(plans: InteractionTargetPlan[], emulatedSnapshotMeaningful: boolean): InteractionTargetPlan[];
|
|
25
|
+
declare function mergeComputedStyleSnapshots(...snapshots: ComputedStyleSnapshot[]): ComputedStyleSnapshot;
|
|
26
|
+
declare function captureComputedStyleSnapshotInDom(props: string[]): ComputedStyleSnapshot;
|
|
27
|
+
declare function captureComputedStyleSnapshotForTargetSelectorsInDom(input: {
|
|
28
|
+
props: string[];
|
|
29
|
+
selectors: string[];
|
|
30
|
+
}): ComputedStyleSnapshot;
|
|
31
|
+
declare function collectInteractionTargetPlansInDom(): InteractionTargetPlan[];
|
|
32
|
+
declare function waitForInteractionStylesInDom(): Promise<void>;
|
|
33
|
+
declare function captureEmulatedInteractionStyleSnapshotInDom(props: string[]): Promise<ComputedStyleSnapshot>;
|
|
34
|
+
declare function computedStyleSnapshotToMap(snapshot: ComputedStyleSnapshot): Map<string, Record<string, string>>;
|
|
35
|
+
declare const ESBUILD_NAME_POLYFILL = "var __name = typeof __name !== 'undefined' ? __name : function(fn) { return fn; };";
|
|
36
|
+
declare function buildComputedStyleCaptureExpression(props?: string[]): string;
|
|
37
|
+
declare function buildComputedStyleCaptureJsonExpression(props?: string[]): string;
|
|
38
|
+
declare function parseComputedStyleSnapshot(value: unknown): ComputedStyleSnapshot;
|
|
39
|
+
declare function hasMeaningfulComputedStyleSnapshot(snapshot: ComputedStyleSnapshot): boolean;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ComputedStyleSnapshot, ESBUILD_NAME_POLYFILL, ForcedPseudoState, InteractionTargetPlan, InteractionType, TRACKED_PROPERTIES, buildComputedStyleCaptureExpression, buildComputedStyleCaptureJsonExpression, buildInteractionTargetPlans, captureComputedStyleSnapshotForTargetSelectorsInDom, captureComputedStyleSnapshotInDom, captureEmulatedInteractionStyleSnapshotInDom, collectInteractionTargetPlansInDom, computedStyleSnapshotToMap, hasMeaningfulComputedStyleSnapshot, mergeComputedStyleSnapshots, normalizeInteractionSelector, parseComputedStyleSnapshot, selectInteractionFallbackPlans, waitForInteractionStylesInDom };
|