@mizchi/vlmkit-core 0.24.0 → 0.28.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/dist/a11y-semantic.d.mts +1 -3
- package/dist/a11y-semantic.mjs +1 -2
- package/dist/animated-image.d.mts +1 -3
- package/dist/animated-image.mjs +1 -2
- package/dist/apng.d.mts +1 -3
- package/dist/apng.mjs +1 -2
- package/dist/arg-reader.d.mts +1 -3
- package/dist/arg-reader.mjs +1 -2
- package/dist/auth-state.d.mts +1 -3
- package/dist/auth-state.mjs +1 -2
- package/dist/authored-style-capture.d.mts +1 -3
- package/dist/authored-style-capture.mjs +1 -2
- package/dist/authored-style-diff.d.mts +2 -4
- package/dist/authored-style-diff.mjs +1 -2
- package/dist/bitmap-font.d.mts +1 -3
- package/dist/bitmap-font.mjs +1 -2
- package/dist/browser-launch.d.mts +1 -3
- package/dist/browser-launch.mjs +1 -2
- package/dist/cli-args.d.mts +1 -3
- package/dist/cli-args.mjs +1 -2
- package/dist/cli-error.d.mts +0 -2
- package/dist/cli-error.mjs +1 -2
- package/dist/computed-style-capture.d.mts +1 -3
- package/dist/computed-style-capture.mjs +1 -2
- package/dist/computed-style-diff.d.mts +0 -2
- package/dist/computed-style-diff.mjs +1 -2
- package/dist/diff-regions.d.mts +1 -3
- package/dist/diff-regions.mjs +1 -2
- package/dist/dom-equivalence.d.mts +1 -3
- package/dist/dom-equivalence.mjs +1 -2
- package/dist/dom-position-styles.d.mts +1 -3
- package/dist/dom-position-styles.mjs +1 -2
- package/dist/element-compare.d.mts +1 -3
- package/dist/element-compare.mjs +2 -3
- package/dist/filmstrip.d.mts +1 -3
- package/dist/filmstrip.mjs +1 -2
- package/dist/gate-config.d.mts +1 -3
- package/dist/gate-config.mjs +8 -4
- package/dist/gate-exit.d.mts +1 -3
- package/dist/gate-exit.mjs +1 -2
- package/dist/gif.d.mts +1 -3
- package/dist/gif.mjs +1 -2
- package/dist/heatmap-regions.d.mts +1 -3
- package/dist/heatmap-regions.mjs +1 -2
- package/dist/heatmap.d.mts +1 -3
- package/dist/heatmap.mjs +12 -8
- package/dist/image-resize.d.mts +1 -3
- package/dist/image-resize.mjs +1 -2
- package/dist/image-timing.d.mts +1 -3
- package/dist/image-timing.mjs +1 -2
- package/dist/index.d.mts +12 -12
- package/dist/index.mjs +11 -11
- package/dist/mask.d.mts +1 -3
- package/dist/mask.mjs +1 -2
- package/dist/motion-spec.d.mts +97 -0
- package/dist/motion-spec.mjs +145 -0
- package/dist/navigation-redirect.d.mts +1 -3
- package/dist/navigation-redirect.mjs +1 -2
- package/dist/page-load.d.mts +28 -3
- package/dist/page-load.mjs +34 -5
- package/dist/page-open.d.mts +5 -3
- package/dist/page-open.mjs +4 -3
- package/dist/plugin/args.d.mts +1 -3
- package/dist/plugin/args.mjs +3 -3
- package/dist/plugin/browser.d.mts +3 -3
- package/dist/plugin/browser.mjs +2 -2
- package/dist/plugin/cli-entry.d.mts +1 -3
- package/dist/plugin/cli-entry.mjs +1 -2
- package/dist/plugin/contract.d.mts +1 -3
- package/dist/plugin/contract.mjs +1 -2
- package/dist/plugin/index.d.mts +4 -6
- package/dist/plugin/index.mjs +7 -8
- package/dist/plugin/load.d.mts +1 -3
- package/dist/plugin/load.mjs +1 -2
- package/dist/plugin/registry.d.mts +1 -3
- package/dist/plugin/registry.mjs +1 -2
- package/dist/plugin/rule-prose.d.mts +1 -3
- package/dist/plugin/rule-prose.mjs +1 -2
- package/dist/plugin/rule-tier.d.mts +1 -3
- package/dist/plugin/rule-tier.mjs +1 -2
- package/dist/plugin/rules.d.mts +1 -3
- package/dist/plugin/rules.mjs +1 -2
- package/dist/plugin/runner.d.mts +1 -3
- package/dist/plugin/runner.mjs +14 -6
- package/dist/png-decode.d.mts +1 -3
- package/dist/png-decode.mjs +1 -2
- package/dist/png-utils.d.mts +1 -3
- package/dist/png-utils.mjs +1 -2
- package/dist/project-config.d.mts +1 -3
- package/dist/project-config.mjs +1 -2
- package/dist/rect-overlap.d.mts +1 -3
- package/dist/rect-overlap.mjs +1 -2
- package/dist/region-shift.d.mts +1 -2
- package/dist/region-shift.mjs +1 -2
- package/dist/run-ledger.d.mts +1 -3
- package/dist/run-ledger.mjs +1 -2
- package/dist/stable-selector.d.mts +1 -3
- package/dist/stable-selector.mjs +1 -2
- package/dist/terminal-colors.d.mts +1 -3
- package/dist/terminal-colors.mjs +1 -2
- package/dist/text-rows.d.mts +1 -3
- package/dist/text-rows.mjs +1 -2
- package/dist/types.d.mts +1 -3
- package/dist/version.d.mts +1 -3
- package/dist/version.mjs +2 -3
- package/dist/video-decode.d.mts +1 -3
- package/dist/video-decode.mjs +35 -32
- package/dist/video-frames.d.mts +11 -7
- package/dist/video-frames.mjs +23 -12
- package/dist/webp.d.mts +1 -3
- package/dist/webp.mjs +1 -2
- package/package.json +5 -5
package/dist/heatmap.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
2
2
|
import { estimateRegionShift } from "./region-shift.mjs";
|
|
3
3
|
import { edgeOnlyDelta } from "@mizchi/vlmkit-judge/edge-noise.ts";
|
|
4
|
-
|
|
4
|
+
// src/heatmap.ts
|
|
5
5
|
/**
|
|
6
6
|
* Colour written into the heatmap over ignored pixels.
|
|
7
7
|
*
|
|
@@ -594,12 +594,17 @@ async function generateDiffReport(snapshot, opts = {}) {
|
|
|
594
594
|
globalShift = detectGlobalShift(r.resizedBaseline, r.resizedCurrent);
|
|
595
595
|
if (globalShift !== 0) {
|
|
596
596
|
compensated = compensatedDiffCount(r.resizedBaseline.data, r.resizedCurrent.data, r.width, r.height, globalShift, r.threshold);
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
597
|
+
if (compensated >= r.diffPixels) {
|
|
598
|
+
globalShift = 0;
|
|
599
|
+
compensated = r.diffPixels;
|
|
600
|
+
} else {
|
|
601
|
+
const bands = detectBandShifts(r.resizedBaseline, r.resizedCurrent);
|
|
602
|
+
shiftRegions = bands.length > 0 ? bands : [{
|
|
603
|
+
yStart: 0,
|
|
604
|
+
yEnd: r.height,
|
|
605
|
+
shift: globalShift
|
|
606
|
+
}];
|
|
607
|
+
}
|
|
603
608
|
}
|
|
604
609
|
}
|
|
605
610
|
const shiftOnly = regions.length > 0 && regions.every((rg) => rg.regionType === "shift" || rg.regionType === "edge");
|
|
@@ -659,5 +664,4 @@ function detectEmptyContent(data, opts = {}) {
|
|
|
659
664
|
uniqueColors: colorSet.size
|
|
660
665
|
};
|
|
661
666
|
}
|
|
662
|
-
//#endregion
|
|
663
667
|
export { adaptiveRegionCellSize, compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec, regionDelta, sampleRegionColorSample };
|
package/dist/image-resize.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/image-resize.d.ts
|
|
2
1
|
export type ResolutionPreset = "low" | "medium" | "high" | "full";
|
|
3
2
|
export declare const RESOLUTION_PRESETS: Record<ResolutionPreset, {
|
|
4
3
|
maxWidth: number;
|
|
@@ -29,5 +28,4 @@ export declare function resizeBase64Png(base64: string, options?: ResizeOptions)
|
|
|
29
28
|
export declare function getImageDimensions(base64: string): {
|
|
30
29
|
width: number;
|
|
31
30
|
height: number;
|
|
32
|
-
};
|
|
33
|
-
//#endregion
|
|
31
|
+
};
|
package/dist/image-resize.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PNG } from "pngjs";
|
|
2
|
-
|
|
2
|
+
// src/image-resize.ts
|
|
3
3
|
/**
|
|
4
4
|
* Image resize + VLM optimization
|
|
5
5
|
*
|
|
@@ -88,5 +88,4 @@ function resizeBase64Png(base64, options = {}) {
|
|
|
88
88
|
function getImageDimensions(base64) {
|
|
89
89
|
return readPngDimensions(Buffer.from(base64, "base64"));
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
export { RESOLUTION_PRESETS, getImageDimensions, readPngDimensions, resizeBase64Png, resizePngBuffer, resolveResolutionForViewport };
|
package/dist/image-timing.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/image-timing.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* How an animated GIF or APNG plays in a browser: each frame's delay as stored, how many times
|
|
4
3
|
* the animation plays, and the delays a browser actually holds.
|
|
@@ -55,5 +54,4 @@ export declare const browserDelayMs: (storedMs: number) => number;
|
|
|
55
54
|
*/
|
|
56
55
|
export declare function gifCompositingProblem(timing: ImageTiming): string | null;
|
|
57
56
|
/** The timing of an animated GIF or APNG, or null for anything else (a still PNG, a video). */
|
|
58
|
-
export declare function imageTiming(bytes: Uint8Array): ImageTiming | null;
|
|
59
|
-
//#endregion
|
|
57
|
+
export declare function imageTiming(bytes: Uint8Array): ImageTiming | null;
|
package/dist/image-timing.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/image-timing.ts
|
|
2
2
|
/** What Chromium holds a frame for: 10ms or less is 100ms. */
|
|
3
3
|
const browserDelayMs = (storedMs) => storedMs <= 10 ? 100 : storedMs;
|
|
4
4
|
const ascii = (bytes, at, length) => String.fromCharCode(...bytes.subarray(at, at + length));
|
|
@@ -163,5 +163,4 @@ function imageTiming(bytes) {
|
|
|
163
163
|
if (bytes.length >= 8 && bytes[0] === 137 && ascii(bytes, 1, 3) === "PNG") return apngTiming(bytes);
|
|
164
164
|
return null;
|
|
165
165
|
}
|
|
166
|
-
//#endregion
|
|
167
166
|
export { browserDelayMs, gifCompositingProblem, imageTiming };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffIgnoreRegion, DiffIgnoredRegionReport, DiffMaskSummary, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionKind, 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, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
|
|
3
|
-
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
4
|
-
import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
|
|
5
|
-
import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
|
|
6
|
-
import { diffComputedStyles } from "./computed-style-diff.mjs";
|
|
7
|
-
import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
|
|
8
|
-
import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
|
|
9
|
-
import { verifyDomEquivalence } from "./dom-equivalence.mjs";
|
|
10
|
-
import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
|
|
11
|
-
import { FilmstripLayout, FilmstripOptions, composeFilmstrip, filmstripLayout } from "./filmstrip.mjs";
|
|
12
|
-
import { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.mjs";
|
|
13
2
|
import { compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec } from "./heatmap.mjs";
|
|
14
|
-
import {
|
|
3
|
+
import { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.mjs";
|
|
4
|
+
import { FilmstripLayout, FilmstripOptions, composeFilmstrip, filmstripLayout } from "./filmstrip.mjs";
|
|
15
5
|
import { WebpEncodeOptions, encodeWebp, imageFormatForPath, webpEncoderAvailable } from "./webp.mjs";
|
|
6
|
+
import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
|
|
16
7
|
import { compareRowTypography, computeRowGapDeltas, extractTextRowsFromFile, extractTextRowsFromRgba, matchTextRows } from "./text-rows.mjs";
|
|
8
|
+
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
9
|
+
import { RESOLUTION_PRESETS, getImageDimensions, resizePngBuffer, resolveResolutionForViewport } from "./image-resize.mjs";
|
|
10
|
+
import { verifyDomEquivalence } from "./dom-equivalence.mjs";
|
|
11
|
+
import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
|
|
12
|
+
import { diffComputedStyles } from "./computed-style-diff.mjs";
|
|
13
|
+
import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
|
|
14
|
+
import { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
|
|
15
|
+
import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
|
|
16
|
+
import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
|
|
17
17
|
export { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AUTHORED_PROPERTIES, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffIgnoreRegion, DiffIgnoredRegionReport, DiffMaskSummary, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionKind, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, type FilmstripLayout, type FilmstripOptions, 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, type WebpEncodeOptions, aggregateAuthoredStyleByViewport, compareRowTypography, compareScreenshots, composeFilmstrip, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, encodeWebp, extractTextRowsFromFile, extractTextRowsFromRgba, filmstripLayout, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, imageFormatForPath, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parseIgnoreRegionSpec, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence, webpEncoderAvailable };
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
|
|
2
|
-
import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
|
|
3
|
-
import { diffComputedStyles } from "./computed-style-diff.mjs";
|
|
4
|
-
import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
|
|
5
|
-
import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
|
|
6
|
-
import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
|
|
7
|
-
import { verifyDomEquivalence } from "./dom-equivalence.mjs";
|
|
8
|
-
import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
|
|
9
|
-
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
10
1
|
import { compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec } from "./heatmap.mjs";
|
|
11
|
-
import { composeFilmstrip, filmstripLayout } from "./filmstrip.mjs";
|
|
12
2
|
import { findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba } from "./heatmap-regions.mjs";
|
|
13
|
-
import {
|
|
3
|
+
import { composeFilmstrip, filmstripLayout } from "./filmstrip.mjs";
|
|
14
4
|
import { encodeWebp, imageFormatForPath, webpEncoderAvailable } from "./webp.mjs";
|
|
5
|
+
import { createScopedVrtDiff, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions } from "./diff-regions.mjs";
|
|
15
6
|
import { compareRowTypography, computeRowGapDeltas, extractTextRowsFromFile, extractTextRowsFromRgba, matchTextRows } from "./text-rows.mjs";
|
|
7
|
+
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
8
|
+
import { RESOLUTION_PRESETS, getImageDimensions, resizePngBuffer, resolveResolutionForViewport } from "./image-resize.mjs";
|
|
9
|
+
import { verifyDomEquivalence } from "./dom-equivalence.mjs";
|
|
10
|
+
import { diffDomPositionStyles, diffPositionStylesAcrossViewports } from "./dom-position-styles.mjs";
|
|
11
|
+
import { diffComputedStyles } from "./computed-style-diff.mjs";
|
|
12
|
+
import { aggregateAuthoredStyleByViewport, diffAuthoredStyles } from "./authored-style-diff.mjs";
|
|
13
|
+
import { INTERACTIVE_ROLES, LANDMARK_ROLES, diffA11yTrees, parsePlaywrightA11ySnapshot, verifyA11yTree } from "./a11y-semantic.mjs";
|
|
14
|
+
import { TRACKED_PROPERTIES } from "./computed-style-capture.mjs";
|
|
15
|
+
import { AUTHORED_PROPERTIES } from "./authored-style-capture.mjs";
|
|
16
16
|
export { AUTHORED_PROPERTIES, INTERACTIVE_ROLES, LANDMARK_ROLES, RESOLUTION_PRESETS, TRACKED_PROPERTIES, aggregateAuthoredStyleByViewport, compareRowTypography, compareScreenshots, composeFilmstrip, computeRowGapDeltas, createScopedVrtDiff, cropImage, decodePng, detectBandShifts, detectEmptyContent, detectWhiteout, diffA11yTrees, diffAuthoredStyles, diffComputedStyles, diffDomPositionStyles, diffPositionStylesAcrossViewports, encodePng, encodeWebp, extractTextRowsFromFile, extractTextRowsFromRgba, filmstripLayout, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba, generateDiffReport, getImageDimensions, imageFormatForPath, matchTextRows, normalizeVrtDiffRegionPixels, normalizeVrtDiffRegions, parseIgnoreRegionSpec, parsePlaywrightA11ySnapshot, resizePngBuffer, resolveResolutionForViewport, verifyA11yTree, verifyDomEquivalence, webpEncoderAvailable };
|
package/dist/mask.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Page } from "playwright";
|
|
2
|
-
//#region src/mask.d.ts
|
|
3
2
|
/** What `applyMask` could and could not do, for the caller to report. */
|
|
4
3
|
export interface MaskResult {
|
|
5
4
|
/** Selectors that matched at least one element and are now hidden. */
|
|
@@ -76,5 +75,4 @@ export declare function formatMaskProblems(invalid: string[], neverMatched: stri
|
|
|
76
75
|
* --mask ".stars,.carousel"
|
|
77
76
|
* --mask ".stars" --mask ".carousel"
|
|
78
77
|
*/
|
|
79
|
-
export declare function parseMaskSelectors(args: string[]): string[];
|
|
80
|
-
//#endregion
|
|
78
|
+
export declare function parseMaskSelectors(args: string[]): string[];
|
package/dist/mask.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/mask.ts
|
|
2
2
|
/**
|
|
3
3
|
* Inject mask styles into the page.
|
|
4
4
|
* Sets visibility: hidden on target selectors including descendants.
|
|
@@ -110,5 +110,4 @@ function parseMaskSelectors(args) {
|
|
|
110
110
|
}
|
|
111
111
|
return selectors;
|
|
112
112
|
}
|
|
113
|
-
//#endregion
|
|
114
113
|
export { MaskTally, applyMask, formatMaskProblems, parseMaskSelectors };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `{"motion": {...}}` in `vlmkit.gates.json`: what a brief asks of a page's motion, written down
|
|
3
|
+
* per target, and run as `inspect motion` (issue #215).
|
|
4
|
+
*
|
|
5
|
+
* In every motion-authoring round the agents mapped a brief to `--expect-*` flags by hand, each
|
|
6
|
+
* time, and most of the small-model round's friction was that mapping: a flag given once applied
|
|
7
|
+
* to every target, `any` was missing, a per-target list had to be counted. The mapping was then
|
|
8
|
+
* thrown away with the session, so CI could not check it again. Here each target carries its own
|
|
9
|
+
* expectations by name, and the object is compiled to the command line `inspect motion` already
|
|
10
|
+
* takes — the flags stay the one implementation, and `gates list` shows exactly what will run.
|
|
11
|
+
*
|
|
12
|
+
* ```json
|
|
13
|
+
* { "motion": {
|
|
14
|
+
* "actions": [{ "click": ".toggle" }],
|
|
15
|
+
* "targets": [
|
|
16
|
+
* { "selector": ".menu", "origin": "top", "duration": 250, "easing": "ease-out" },
|
|
17
|
+
* { "selector": ".backdrop", "still": true }
|
|
18
|
+
* ],
|
|
19
|
+
* "baseline": ".vlmkit/motion/menu.json" } }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Targets are put in the order the command line measures them: `selector` targets first, then
|
|
23
|
+
* `track` ones. A key it does not know is a config error naming its JSON path, as everywhere in
|
|
24
|
+
* the file: a misspelt expectation that silently checked nothing is the failure this exists to end.
|
|
25
|
+
*
|
|
26
|
+
* Pure: an object in, a command string out.
|
|
27
|
+
*/
|
|
28
|
+
/** One expectation value given as the flag takes it: a number of ms, or a string ("280ms", "+50"). */
|
|
29
|
+
type TimeValue = number | string;
|
|
30
|
+
export interface MotionSpecTarget {
|
|
31
|
+
/** The element that moves (`--selector`). */
|
|
32
|
+
selector?: string;
|
|
33
|
+
/** Or the region it fills in the last frame (`--track x,y,w,h`): a canvas, a recording. */
|
|
34
|
+
track?: string | [number, number, number, number];
|
|
35
|
+
/** Its name in the report and the baseline (`--target`). */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** Its curve, or one per segment (`--expect-easing`). */
|
|
38
|
+
easing?: string | string[];
|
|
39
|
+
/** The point it scales, turns or grows about: a keyword or [x, y] in its own units. */
|
|
40
|
+
origin?: string | [number, number];
|
|
41
|
+
/** When its own animation begins (ms of page time, or "+N" from the last action). */
|
|
42
|
+
start?: TimeValue;
|
|
43
|
+
duration?: TimeValue;
|
|
44
|
+
/** How many runs, or "infinite". */
|
|
45
|
+
iterations?: number | "infinite";
|
|
46
|
+
direction?: string;
|
|
47
|
+
/** Lines its text runs to in every frame. */
|
|
48
|
+
lines?: number;
|
|
49
|
+
/** At rest its left and right edges are this element's (`--expect-span-of`). */
|
|
50
|
+
spanOf?: string;
|
|
51
|
+
/** Its centre must not move (`--still`). A `selector` target only. */
|
|
52
|
+
still?: boolean;
|
|
53
|
+
/** It is meant to leave (`--exit`). A `selector` target only. */
|
|
54
|
+
exit?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export type MotionSpecAction = {
|
|
57
|
+
click: string;
|
|
58
|
+
} | {
|
|
59
|
+
hover: string;
|
|
60
|
+
} | {
|
|
61
|
+
leave: true;
|
|
62
|
+
} | {
|
|
63
|
+
scroll: string | number;
|
|
64
|
+
} | {
|
|
65
|
+
wait: TimeValue;
|
|
66
|
+
};
|
|
67
|
+
export interface MotionSpec {
|
|
68
|
+
targets: MotionSpecTarget[];
|
|
69
|
+
actions?: MotionSpecAction[];
|
|
70
|
+
/** Each target begins this long after the one before (`--expect-stagger`). */
|
|
71
|
+
stagger?: TimeValue;
|
|
72
|
+
/** Every target is meant to leave (`--exits`). */
|
|
73
|
+
exits?: boolean;
|
|
74
|
+
reducedMotion?: boolean;
|
|
75
|
+
/** Every target's angle on screen stays the same (`--expect-upright`). */
|
|
76
|
+
upright?: boolean;
|
|
77
|
+
everyAction?: boolean;
|
|
78
|
+
start?: TimeValue;
|
|
79
|
+
end?: TimeValue;
|
|
80
|
+
/** Instants to shoot, as `--at` takes them ("0..600/50"). */
|
|
81
|
+
at?: string;
|
|
82
|
+
/** "WxH". */
|
|
83
|
+
viewport?: string;
|
|
84
|
+
deviceScale?: number;
|
|
85
|
+
/** Hold the run to an approved one (`--baseline`), relative to the config file. */
|
|
86
|
+
baseline?: string;
|
|
87
|
+
/** Where the frames go (`--frames`). */
|
|
88
|
+
frames?: string;
|
|
89
|
+
}
|
|
90
|
+
/** One argument as `tokenizeCommand` reads it back: quoted when it holds a space or a quote. */
|
|
91
|
+
export declare function quoteArg(value: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Compile a `{"motion": ...}` entry's value to the `inspect motion` command it stands for.
|
|
94
|
+
* `fail(path, message)` reports a config error at a JSON path (and does not return).
|
|
95
|
+
*/
|
|
96
|
+
export declare function motionSpecCommand(raw: unknown, path: string, fail: (path: string, message: string) => never): string;
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// src/motion-spec.ts
|
|
2
|
+
const TARGET_KEYS = /* @__PURE__ */ new Set([
|
|
3
|
+
"selector",
|
|
4
|
+
"track",
|
|
5
|
+
"name",
|
|
6
|
+
"easing",
|
|
7
|
+
"origin",
|
|
8
|
+
"start",
|
|
9
|
+
"duration",
|
|
10
|
+
"iterations",
|
|
11
|
+
"direction",
|
|
12
|
+
"lines",
|
|
13
|
+
"spanOf",
|
|
14
|
+
"still",
|
|
15
|
+
"exit"
|
|
16
|
+
]);
|
|
17
|
+
const SPEC_KEYS = /* @__PURE__ */ new Set([
|
|
18
|
+
"targets",
|
|
19
|
+
"actions",
|
|
20
|
+
"stagger",
|
|
21
|
+
"exits",
|
|
22
|
+
"reducedMotion",
|
|
23
|
+
"upright",
|
|
24
|
+
"everyAction",
|
|
25
|
+
"start",
|
|
26
|
+
"end",
|
|
27
|
+
"at",
|
|
28
|
+
"viewport",
|
|
29
|
+
"deviceScale",
|
|
30
|
+
"baseline",
|
|
31
|
+
"frames"
|
|
32
|
+
]);
|
|
33
|
+
/** One argument as `tokenizeCommand` reads it back: quoted when it holds a space or a quote. */
|
|
34
|
+
function quoteArg(value) {
|
|
35
|
+
if (value !== "" && !/[\s'"]/.test(value)) return value;
|
|
36
|
+
return value.includes("'") ? `"${value}"` : `'${value}'`;
|
|
37
|
+
}
|
|
38
|
+
/** The name `inspect motion` gives a --track target it was not given one for. */
|
|
39
|
+
const defaultTrackName = (track) => {
|
|
40
|
+
const [x, y, w, h] = track.split(",").map((v) => Number(v.trim()));
|
|
41
|
+
return `region ${x},${y} ${w}x${h}`;
|
|
42
|
+
};
|
|
43
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
44
|
+
/**
|
|
45
|
+
* Compile a `{"motion": ...}` entry's value to the `inspect motion` command it stands for.
|
|
46
|
+
* `fail(path, message)` reports a config error at a JSON path (and does not return).
|
|
47
|
+
*/
|
|
48
|
+
function motionSpecCommand(raw, path, fail) {
|
|
49
|
+
if (!isObject(raw)) fail(path, "must be an object: { \"targets\": [...], \"actions\"?: [...], ... }");
|
|
50
|
+
for (const key of Object.keys(raw)) if (!SPEC_KEYS.has(key)) fail(`${path}.${key}`, `is not a motion expectation (known: ${[...SPEC_KEYS].join(", ")})`);
|
|
51
|
+
const str = (v, at) => {
|
|
52
|
+
if (typeof v !== "string" || !v.trim()) fail(at, "must be a non-empty string");
|
|
53
|
+
return v.trim();
|
|
54
|
+
};
|
|
55
|
+
const time = (v, at) => {
|
|
56
|
+
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
|
57
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
58
|
+
fail(at, "must be a number of ms or a time string (\"280ms\", \"1.2s\", \"+50\")");
|
|
59
|
+
};
|
|
60
|
+
const bool = (v, at) => {
|
|
61
|
+
if (typeof v !== "boolean") fail(at, "must be true or false");
|
|
62
|
+
return v;
|
|
63
|
+
};
|
|
64
|
+
if (!Array.isArray(raw.targets) || raw.targets.length === 0) fail(`${path}.targets`, "must be a non-empty array: one entry per element (or region) that moves");
|
|
65
|
+
const parsed = raw.targets.map((t, i) => {
|
|
66
|
+
const at = `${path}.targets[${i}]`;
|
|
67
|
+
if (!isObject(t)) fail(at, "must be an object");
|
|
68
|
+
for (const key of Object.keys(t)) if (!TARGET_KEYS.has(key)) fail(`${at}.${key}`, `is not a target expectation (known: ${[...TARGET_KEYS].join(", ")})`);
|
|
69
|
+
if (t.selector === void 0 === (t.track === void 0)) fail(at, "needs exactly one of selector or track");
|
|
70
|
+
let track;
|
|
71
|
+
if (t.track !== void 0) {
|
|
72
|
+
if (Array.isArray(t.track) && t.track.length === 4 && t.track.every((n) => typeof n === "number" && Number.isFinite(n))) track = t.track.join(",");
|
|
73
|
+
else track = str(t.track, `${at}.track`);
|
|
74
|
+
if (t.still !== void 0 || t.exit !== void 0) fail(at, "still and exit name an element: give this target a selector, or drop them");
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
t,
|
|
78
|
+
at,
|
|
79
|
+
selector: t.selector === void 0 ? void 0 : str(t.selector, `${at}.selector`),
|
|
80
|
+
track
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const ordered = [...parsed.filter((p) => p.selector !== void 0), ...parsed.filter((p) => p.track !== void 0)];
|
|
84
|
+
const out = ["inspect", "motion"];
|
|
85
|
+
const flag = (name, value) => out.push(name, ...value === void 0 ? [] : [quoteArg(value)]);
|
|
86
|
+
if (raw.actions !== void 0 && !Array.isArray(raw.actions)) fail(`${path}.actions`, "must be an array");
|
|
87
|
+
for (const [k, a] of (raw.actions ?? []).entries()) {
|
|
88
|
+
const at = `${path}.actions[${k}]`;
|
|
89
|
+
if (!isObject(a) || Object.keys(a).length !== 1) fail(at, "must be one of { \"click\": css }, { \"hover\": css }, { \"leave\": true }, { \"scroll\": css | px }, { \"wait\": ms }");
|
|
90
|
+
const [kind, v] = Object.entries(a)[0];
|
|
91
|
+
if (kind === "click" || kind === "hover") flag(`--${kind}`, str(v, `${at}.${kind}`));
|
|
92
|
+
else if (kind === "leave") {
|
|
93
|
+
if (v !== true) fail(`${at}.leave`, "must be true");
|
|
94
|
+
flag("--leave");
|
|
95
|
+
} else if (kind === "scroll") flag("--scroll", typeof v === "number" ? String(v) : str(v, `${at}.scroll`));
|
|
96
|
+
else if (kind === "wait") flag("--wait", time(v, `${at}.wait`));
|
|
97
|
+
else fail(`${at}.${kind}`, "is not an action (click, hover, leave, scroll, wait)");
|
|
98
|
+
}
|
|
99
|
+
for (const p of ordered) if (p.selector !== void 0) flag("--selector", p.selector);
|
|
100
|
+
else flag("--track", p.track);
|
|
101
|
+
if (ordered.some((p) => p.t.name !== void 0)) for (const p of ordered) flag("--target", p.t.name !== void 0 ? str(p.t.name, `${p.at}.name`) : p.selector ?? defaultTrackName(p.track));
|
|
102
|
+
const any = (key) => ordered.some((p) => p.t[key] !== void 0);
|
|
103
|
+
if (any("easing")) for (const p of ordered) {
|
|
104
|
+
const v = p.t.easing;
|
|
105
|
+
if (v === void 0) flag("--expect-easing", "any");
|
|
106
|
+
else if (Array.isArray(v)) flag("--expect-easing", v.map((e, j) => str(e, `${p.at}.easing[${j}]`)).join(","));
|
|
107
|
+
else flag("--expect-easing", str(v, `${p.at}.easing`));
|
|
108
|
+
}
|
|
109
|
+
if (any("origin")) for (const p of ordered) {
|
|
110
|
+
const v = p.t.origin;
|
|
111
|
+
if (v === void 0) flag("--expect-origin", "any");
|
|
112
|
+
else if (Array.isArray(v) && v.length === 2 && v.every((n) => typeof n === "number" && Number.isFinite(n))) flag("--expect-origin", v.join(","));
|
|
113
|
+
else flag("--expect-origin", str(v, `${p.at}.origin`));
|
|
114
|
+
}
|
|
115
|
+
if (any("spanOf")) for (const p of ordered) flag("--expect-span-of", p.t.spanOf === void 0 ? "any" : str(p.t.spanOf, `${p.at}.spanOf`));
|
|
116
|
+
const list = (key, name, read) => {
|
|
117
|
+
if (any(key)) flag(name, ordered.map((p) => p.t[key] === void 0 ? "any" : read(p.t[key], `${p.at}.${key}`)).join(","));
|
|
118
|
+
};
|
|
119
|
+
list("start", "--expect-start", time);
|
|
120
|
+
list("duration", "--expect-duration", time);
|
|
121
|
+
list("iterations", "--expect-iterations", (v, at) => v === "infinite" ? "infinite" : typeof v === "number" && Number.isInteger(v) && v > 0 ? String(v) : fail(at, "must be a whole number of runs, or \"infinite\""));
|
|
122
|
+
list("direction", "--expect-direction", str);
|
|
123
|
+
list("lines", "--expect-lines", (v, at) => typeof v === "number" && Number.isInteger(v) && v > 0 ? String(v) : fail(at, "must be a whole number of lines"));
|
|
124
|
+
for (const p of ordered) {
|
|
125
|
+
if (p.t.still !== void 0 && bool(p.t.still, `${p.at}.still`)) flag("--still", p.selector);
|
|
126
|
+
if (p.t.exit !== void 0 && bool(p.t.exit, `${p.at}.exit`)) flag("--exit", p.selector);
|
|
127
|
+
}
|
|
128
|
+
if (raw.stagger !== void 0) flag("--expect-stagger", time(raw.stagger, `${path}.stagger`));
|
|
129
|
+
if (raw.exits !== void 0 && bool(raw.exits, `${path}.exits`)) flag("--exits");
|
|
130
|
+
if (raw.reducedMotion !== void 0 && bool(raw.reducedMotion, `${path}.reducedMotion`)) flag("--reduced-motion");
|
|
131
|
+
if (raw.upright !== void 0 && bool(raw.upright, `${path}.upright`)) flag("--expect-upright");
|
|
132
|
+
if (raw.everyAction !== void 0 && bool(raw.everyAction, `${path}.everyAction`)) flag("--every-action");
|
|
133
|
+
if (raw.start !== void 0) flag("--start", time(raw.start, `${path}.start`));
|
|
134
|
+
if (raw.end !== void 0) flag("--end", time(raw.end, `${path}.end`));
|
|
135
|
+
if (raw.at !== void 0) flag("--at", str(raw.at, `${path}.at`));
|
|
136
|
+
if (raw.viewport !== void 0) flag("--viewport", str(raw.viewport, `${path}.viewport`));
|
|
137
|
+
if (raw.deviceScale !== void 0) {
|
|
138
|
+
if (typeof raw.deviceScale !== "number" || !(raw.deviceScale > 0)) fail(`${path}.deviceScale`, "must be a positive number");
|
|
139
|
+
flag("--device-scale", String(raw.deviceScale));
|
|
140
|
+
}
|
|
141
|
+
if (raw.baseline !== void 0) flag("--baseline", str(raw.baseline, `${path}.baseline`));
|
|
142
|
+
if (raw.frames !== void 0) flag("--frames", str(raw.frames, `${path}.frames`));
|
|
143
|
+
return out.join(" ");
|
|
144
|
+
}
|
|
145
|
+
export { motionSpecCommand, quoteArg };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/navigation-redirect.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Redirect disclosure for gates that navigate.
|
|
4
3
|
*
|
|
@@ -23,5 +22,4 @@
|
|
|
23
22
|
* than the one requested, or `null` when the navigation landed where the
|
|
24
23
|
* caller intended (or when either URL is unparseable / not http(s)).
|
|
25
24
|
*/
|
|
26
|
-
export declare function describeRedirect(requested: string, final: string): string | null;
|
|
27
|
-
//#endregion
|
|
25
|
+
export declare function describeRedirect(requested: string, final: string): string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/navigation-redirect.ts
|
|
2
2
|
/**
|
|
3
3
|
* Redirect disclosure for gates that navigate.
|
|
4
4
|
*
|
|
@@ -43,5 +43,4 @@ function describeRedirect(requested, final) {
|
|
|
43
43
|
const hint = /login|signin|sign-in|auth|sso|account\/login/i.test(b.pathname) ? " This looks like a login wall: the gate measured the sign-in page, NOT the page you asked about. Pass a logged-in Playwright storage state (--storage-state <file>, or VLMKIT_STORAGE_STATE), or point the gate at a route that does not need auth." : " The gate measured the destination, not the URL you passed.";
|
|
44
44
|
return `redirected: requested ${a.pathname}${a.search} but measured ${b.href}.${hint}`;
|
|
45
45
|
}
|
|
46
|
-
//#endregion
|
|
47
46
|
export { describeRedirect };
|
package/dist/page-load.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GateInput } from "./plugin/contract.mjs";
|
|
2
2
|
import { applyHar } from "./page-open.mjs";
|
|
3
3
|
import { Page } from "playwright";
|
|
4
|
-
//#region src/page-load.d.ts
|
|
5
4
|
/** The navigation milestones a gate exposes. Playwright's `commit` is not one of
|
|
6
5
|
* them: no gate can read a document that has not parsed. */
|
|
7
6
|
export declare const PAGE_LOAD_WAIT_UNTIL: readonly ["domcontentloaded", "load", "networkidle"];
|
|
@@ -23,21 +22,48 @@ export interface PageLoadOptions {
|
|
|
23
22
|
timeout?: number;
|
|
24
23
|
/** Replay network responses from a Playwright HAR. See `applyHar`. */
|
|
25
24
|
har?: string;
|
|
25
|
+
/**
|
|
26
|
+
* `prefers-color-scheme` to emulate. Not one of the three load knobs: it is declared by
|
|
27
|
+
* `COLOR_SCHEME_INPUT`, only on gates that honour it, and carried here so `pickPageLoad`
|
|
28
|
+
* hands it to `openSource` with the rest.
|
|
29
|
+
*/
|
|
30
|
+
colorScheme?: ColorScheme;
|
|
26
31
|
}
|
|
32
|
+
/** The schemes a gate can be asked to judge a page in. */
|
|
33
|
+
export declare const COLOR_SCHEMES: readonly ["light", "dark"];
|
|
34
|
+
export type ColorScheme = (typeof COLOR_SCHEMES)[number];
|
|
27
35
|
/**
|
|
28
36
|
* `inputs` fragment. Spread at the END of a gate's `inputs` array so the
|
|
29
37
|
* gate-specific flags stay first in `--help`.
|
|
30
38
|
*/
|
|
31
39
|
export declare const PAGE_LOAD_INPUTS: readonly GateInput[];
|
|
40
|
+
/**
|
|
41
|
+
* `--color-scheme light|dark`, for a gate whose judgement reads paint (contrast, invisible
|
|
42
|
+
* text, palette). Kept apart from `PAGE_LOAD_INPUTS` on purpose: a gate that declares it must
|
|
43
|
+
* honour it (`applyColorScheme` before its navigation, or `pickPageLoad` into `openSource`),
|
|
44
|
+
* and most load-honouring gates have no reason to.
|
|
45
|
+
*
|
|
46
|
+
* Why it exists: no paint-reading gate emulated `prefers-color-scheme`, so a page that follows
|
|
47
|
+
* the OS theme had its dark theme judged by eye only (the demo sites took `?theme=dark` instead).
|
|
48
|
+
*/
|
|
49
|
+
export declare const COLOR_SCHEME_INPUT: GateInput;
|
|
50
|
+
/** Read `--color-scheme`; absent gives an absent key. */
|
|
51
|
+
export declare function parseColorScheme(argv: readonly string[]): {
|
|
52
|
+
colorScheme?: ColorScheme;
|
|
53
|
+
};
|
|
54
|
+
/** Emulate the scheme on a page before it navigates, so its first style already matches. */
|
|
55
|
+
export declare function applyColorScheme(page: Page, colorScheme: ColorScheme | undefined): Promise<void>;
|
|
32
56
|
/** The flag spellings, for `readPositionals` value-flag lists. */
|
|
33
57
|
export declare const PAGE_LOAD_VALUE_FLAGS: readonly string[];
|
|
58
|
+
/** `--color-scheme`'s spelling, for the value-flag lists of the gates that declare it. */
|
|
59
|
+
export declare const COLOR_SCHEME_VALUE_FLAGS: readonly string[];
|
|
34
60
|
/**
|
|
35
61
|
* Read the three flags off argv. Absent flags produce absent keys, so spreading
|
|
36
62
|
* the result never overwrites a gate's own default with `undefined`.
|
|
37
63
|
*/
|
|
38
64
|
export declare function parsePageLoad(argv: readonly string[]): PageLoadOptions;
|
|
39
65
|
/**
|
|
40
|
-
* Narrow a wider options object down to
|
|
66
|
+
* Narrow a wider options object down to these three keys, plus `colorScheme` when set.
|
|
41
67
|
*
|
|
42
68
|
* For measurement modules that load through `openSource`: spreading the whole
|
|
43
69
|
* gate options object into it would also hand over `outputDir`, `reportPath` and
|
|
@@ -78,5 +104,4 @@ export declare function navigationOptions(options?: PageLoadOptions, defaultWait
|
|
|
78
104
|
* settle is not done twice.
|
|
79
105
|
*/
|
|
80
106
|
export declare function navigatePage(page: Page, url: string, options?: PageLoadOptions): Promise<void>;
|
|
81
|
-
//#endregion
|
|
82
107
|
export { applyHar };
|
package/dist/page-load.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readChoice, readFlag, readInt } from "./arg-reader.mjs";
|
|
2
2
|
import { applyHar, settlePage } from "./page-open.mjs";
|
|
3
|
-
|
|
3
|
+
// src/page-load.ts
|
|
4
4
|
/** The navigation milestones a gate exposes. Playwright's `commit` is not one of
|
|
5
5
|
* them: no gate can read a document that has not parsed. */
|
|
6
6
|
const PAGE_LOAD_WAIT_UNTIL = [
|
|
@@ -12,6 +12,8 @@ const PAGE_LOAD_WAIT_UNTIL = [
|
|
|
12
12
|
const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 3e4;
|
|
13
13
|
/** The default milestone every gate has always used. */
|
|
14
14
|
const DEFAULT_PAGE_LOAD_WAIT_UNTIL = "networkidle";
|
|
15
|
+
/** The schemes a gate can be asked to judge a page in. */
|
|
16
|
+
const COLOR_SCHEMES = ["light", "dark"];
|
|
15
17
|
/**
|
|
16
18
|
* `inputs` fragment. Spread at the END of a gate's `inputs` array so the
|
|
17
19
|
* gate-specific flags stay first in `--help`.
|
|
@@ -38,12 +40,39 @@ const PAGE_LOAD_INPUTS = [
|
|
|
38
40
|
description: "Replay network responses from a Playwright HAR (requests absent from it are aborted)"
|
|
39
41
|
}
|
|
40
42
|
];
|
|
43
|
+
/**
|
|
44
|
+
* `--color-scheme light|dark`, for a gate whose judgement reads paint (contrast, invisible
|
|
45
|
+
* text, palette). Kept apart from `PAGE_LOAD_INPUTS` on purpose: a gate that declares it must
|
|
46
|
+
* honour it (`applyColorScheme` before its navigation, or `pickPageLoad` into `openSource`),
|
|
47
|
+
* and most load-honouring gates have no reason to.
|
|
48
|
+
*
|
|
49
|
+
* Why it exists: no paint-reading gate emulated `prefers-color-scheme`, so a page that follows
|
|
50
|
+
* the OS theme had its dark theme judged by eye only (the demo sites took `?theme=dark` instead).
|
|
51
|
+
*/
|
|
52
|
+
const COLOR_SCHEME_INPUT = {
|
|
53
|
+
name: "color-scheme",
|
|
54
|
+
kind: "string",
|
|
55
|
+
description: "Emulate prefers-color-scheme while judging (a page that follows the OS theme)",
|
|
56
|
+
choices: COLOR_SCHEMES,
|
|
57
|
+
defaultDescription: "light"
|
|
58
|
+
};
|
|
59
|
+
/** Read `--color-scheme`; absent gives an absent key. */
|
|
60
|
+
function parseColorScheme(argv) {
|
|
61
|
+
const colorScheme = readChoice(argv, "color-scheme", COLOR_SCHEMES);
|
|
62
|
+
return colorScheme ? { colorScheme } : {};
|
|
63
|
+
}
|
|
64
|
+
/** Emulate the scheme on a page before it navigates, so its first style already matches. */
|
|
65
|
+
async function applyColorScheme(page, colorScheme) {
|
|
66
|
+
if (colorScheme) await page.emulateMedia({ colorScheme });
|
|
67
|
+
}
|
|
41
68
|
/** The flag spellings, for `readPositionals` value-flag lists. */
|
|
42
69
|
const PAGE_LOAD_VALUE_FLAGS = [
|
|
43
70
|
"--timeout",
|
|
44
71
|
"--wait-until",
|
|
45
72
|
"--har"
|
|
46
73
|
];
|
|
74
|
+
/** `--color-scheme`'s spelling, for the value-flag lists of the gates that declare it. */
|
|
75
|
+
const COLOR_SCHEME_VALUE_FLAGS = ["--color-scheme"];
|
|
47
76
|
/**
|
|
48
77
|
* Read the three flags off argv. Absent flags produce absent keys, so spreading
|
|
49
78
|
* the result never overwrites a gate's own default with `undefined`.
|
|
@@ -59,7 +88,7 @@ function parsePageLoad(argv) {
|
|
|
59
88
|
};
|
|
60
89
|
}
|
|
61
90
|
/**
|
|
62
|
-
* Narrow a wider options object down to
|
|
91
|
+
* Narrow a wider options object down to these three keys, plus `colorScheme` when set.
|
|
63
92
|
*
|
|
64
93
|
* For measurement modules that load through `openSource`: spreading the whole
|
|
65
94
|
* gate options object into it would also hand over `outputDir`, `reportPath` and
|
|
@@ -70,7 +99,8 @@ function pickPageLoad(options) {
|
|
|
70
99
|
return {
|
|
71
100
|
...options.waitUntil ? { waitUntil: options.waitUntil } : {},
|
|
72
101
|
...options.timeout !== void 0 ? { timeout: options.timeout } : {},
|
|
73
|
-
...options.har ? { har: options.har } : {}
|
|
102
|
+
...options.har ? { har: options.har } : {},
|
|
103
|
+
...options.colorScheme ? { colorScheme: options.colorScheme } : {}
|
|
74
104
|
};
|
|
75
105
|
}
|
|
76
106
|
/**
|
|
@@ -112,5 +142,4 @@ async function navigatePage(page, url, options = {}) {
|
|
|
112
142
|
await page.goto(url, navigationOptions(options));
|
|
113
143
|
if (options.waitUntil && options.waitUntil !== "networkidle") await settlePage(page, 0);
|
|
114
144
|
}
|
|
115
|
-
|
|
116
|
-
export { DEFAULT_PAGE_LOAD_TIMEOUT_MS, DEFAULT_PAGE_LOAD_WAIT_UNTIL, PAGE_LOAD_INPUTS, PAGE_LOAD_VALUE_FLAGS, PAGE_LOAD_WAIT_UNTIL, applyHar, navigatePage, navigationOptions, parsePageLoad, pickPageLoad };
|
|
145
|
+
export { COLOR_SCHEMES, COLOR_SCHEME_INPUT, COLOR_SCHEME_VALUE_FLAGS, DEFAULT_PAGE_LOAD_TIMEOUT_MS, DEFAULT_PAGE_LOAD_WAIT_UNTIL, PAGE_LOAD_INPUTS, PAGE_LOAD_VALUE_FLAGS, PAGE_LOAD_WAIT_UNTIL, applyColorScheme, applyHar, navigatePage, navigationOptions, parseColorScheme, parsePageLoad, pickPageLoad };
|
package/dist/page-open.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Browser, Page, ViewportSize } from "playwright";
|
|
2
|
-
//#region src/page-open.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Is this source already a URL, or is it a path that has to become one?
|
|
5
4
|
*
|
|
@@ -160,6 +159,10 @@ export interface HarReplay {
|
|
|
160
159
|
export interface OpenPageOptions {
|
|
161
160
|
viewport?: ViewportSize;
|
|
162
161
|
deviceScaleFactor?: number;
|
|
162
|
+
/** A phone: the viewport meta is honoured and `pointer: coarse` matches (`check mobile`). */
|
|
163
|
+
isMobile?: boolean;
|
|
164
|
+
/** Touch events are on (`check mobile` swipes with them). */
|
|
165
|
+
hasTouch?: boolean;
|
|
163
166
|
/** `prefers-color-scheme` for the page's context (theme-parity opens both). */
|
|
164
167
|
colorScheme?: "light" | "dark" | "no-preference";
|
|
165
168
|
/** Playwright storage state for pages behind a login. */
|
|
@@ -228,5 +231,4 @@ export interface OpenHtmlOptions extends OpenPageOptions {
|
|
|
228
231
|
* the document a real base URL, and `setContent` replaces the markup without
|
|
229
232
|
* discarding it.
|
|
230
233
|
*/
|
|
231
|
-
export declare function openHtml(browser: Browser, html: string, options?: OpenHtmlOptions): Promise<Page>;
|
|
232
|
-
//#endregion
|
|
234
|
+
export declare function openHtml(browser: Browser, html: string, options?: OpenHtmlOptions): Promise<Page>;
|
package/dist/page-open.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { describeRedirect } from "./navigation-redirect.mjs";
|
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
|
|
6
|
+
// src/page-open.ts
|
|
7
7
|
/**
|
|
8
8
|
* One way to open the page under test.
|
|
9
9
|
*
|
|
@@ -266,7 +266,9 @@ function pageOptions(options) {
|
|
|
266
266
|
return withAuthState({
|
|
267
267
|
...options.viewport ? { viewport: options.viewport } : {},
|
|
268
268
|
...options.deviceScaleFactor !== void 0 ? { deviceScaleFactor: options.deviceScaleFactor } : {},
|
|
269
|
-
...options.colorScheme ? { colorScheme: options.colorScheme } : {}
|
|
269
|
+
...options.colorScheme ? { colorScheme: options.colorScheme } : {},
|
|
270
|
+
...options.isMobile ? { isMobile: true } : {},
|
|
271
|
+
...options.hasTouch ? { hasTouch: true } : {}
|
|
270
272
|
}, options.storageState);
|
|
271
273
|
}
|
|
272
274
|
/**
|
|
@@ -317,5 +319,4 @@ async function openHtml(browser, html, options = {}) {
|
|
|
317
319
|
if (!options.skipSettle) await settlePage(page, options.settleMs ?? 250, options.animationCapMs);
|
|
318
320
|
return page;
|
|
319
321
|
}
|
|
320
|
-
//#endregion
|
|
321
322
|
export { applyHar, isUrlSource, openHtml, openSource, resolveSource, settlePage, sourceToUrl };
|