@mizchi/vlmkit-capture 0.8.0 → 0.8.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.
Files changed (39) hide show
  1. package/dist/batch-prescan.d.mts +51 -0
  2. package/dist/batch-prescan.mjs +66 -0
  3. package/dist/capture-config.d.mts +50 -0
  4. package/dist/capture-config.mjs +164 -0
  5. package/dist/capturer.d.mts +45 -0
  6. package/dist/capturer.mjs +94 -0
  7. package/dist/cloudflare-quick-actions.d.mts +114 -0
  8. package/dist/cloudflare-quick-actions.mjs +142 -0
  9. package/dist/crater-client.d.mts +159 -0
  10. package/dist/crater-client.mjs +362 -0
  11. package/dist/crater-smoke.d.mts +98 -0
  12. package/dist/crater-smoke.mjs +269 -0
  13. package/dist/crater-wasm.d.mts +65 -0
  14. package/dist/crater-wasm.mjs +132 -0
  15. package/{src/detection-types.ts → dist/detection-types.d.mts} +4 -2
  16. package/dist/detection-types.mjs +1 -0
  17. package/dist/index.d.mts +12 -0
  18. package/dist/index.mjs +11 -0
  19. package/dist/playwright-analyzer.d.mts +38 -0
  20. package/dist/playwright-analyzer.mjs +117 -0
  21. package/dist/playwright-launch-error.d.mts +7 -0
  22. package/dist/playwright-launch-error.mjs +25 -0
  23. package/dist/prescanner.d.mts +39 -0
  24. package/dist/prescanner.mjs +61 -0
  25. package/dist/viewport-discovery.d.mts +114 -0
  26. package/dist/viewport-discovery.mjs +294 -0
  27. package/package.json +18 -6
  28. package/src/batch-prescan.ts +0 -115
  29. package/src/capture-config.ts +0 -219
  30. package/src/capturer.ts +0 -138
  31. package/src/cloudflare-quick-actions.ts +0 -304
  32. package/src/crater-client.ts +0 -537
  33. package/src/crater-smoke.ts +0 -336
  34. package/src/crater-wasm.ts +0 -260
  35. package/src/index.ts +0 -157
  36. package/src/playwright-analyzer.ts +0 -180
  37. package/src/playwright-launch-error.ts +0 -41
  38. package/src/prescanner.ts +0 -123
  39. package/src/viewport-discovery.ts +0 -455
@@ -0,0 +1,51 @@
1
+ import { CraterClient, CraterCssMutation, PaintNode, PaintTreeChange } from "./crater-client.mjs";
2
+
3
+ //#region src/batch-prescan.d.ts
4
+ interface BatchPrescanRequest {
5
+ /** Stable id (echoed back in the result). */
6
+ id: string;
7
+ /** CSS mutations describing how this variant diverges from the baseline. */
8
+ mutations: CraterCssMutation[];
9
+ }
10
+ interface BatchPrescanResult {
11
+ id: string;
12
+ /** Paint-tree changes vs. the baseline tree. Empty when the variant looks identical. */
13
+ changes: PaintTreeChange[];
14
+ /** The variant's paint tree, when Crater returned one (kept for downstream inspection). */
15
+ paintTree?: PaintNode | null;
16
+ /** True when Crater silently dropped the variant (no `paintTree` in the response). */
17
+ missing: boolean;
18
+ }
19
+ interface BatchPrescanOptions {
20
+ /** Skip variants whose `mutations` array is empty — Crater would no-op them anyway. */
21
+ skipEmptyMutations?: boolean;
22
+ }
23
+ /**
24
+ * Drive `batchRender` and return per-variant paint-tree diffs against a
25
+ * caller-supplied baseline tree. The baseline tree must come from a render
26
+ * of the unmodified `baseHtml` at the same viewport.
27
+ *
28
+ * The caller is responsible for collecting `baselinePaintTree` (e.g. via
29
+ * the existing `capturePageStateCrater` flow at the same viewport).
30
+ */
31
+ declare function runBatchPrescan(client: Pick<CraterClient, "batchRender">, baseHtml: string, viewport: {
32
+ width: number;
33
+ height: number;
34
+ }, baselinePaintTree: PaintNode, requests: BatchPrescanRequest[], options?: BatchPrescanOptions): Promise<BatchPrescanResult[]>;
35
+ /**
36
+ * Build a Crater `mutations` payload for "remove a single CSS declaration"
37
+ * — the css-challenge property-mode trial shape.
38
+ */
39
+ declare function mutationsForPropertyRemoval(selector: string, property: string): CraterCssMutation[];
40
+ /**
41
+ * Build a Crater `mutations` payload for "remove every declaration in a
42
+ * selector block" — the css-challenge selector-mode trial shape.
43
+ */
44
+ declare function mutationsForSelectorBlockRemoval(selector: string, properties: string[]): CraterCssMutation[];
45
+ /**
46
+ * True when at least one of the batch-prescan results found a paint-tree
47
+ * signal. Used to short-circuit follow-up per-viewport captures.
48
+ */
49
+ declare function hasAnyBatchPrescanSignal(results: BatchPrescanResult[]): boolean;
50
+ //#endregion
51
+ export { BatchPrescanOptions, BatchPrescanRequest, BatchPrescanResult, hasAnyBatchPrescanSignal, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, runBatchPrescan };
@@ -0,0 +1,66 @@
1
+ import { diffPaintTrees } from "./crater-client.mjs";
2
+ //#region src/batch-prescan.ts
3
+ /**
4
+ * Drive `batchRender` and return per-variant paint-tree diffs against a
5
+ * caller-supplied baseline tree. The baseline tree must come from a render
6
+ * of the unmodified `baseHtml` at the same viewport.
7
+ *
8
+ * The caller is responsible for collecting `baselinePaintTree` (e.g. via
9
+ * the existing `capturePageStateCrater` flow at the same viewport).
10
+ */
11
+ async function runBatchPrescan(client, baseHtml, viewport, baselinePaintTree, requests, options = {}) {
12
+ const callable = options.skipEmptyMutations ?? true ? requests.filter((req) => req.mutations.length > 0) : requests;
13
+ if (callable.length === 0) return [];
14
+ const batch = await client.batchRender(baseHtml, viewport, callable.map((req) => ({
15
+ id: req.id,
16
+ mutations: req.mutations
17
+ })));
18
+ const byId = /* @__PURE__ */ new Map();
19
+ for (const entry of batch.results ?? []) byId.set(entry.id, entry.paintTree ?? null);
20
+ return callable.map((req) => {
21
+ const tree = byId.get(req.id);
22
+ if (tree === void 0 || tree === null) return {
23
+ id: req.id,
24
+ changes: [],
25
+ missing: true
26
+ };
27
+ const changes = diffPaintTrees(baselinePaintTree, tree);
28
+ return {
29
+ id: req.id,
30
+ changes,
31
+ paintTree: tree,
32
+ missing: false
33
+ };
34
+ });
35
+ }
36
+ /**
37
+ * Build a Crater `mutations` payload for "remove a single CSS declaration"
38
+ * — the css-challenge property-mode trial shape.
39
+ */
40
+ function mutationsForPropertyRemoval(selector, property) {
41
+ return [{
42
+ selector,
43
+ property,
44
+ action: "remove"
45
+ }];
46
+ }
47
+ /**
48
+ * Build a Crater `mutations` payload for "remove every declaration in a
49
+ * selector block" — the css-challenge selector-mode trial shape.
50
+ */
51
+ function mutationsForSelectorBlockRemoval(selector, properties) {
52
+ return properties.map((property) => ({
53
+ selector,
54
+ property,
55
+ action: "remove"
56
+ }));
57
+ }
58
+ /**
59
+ * True when at least one of the batch-prescan results found a paint-tree
60
+ * signal. Used to short-circuit follow-up per-viewport captures.
61
+ */
62
+ function hasAnyBatchPrescanSignal(results) {
63
+ return results.some((result) => !result.missing && result.changes.length > 0);
64
+ }
65
+ //#endregion
66
+ export { hasAnyBatchPrescanSignal, mutationsForPropertyRemoval, mutationsForSelectorBlockRemoval, runBatchPrescan };
@@ -0,0 +1,50 @@
1
+ //#region src/capture-config.d.ts
2
+ interface CaptureRoute {
3
+ name: string;
4
+ path: string;
5
+ waitFor?: string;
6
+ }
7
+ interface CaptureConfig {
8
+ baseUrl?: string;
9
+ routes?: CaptureRoute[];
10
+ }
11
+ interface CaptureRouteSet {
12
+ baseUrl: string;
13
+ routes: CaptureRoute[];
14
+ source: "env" | "config" | "default";
15
+ configPath?: string;
16
+ }
17
+ declare const DEFAULT_CAPTURE_BASE_URL = "http://127.0.0.1:4174";
18
+ /**
19
+ * Built-in fallback used when no config or env override is provided.
20
+ * Kept for vrt's own development workflow; external projects should
21
+ * supply their own routes via `vrt.config.json`.
22
+ */
23
+ declare const DEFAULT_CAPTURE_ROUTES: CaptureRoute[];
24
+ declare const DEFAULT_CAPTURE_CONFIG_FILE = "vrt.config.json";
25
+ declare function parseCaptureConfig(raw: string): CaptureConfig;
26
+ declare function routeNameFromPath(path: string): string;
27
+ interface LoadCaptureConfigOptions {
28
+ configPath?: string;
29
+ cwd?: string;
30
+ envRoutes?: string;
31
+ envBaseUrl?: string;
32
+ envConfigPath?: string;
33
+ }
34
+ /**
35
+ * Resolve the route set to use for a capture run.
36
+ *
37
+ * Precedence (highest first):
38
+ * 1. `VRT_CAPTURE_ROUTES` env var (JSON-encoded array)
39
+ * 2. Explicit config path (CLI / `VRT_CONFIG_PATH`)
40
+ * 3. `vrt.config.json` discovered in `cwd`
41
+ * 4. Built-in defaults
42
+ */
43
+ declare function resolveCaptureRoutes(options?: LoadCaptureConfigOptions): CaptureRouteSet;
44
+ /**
45
+ * Helper for unit tests / non-Playwright callers: read & normalize a file.
46
+ */
47
+ declare function loadCaptureConfigFromFile(configPath: string): CaptureConfig;
48
+ declare function captureConfigDir(configPath: string): string;
49
+ //#endregion
50
+ export { CaptureConfig, CaptureRoute, CaptureRouteSet, DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, LoadCaptureConfigOptions, captureConfigDir, loadCaptureConfigFromFile, parseCaptureConfig, resolveCaptureRoutes, routeNameFromPath };
@@ -0,0 +1,164 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, isAbsolute, resolve } from "node:path";
3
+ //#region src/capture-config.ts
4
+ /**
5
+ * Capture configuration loader for `vrt workflow init|capture`.
6
+ *
7
+ * Allows external projects to drive `e2e/vrt-capture.spec.ts` without
8
+ * editing the spec by sourcing routes from `vrt.config.json` (or any
9
+ * file pointed at by `--config` / `VRT_CONFIG_PATH`).
10
+ */
11
+ const DEFAULT_CAPTURE_BASE_URL = "http://127.0.0.1:4174";
12
+ /**
13
+ * Built-in fallback used when no config or env override is provided.
14
+ * Kept for vrt's own development workflow; external projects should
15
+ * supply their own routes via `vrt.config.json`.
16
+ */
17
+ const DEFAULT_CAPTURE_ROUTES = [
18
+ {
19
+ name: "home",
20
+ path: "/",
21
+ waitFor: "main"
22
+ },
23
+ {
24
+ name: "readme",
25
+ path: "/readme",
26
+ waitFor: "article"
27
+ },
28
+ {
29
+ name: "files",
30
+ path: "/files",
31
+ waitFor: "main"
32
+ },
33
+ {
34
+ name: "issues",
35
+ path: "/issues",
36
+ waitFor: "main"
37
+ },
38
+ {
39
+ name: "pulls",
40
+ path: "/pulls",
41
+ waitFor: "main"
42
+ }
43
+ ];
44
+ const DEFAULT_CAPTURE_CONFIG_FILE = "vrt.config.json";
45
+ function parseCaptureConfig(raw) {
46
+ let parsed;
47
+ try {
48
+ parsed = JSON.parse(raw);
49
+ } catch (error) {
50
+ throw new Error(`Invalid capture config JSON: ${String(error)}`);
51
+ }
52
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Capture config must be an object");
53
+ const record = parsed;
54
+ const baseUrl = record.baseUrl == null ? void 0 : parseNonEmptyString(record.baseUrl, "capture config baseUrl must be a non-empty string");
55
+ const captureSection = record.capture;
56
+ const routesSource = pickRoutesSource(captureSection, record.routes);
57
+ return {
58
+ baseUrl,
59
+ routes: routesSource === void 0 ? void 0 : parseCaptureRoutes(routesSource)
60
+ };
61
+ }
62
+ function pickRoutesSource(captureSection, topLevelRoutes) {
63
+ if (captureSection !== void 0 && captureSection !== null) {
64
+ if (typeof captureSection !== "object" || Array.isArray(captureSection)) throw new Error("capture config `capture` must be an object");
65
+ const inner = captureSection.routes;
66
+ if (inner !== void 0) return inner;
67
+ }
68
+ return topLevelRoutes;
69
+ }
70
+ function parseCaptureRoutes(value) {
71
+ if (!Array.isArray(value)) throw new Error("capture config routes must be an array");
72
+ return value.map((entry, index) => parseCaptureRoute(entry, index));
73
+ }
74
+ function parseCaptureRoute(entry, index) {
75
+ if (typeof entry === "string") {
76
+ const path = entry.trim();
77
+ if (!path) throw new Error(`capture config route at index ${index} must be a non-empty string`);
78
+ return {
79
+ name: routeNameFromPath(path),
80
+ path
81
+ };
82
+ }
83
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) throw new Error(`capture config route at index ${index} must be a string or object`);
84
+ const record = entry;
85
+ const path = parseNonEmptyString(record.path ?? record.url, `capture config route at index ${index} must have a path`);
86
+ const nameRaw = record.name ?? record.label;
87
+ const name = nameRaw === void 0 ? routeNameFromPath(path) : parseNonEmptyString(nameRaw, `capture config route at index ${index} has an invalid name`);
88
+ const waitForRaw = record.waitFor ?? record.wait_for;
89
+ const route = {
90
+ name,
91
+ path
92
+ };
93
+ if (waitForRaw !== void 0) route.waitFor = parseNonEmptyString(waitForRaw, `capture config route at index ${index} has an invalid waitFor`);
94
+ return route;
95
+ }
96
+ function routeNameFromPath(path) {
97
+ const cleaned = path.split("?")[0].split("#")[0].replace(/^\/+|\/+$/g, "");
98
+ if (!cleaned) return "home";
99
+ return cleaned.replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase() || "home";
100
+ }
101
+ /**
102
+ * Resolve the route set to use for a capture run.
103
+ *
104
+ * Precedence (highest first):
105
+ * 1. `VRT_CAPTURE_ROUTES` env var (JSON-encoded array)
106
+ * 2. Explicit config path (CLI / `VRT_CONFIG_PATH`)
107
+ * 3. `vrt.config.json` discovered in `cwd`
108
+ * 4. Built-in defaults
109
+ */
110
+ function resolveCaptureRoutes(options = {}) {
111
+ const cwd = options.cwd ?? process.cwd();
112
+ const envBaseUrl = options.envBaseUrl?.trim();
113
+ const envRoutes = options.envRoutes;
114
+ if (envRoutes && envRoutes.trim().length > 0) {
115
+ const routes = parseCaptureRoutes(JSON.parse(envRoutes));
116
+ return {
117
+ baseUrl: envBaseUrl || "http://127.0.0.1:4174",
118
+ routes,
119
+ source: "env"
120
+ };
121
+ }
122
+ const configPath = resolveConfigPath(options.configPath, options.envConfigPath, cwd);
123
+ if (configPath) {
124
+ const config = parseCaptureConfig(readFileSync(configPath, "utf-8"));
125
+ const routes = config.routes ?? DEFAULT_CAPTURE_ROUTES;
126
+ return {
127
+ baseUrl: envBaseUrl || config.baseUrl || "http://127.0.0.1:4174",
128
+ routes,
129
+ source: "config",
130
+ configPath
131
+ };
132
+ }
133
+ return {
134
+ baseUrl: envBaseUrl || "http://127.0.0.1:4174",
135
+ routes: DEFAULT_CAPTURE_ROUTES,
136
+ source: "default"
137
+ };
138
+ }
139
+ function resolveConfigPath(explicit, fromEnv, cwd) {
140
+ const candidate = explicit ?? fromEnv;
141
+ if (candidate && candidate.trim().length > 0) {
142
+ const absolute = isAbsolute(candidate) ? candidate : resolve(cwd, candidate);
143
+ if (!existsSync(absolute)) throw new Error(`Capture config not found: ${absolute}`);
144
+ return absolute;
145
+ }
146
+ const defaultPath = resolve(cwd, DEFAULT_CAPTURE_CONFIG_FILE);
147
+ return existsSync(defaultPath) ? defaultPath : void 0;
148
+ }
149
+ function parseNonEmptyString(value, message) {
150
+ if (typeof value !== "string" || value.trim() === "") throw new Error(message);
151
+ return value;
152
+ }
153
+ /**
154
+ * Helper for unit tests / non-Playwright callers: read & normalize a file.
155
+ */
156
+ function loadCaptureConfigFromFile(configPath) {
157
+ if (!existsSync(configPath)) throw new Error(`Capture config not found: ${configPath}`);
158
+ return parseCaptureConfig(readFileSync(configPath, "utf-8"));
159
+ }
160
+ function captureConfigDir(configPath) {
161
+ return dirname(configPath);
162
+ }
163
+ //#endregion
164
+ export { DEFAULT_CAPTURE_BASE_URL, DEFAULT_CAPTURE_CONFIG_FILE, DEFAULT_CAPTURE_ROUTES, captureConfigDir, loadCaptureConfigFromFile, parseCaptureConfig, resolveCaptureRoutes, routeNameFromPath };
@@ -0,0 +1,45 @@
1
+ import { Browser } from "playwright";
2
+
3
+ //#region src/capturer.d.ts
4
+ type CaptureBackendKind = "local" | "cloudflare-cdp";
5
+ interface CaptureBackend {
6
+ readonly kind: CaptureBackendKind;
7
+ /** Human-readable label used in logs. */
8
+ readonly label: string;
9
+ launch(): Promise<Browser>;
10
+ close(browser: Browser): Promise<void>;
11
+ }
12
+ interface CloudflareCdpOptions {
13
+ accountId: string;
14
+ apiToken: string;
15
+ /** Override the default CF CDP URL (useful for tests / private deployments). */
16
+ endpoint?: string;
17
+ }
18
+ declare function buildCloudflareCdpUrl(opts: {
19
+ accountId: string;
20
+ endpoint?: string;
21
+ }): string;
22
+ declare function createLocalCapturer(): CaptureBackend;
23
+ declare function createCloudflareCdpCapturer(opts: CloudflareCdpOptions): CaptureBackend;
24
+ interface ResolveCaptureBackendOptions {
25
+ /** Value from `--backend` CLI flag (e.g. "local", "cloudflare"). */
26
+ backendFlag?: string;
27
+ env?: NodeJS.ProcessEnv;
28
+ }
29
+ interface ResolvedCaptureBackend {
30
+ backend: CaptureBackend;
31
+ source: "flag" | "env" | "default";
32
+ }
33
+ /**
34
+ * Resolution order:
35
+ * 1. Explicit `--backend` flag
36
+ * 2. `VRT_CAPTURE_BACKEND` env var
37
+ * 3. Default local
38
+ *
39
+ * For the Cloudflare backend, credentials come from env (`CLOUDFLARE_ACCOUNT_ID`
40
+ * + `CLOUDFLARE_API_TOKEN`) regardless of how the backend was selected, so
41
+ * CI configs can stay declarative.
42
+ */
43
+ declare function resolveCaptureBackend(options?: ResolveCaptureBackendOptions): ResolvedCaptureBackend;
44
+ //#endregion
45
+ export { CaptureBackend, CaptureBackendKind, CloudflareCdpOptions, ResolveCaptureBackendOptions, ResolvedCaptureBackend, buildCloudflareCdpUrl, createCloudflareCdpCapturer, createLocalCapturer, resolveCaptureBackend };
@@ -0,0 +1,94 @@
1
+ import { chromium } from "playwright";
2
+ //#region src/capturer.ts
3
+ /**
4
+ * Browser launch abstraction.
5
+ *
6
+ * Lets every consumer pick between launching Chromium locally and connecting
7
+ * to a remote Chrome DevTools Protocol endpoint such as Cloudflare's
8
+ * Browser Run service (https://api.cloudflare.com/client/v4/accounts/<id>/browser-rendering/devtools/browser).
9
+ *
10
+ * The factory only knows how to *open* a Browser. Page/context creation is
11
+ * left to the caller so existing capture code can keep its current
12
+ * `browser.newPage({viewport})` style.
13
+ */
14
+ function buildCloudflareCdpUrl(opts) {
15
+ if (opts.endpoint && opts.endpoint.length > 0) return opts.endpoint;
16
+ const account = opts.accountId.trim();
17
+ if (account.length === 0) throw new Error("Cloudflare account id is required to build the CDP URL");
18
+ return `wss://api.cloudflare.com/client/v4/accounts/${account}/browser-rendering/devtools/browser`;
19
+ }
20
+ function createLocalCapturer() {
21
+ return {
22
+ kind: "local",
23
+ label: "local chromium",
24
+ async launch() {
25
+ return chromium.launch();
26
+ },
27
+ async close(browser) {
28
+ await browser.close();
29
+ }
30
+ };
31
+ }
32
+ function createCloudflareCdpCapturer(opts) {
33
+ if (!opts.apiToken || opts.apiToken.trim().length === 0) throw new Error("Cloudflare API token is required for the cloudflare-cdp backend");
34
+ const wsEndpoint = buildCloudflareCdpUrl(opts);
35
+ const headers = { Authorization: `Bearer ${opts.apiToken}` };
36
+ return {
37
+ kind: "cloudflare-cdp",
38
+ label: `cloudflare browser run (${maskAccount(opts.accountId)})`,
39
+ async launch() {
40
+ return chromium.connectOverCDP(wsEndpoint, { headers });
41
+ },
42
+ async close(browser) {
43
+ await browser.close();
44
+ }
45
+ };
46
+ }
47
+ function maskAccount(id) {
48
+ if (id.length <= 8) return id;
49
+ return `${id.slice(0, 4)}…${id.slice(-4)}`;
50
+ }
51
+ /**
52
+ * Resolution order:
53
+ * 1. Explicit `--backend` flag
54
+ * 2. `VRT_CAPTURE_BACKEND` env var
55
+ * 3. Default local
56
+ *
57
+ * For the Cloudflare backend, credentials come from env (`CLOUDFLARE_ACCOUNT_ID`
58
+ * + `CLOUDFLARE_API_TOKEN`) regardless of how the backend was selected, so
59
+ * CI configs can stay declarative.
60
+ */
61
+ function resolveCaptureBackend(options = {}) {
62
+ const env = options.env ?? process.env;
63
+ const explicit = options.backendFlag?.trim().toLowerCase();
64
+ const envChoice = env.VRT_CAPTURE_BACKEND?.trim().toLowerCase();
65
+ const choice = explicit || envChoice || "local";
66
+ const source = explicit ? "flag" : envChoice ? "env" : "default";
67
+ switch (choice) {
68
+ case "local":
69
+ case "chromium": return {
70
+ backend: createLocalCapturer(),
71
+ source
72
+ };
73
+ case "cloudflare":
74
+ case "cloudflare-cdp":
75
+ case "browser-run": {
76
+ const accountId = env.CLOUDFLARE_ACCOUNT_ID?.trim();
77
+ const apiToken = env.CLOUDFLARE_API_TOKEN?.trim();
78
+ const endpoint = env.CLOUDFLARE_BROWSER_RUN_ENDPOINT?.trim();
79
+ if (!accountId) throw new Error("CLOUDFLARE_ACCOUNT_ID is required when --backend cloudflare is selected");
80
+ if (!apiToken) throw new Error("CLOUDFLARE_API_TOKEN is required when --backend cloudflare is selected");
81
+ return {
82
+ backend: createCloudflareCdpCapturer({
83
+ accountId,
84
+ apiToken,
85
+ endpoint
86
+ }),
87
+ source
88
+ };
89
+ }
90
+ default: throw new Error(`Unknown capture backend: ${choice}`);
91
+ }
92
+ }
93
+ //#endregion
94
+ export { buildCloudflareCdpUrl, createCloudflareCdpCapturer, createLocalCapturer, resolveCaptureBackend };
@@ -0,0 +1,114 @@
1
+ //#region src/cloudflare-quick-actions.d.ts
2
+ type CloudflareQuickAction = "screenshot" | "crawl";
3
+ interface CloudflareQuickActionsConfig {
4
+ accountId: string;
5
+ apiToken: string;
6
+ apiBase?: string;
7
+ fetch?: typeof fetch;
8
+ }
9
+ interface CloudflareQuickActionsEnv {
10
+ CLOUDFLARE_ACCOUNT_ID?: string;
11
+ CLOUDFLARE_API_TOKEN?: string;
12
+ CLOUDFLARE_BROWSER_RENDERING_API_BASE?: string;
13
+ }
14
+ interface CloudflareQuickActionEndpointInput {
15
+ accountId: string;
16
+ action: CloudflareQuickAction;
17
+ jobId?: string;
18
+ apiBase?: string;
19
+ }
20
+ interface CloudflareScreenshotRequest {
21
+ url?: string;
22
+ html?: string;
23
+ viewport?: {
24
+ width: number;
25
+ height: number;
26
+ deviceScaleFactor?: number;
27
+ };
28
+ screenshotOptions?: {
29
+ fullPage?: boolean;
30
+ omitBackground?: boolean;
31
+ type?: "png" | "jpeg" | "webp";
32
+ quality?: number;
33
+ clip?: {
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ };
39
+ };
40
+ selector?: string;
41
+ gotoOptions?: Record<string, unknown>;
42
+ authenticate?: Record<string, unknown>;
43
+ cookies?: unknown[];
44
+ setExtraHTTPHeaders?: Record<string, string>;
45
+ addScriptTag?: Array<Record<string, unknown>>;
46
+ addStyleTag?: Array<Record<string, unknown>>;
47
+ userAgent?: string;
48
+ }
49
+ interface CloudflareScreenshotResult {
50
+ bytes: ArrayBuffer;
51
+ contentType: string;
52
+ browserMsUsed?: number;
53
+ }
54
+ interface CloudflareCrawlRequest {
55
+ url: string;
56
+ limit?: number;
57
+ depth?: number;
58
+ formats?: Array<"html" | "markdown" | "json">;
59
+ render?: boolean;
60
+ maxAge?: number;
61
+ options?: {
62
+ includePatterns?: string[];
63
+ excludePatterns?: string[];
64
+ includeExternalLinks?: boolean;
65
+ includeSubdomains?: boolean;
66
+ };
67
+ gotoOptions?: Record<string, unknown>;
68
+ authenticate?: Record<string, unknown>;
69
+ cookies?: unknown[];
70
+ setExtraHTTPHeaders?: Record<string, string>;
71
+ rejectResourceTypes?: string[];
72
+ }
73
+ interface CloudflareCrawlStartResult {
74
+ jobId: string;
75
+ }
76
+ type CloudflareCrawlRecordStatus = "queued" | "errored" | "completed" | "disallowed" | "skipped" | "cancelled";
77
+ interface CloudflareCrawlRecord {
78
+ url: string;
79
+ status: CloudflareCrawlRecordStatus;
80
+ metadata?: {
81
+ status?: number;
82
+ url?: string;
83
+ title?: string;
84
+ };
85
+ html?: string;
86
+ markdown?: string;
87
+ json?: unknown;
88
+ }
89
+ interface CloudflareCrawlResult {
90
+ id: string;
91
+ status: string;
92
+ browserSecondsUsed?: number;
93
+ total?: number;
94
+ finished?: number;
95
+ records: CloudflareCrawlRecord[];
96
+ }
97
+ interface CloudflareCrawlRoute {
98
+ url: string;
99
+ path: string;
100
+ title?: string;
101
+ }
102
+ interface ExtractCloudflareCrawlRoutesOptions {
103
+ baseUrl?: string;
104
+ }
105
+ declare function buildCloudflareQuickActionEndpoint(input: CloudflareQuickActionEndpointInput): string;
106
+ declare function resolveCloudflareQuickActionsConfig(env?: CloudflareQuickActionsEnv): CloudflareQuickActionsConfig;
107
+ declare function createCloudflareQuickActionsClient(config: CloudflareQuickActionsConfig): {
108
+ screenshot(input: CloudflareScreenshotRequest): Promise<CloudflareScreenshotResult>;
109
+ startCrawl(input: CloudflareCrawlRequest): Promise<CloudflareCrawlStartResult>;
110
+ getCrawlResult(jobId: string): Promise<CloudflareCrawlResult>;
111
+ };
112
+ declare function extractCloudflareCrawlRoutes(result: CloudflareCrawlResult, options?: ExtractCloudflareCrawlRoutesOptions): CloudflareCrawlRoute[];
113
+ //#endregion
114
+ export { CloudflareCrawlRecord, CloudflareCrawlRecordStatus, CloudflareCrawlRequest, CloudflareCrawlResult, CloudflareCrawlRoute, CloudflareCrawlStartResult, CloudflareQuickAction, CloudflareQuickActionEndpointInput, CloudflareQuickActionsConfig, CloudflareQuickActionsEnv, CloudflareScreenshotRequest, CloudflareScreenshotResult, ExtractCloudflareCrawlRoutesOptions, buildCloudflareQuickActionEndpoint, createCloudflareQuickActionsClient, extractCloudflareCrawlRoutes, resolveCloudflareQuickActionsConfig };