@bridge-ds/visual 0.0.0-stage → 0.2.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.
@@ -0,0 +1,40 @@
1
+ import { type Browser, type BrowserContext, type Page } from 'playwright-core';
2
+ import type { Viewport } from './types.js';
3
+ export declare const FROZEN_TIME = "2026-01-15T10:00:00.000Z";
4
+ export interface LaunchOptions {
5
+ /** Path to a Chrome or Chromium binary; otherwise the installed Chrome (channel "chrome"). */
6
+ executablePath?: string;
7
+ channel?: string;
8
+ }
9
+ export declare function launch(o?: LaunchOptions): Promise<Browser>;
10
+ export declare function newContext(browser: Browser, viewport: Viewport): Promise<BrowserContext>;
11
+ export declare function newPage(ctx: BrowserContext): Promise<Page>;
12
+ /** Waits for fonts, images, two frames, and a DOM whose markup stops changing (bounded). */
13
+ export declare function settle(page: Page, o?: {
14
+ timeout?: number;
15
+ network?: boolean;
16
+ quiet?: number;
17
+ interval?: number;
18
+ busy?: boolean;
19
+ }): Promise<void>;
20
+ export interface ShotRequest {
21
+ url: string;
22
+ /** Replaces page.goto(url): e.g. switching stories inside an already loaded Storybook. */
23
+ navigate?: (page: Page) => Promise<void>;
24
+ /** Settle options; app screens wait for the network, story switches do not. */
25
+ settle?: Parameters<typeof settle>[1];
26
+ file: string;
27
+ fullPage: boolean;
28
+ waitFor?: string;
29
+ ready?: string;
30
+ /** JS expression polled until truthy before settling (story rendered, app mounted). */
31
+ readyFn?: string;
32
+ mask?: string[];
33
+ }
34
+ /** Navigates, settles and writes a PNG. Returns an error message instead of throwing. */
35
+ export declare function shoot(page: Page, r: ShotRequest): Promise<string | null>;
36
+ /**
37
+ * Shows a story in an already loaded Storybook preview through its channel (what the manager does when you
38
+ * click a story), much faster than a page load per story. Resolves once the story rendered or failed.
39
+ */
40
+ export declare function switchStory(page: Page, storyId: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ import type { Page } from 'playwright-core';
2
+ import type { Box } from './types.js';
3
+ export interface CompositeInput {
4
+ title: string;
5
+ subtitle: string;
6
+ before: string | null;
7
+ after: string | null;
8
+ diff: string | null;
9
+ width: number;
10
+ height: number;
11
+ boxes: Box[];
12
+ out: string;
13
+ /** Column width in CSS px; images wider than this are scaled down. */
14
+ column?: number;
15
+ }
16
+ export declare function composite(page: Page, c: CompositeInput): Promise<void>;
package/dist/diff.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { PNG } from 'pngjs';
2
+ import type { Box } from './types.js';
3
+ export interface DiffResult {
4
+ changedPixels: number;
5
+ totalPixels: number;
6
+ percent: number;
7
+ boxes: Box[];
8
+ /** Diff image: the after image faded, changed pixels in red. Null when nothing changed. */
9
+ diff: PNG | null;
10
+ width: number;
11
+ height: number;
12
+ }
13
+ export declare const decodePng: (buf: Buffer) => PNG;
14
+ export declare const encodePng: (png: PNG) => Buffer;
15
+ /** Copies `src` onto a `width` x `height` canvas filled with an opaque neutral, so sizes can differ. */
16
+ export declare function padTo(src: PNG, width: number, height: number): PNG;
17
+ /**
18
+ * Compares two screenshots. `threshold` is pixelmatch's per-pixel color distance (0..1, 0.03 by default: low enough to catch one step of a color ramp);
19
+ * anti-aliasing differences are ignored. Area that exists in only one image (a taller story) counts as changed.
20
+ */
21
+ export declare function diffPngs(before: PNG, after: PNG, threshold?: number, cell?: number): DiffResult;
22
+ /**
23
+ * Bounding boxes of changed regions: the diff mask is bucketed into `cell` px cells, neighbouring cells
24
+ * (8-connected, one empty cell of slack) are merged, and each group gives one box. At most `max` boxes;
25
+ * beyond that the smallest are merged into their nearest neighbour.
26
+ */
27
+ export declare function boxesFromDiff(diff: PNG, cell?: number, max?: number): Box[];
28
+ export declare function boxesFromCells(hot: Uint8Array, cols: number, rows: number, cell: number, width: number, height: number, max?: number): Box[];
@@ -0,0 +1,7 @@
1
+ export { runImpact, planImpact, changedTokens, type ImpactOptions, type ImpactResult, type Plan } from './run.js';
2
+ export { selectImpact, storiesFromSource, storyId, storyComponent, type SelectInput } from './select.js';
3
+ export { diffPngs, boxesFromDiff, boxesFromCells, padTo, decodePng, encodePng, type DiffResult } from './diff.js';
4
+ export { COMMENT_MARKER, hasVisualChange, rankShots, renderComment, summarize, summaryLine, type CommentOptions } from './manifest.js';
5
+ export { DEFAULT_ROUTES, DEFAULT_TENANTS, routeUrl, storyUrl, shotKey } from './routes.js';
6
+ export { linkNodeModules } from './workspace.js';
7
+ export type * from './types.js';