snoop-ui 0.0.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 @@
1
+ {"version":3,"sources":["../src/cli/index.ts","../src/cli/init.ts","../src/cli/scan.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { resolve } from 'node:path';\nimport { cac } from 'cac';\nimport { readFileSync } from 'node:fs';\nimport { relativePosix } from '@snoop-ui/core/utils/paths.js';\nimport { initConfig } from './init.js';\nimport { DEFAULT_MANIFEST_PATH, runScan } from './scan.js';\n\nconst pkg = JSON.parse(readFileSync(resolve(import.meta.dirname, 'package.json'), 'utf8'));\n\ninterface InitCliOptions {\n cwd?: string;\n force?: boolean;\n}\n\ninterface ScanCliOptions {\n cwd?: string;\n out?: string;\n config?: string;\n cache?: boolean;\n}\n\nconst cli = cac('snoop');\n\ncli\n .command('init', 'Create a snoop.config.ts file')\n .option('--force', 'Overwrite an existing config')\n .option('--cwd <path>', 'Project directory')\n .action(async (options: InitCliOptions) => {\n const cwd = resolve(options.cwd ?? process.cwd());\n const result = await initConfig({ cwd, force: options.force });\n console.log(`Created ${displayPath(cwd, result.path)}.`);\n });\n\ncli\n .command('scan', 'Scan the project and write .snoop/manifest.json')\n .option('--out <path>', 'Output path', { default: DEFAULT_MANIFEST_PATH })\n .option('--cwd <path>', 'Project directory')\n .option('--config <path>', 'Config file to load')\n .option('--no-cache', 'Disable the content-hash scan cache')\n .action(async (options: ScanCliOptions) => {\n const cwd = resolve(options.cwd ?? process.cwd());\n const { result, outPath } = await runScan({\n cwd,\n out: options.out,\n ...(options.config ? { configFile: options.config } : {}),\n cache: options.cache,\n });\n const { stats } = result;\n const output = displayPath(cwd, outPath);\n\n if (stats.components === 0) {\n console.log(`No components found in ${stats.files} file(s).`);\n } else {\n console.log(`Scanned ${stats.components} component(s) in ${stats.files} file(s).`);\n }\n\n if (stats.cachedFiles > 0) {\n console.log(`Reused ${stats.cachedFiles} cached file(s).`);\n }\n\n if (stats.errors > 0) {\n console.log(`${stats.errors} file(s) had warnings; see ${output}.`);\n }\n\n console.log(`Wrote ${output}.`);\n });\n\ncli.help();\ncli.version(pkg.version);\n\nasync function main(): Promise<void> {\n if (process.argv.slice(2).length === 0) {\n cli.outputHelp();\n return;\n }\n\n const wantsHelp = process.argv.includes('--help') || process.argv.includes('-h');\n const wantsVersion = process.argv.includes('--version') || process.argv.includes('-v');\n\n cli.parse(process.argv, { run: false });\n\n if (!cli.matchedCommand) {\n if (!wantsHelp && !wantsVersion && cli.args[0]) {\n console.error(`Unknown command: ${cli.args[0]}`);\n cli.outputHelp();\n process.exitCode = 1;\n }\n return;\n }\n\n try {\n await cli.runMatchedCommand();\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n }\n}\n\nfunction displayPath(cwd: string, path: string): string {\n return relativePosix(cwd, path) || '.';\n}\n\nawait main();\n","import { access, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\n\nexport interface InitOptions {\n cwd?: string;\n force?: boolean;\n}\n\nexport interface InitResult {\n path: string;\n}\n\nconst CONFIG_TEMPLATE = `import { defineConfig } from 'snoop-ui';\n\nexport default defineConfig({\n // include: ['src/**/*.{jsx,tsx}'],\n // exclude: ['**/*.stories.{js,jsx,ts,tsx}'],\n // tokens: ['src/styles/tokens.css'],\n});\n`;\n\nexport async function initConfig(options: InitOptions = {}): Promise<InitResult> {\n const cwd = resolve(options.cwd ?? process.cwd());\n const path = resolve(cwd, 'snoop.config.ts');\n\n if (!options.force && (await exists(path))) {\n throw new Error(`A Snoop config already exists at ${path}. Use --force to overwrite it.`);\n }\n\n try {\n await writeFile(path, CONFIG_TEMPLATE, {\n encoding: 'utf8',\n flag: options.force ? 'w' : 'wx',\n });\n } catch (error) {\n if (!options.force && isAlreadyExists(error)) {\n throw new Error(`A Snoop config already exists at ${path}. Use --force to overwrite it.`, {\n cause: error,\n });\n }\n throw error;\n }\n\n return { path };\n}\n\nasync function exists(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction isAlreadyExists(error: unknown): boolean {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === 'EEXIST';\n}\n","import { resolve } from 'node:path';\nimport { loadConfig } from '@snoop-ui/core/config.js';\nimport { scanProject, writeManifest, type ScanResult } from '@snoop-ui/core/scanner/index.js';\n\nexport interface ScanOptions {\n cwd?: string;\n out?: string;\n configFile?: string;\n cache?: boolean;\n}\n\nexport interface ScanCommandResult {\n result: ScanResult;\n outPath: string;\n}\n\nexport const DEFAULT_MANIFEST_PATH = '.snoop/manifest.json';\n\nexport async function runScan(options: ScanOptions = {}): Promise<ScanCommandResult> {\n const cwd = resolve(options.cwd ?? process.cwd());\n const config = await loadConfig({\n cwd,\n ...(options.configFile ? { configFile: options.configFile } : {}),\n });\n\n const result = await scanProject({\n cwd,\n include: config.include,\n exclude: config.exclude,\n tokens: config.tokens,\n cache: options.cache,\n });\n\n const outPath = resolve(cwd, options.out ?? DEFAULT_MANIFEST_PATH);\n await writeManifest(outPath, result.manifest);\n\n return { result, outPath };\n}\n"],"mappings":";;;AACA,SAAS,WAAAA,gBAAe;AACxB,SAAS,WAAW;AACpB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;;;ACJ9B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,eAAe;AAWxB,IAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASxB,eAAsB,WAAW,UAAuB,CAAC,GAAwB;AAC/E,QAAM,MAAM,QAAQ,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAChD,QAAM,OAAO,QAAQ,KAAK,iBAAiB;AAE3C,MAAI,CAAC,QAAQ,SAAU,MAAM,OAAO,IAAI,GAAI;AAC1C,UAAM,IAAI,MAAM,oCAAoC,IAAI,gCAAgC;AAAA,EAC1F;AAEA,MAAI;AACF,UAAM,UAAU,MAAM,iBAAiB;AAAA,MACrC,UAAU;AAAA,M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AAC;AAEH,IAAI,KAAK;AACT,IAAI,QAAQ,IAAI,OAAO;AAEvB,eAAe,OAAsB;AACnC,MAAI,QAAQ,KAAK,MAAM,CAAC,EAAE,WAAW,GAAG;AACtC,QAAI,WAAW;AACf;AAAA,EACF;AAEA,QAAM,YAAY,QAAQ,KAAK,SAAS,QAAQ,KAAK,QAAQ,KAAK,SAAS,IAAI;AAC/E,QAAM,eAAe,QAAQ,KAAK,SAAS,WAAW,KAAK,QAAQ,KAAK,SAAS,IAAI;AAErF,MAAI,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM,CAAC;AAEtC,MAAI,CAAC,IAAI,gBAAgB;AACvB,QAAI,CAAC,aAAa,CAAC,gBAAgB,IAAI,KAAK,CAAC,GAAG;AAC9C,cAAQ,MAAM,oBAAoB,IAAI,KAAK,CAAC,CAAC,EAAE;AAC/C,UAAI,WAAW;AACf,cAAQ,WAAW;AAAA,IACrB;AACA;AAAA,EACF;AAEA,MAAI;AACF,UAAM,IAAI,kBAAkB;AAAA,EAC9B,SAAS,OAAO;AACd,YAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AACpE,YAAQ,WAAW;AAAA,EACrB;AACF;AAEA,SAAS,YAAY,KAAa,MAAsB;AACtD,SAAO,cAAc,KAAK,IAAI,KAAK;AACrC;AAEA,MAAM,KAAK;","names":["resolve","resolve","resolve"]}
@@ -0,0 +1,607 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const RuleSettingSchema: z.ZodEnum<{
4
+ off: "off";
5
+ info: "info";
6
+ warning: "warning";
7
+ error: "error";
8
+ }>;
9
+ type RuleSetting = z.infer<typeof RuleSettingSchema>;
10
+ declare const DEFAULT_INCLUDE: readonly ["src/**/*.{jsx,tsx}"];
11
+ declare const DEFAULT_EXCLUDE: readonly ["**/node_modules/**", "**/dist/**", "**/build/**", "**/*.test.{js,jsx,ts,tsx}", "**/*.spec.{js,jsx,ts,tsx}", "**/*.stories.{js,jsx,ts,tsx}"];
12
+ declare const ConfigSchema: z.ZodObject<{
13
+ include: z.ZodDefault<z.ZodArray<z.ZodString>>;
14
+ exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
15
+ tokens: z.ZodDefault<z.ZodArray<z.ZodString>>;
16
+ providers: z.ZodOptional<z.ZodString>;
17
+ tolerance: z.ZodDefault<z.ZodObject<{
18
+ px: z.ZodNumber;
19
+ }, z.core.$strip>>;
20
+ baseline: z.ZodDefault<z.ZodString>;
21
+ basePath: z.ZodDefault<z.ZodString>;
22
+ appUrl: z.ZodDefault<z.ZodString>;
23
+ rules: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<{
24
+ off: "off";
25
+ info: "info";
26
+ warning: "warning";
27
+ error: "error";
28
+ }>>>;
29
+ editor: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>;
31
+ type SnoopConfig = z.input<typeof ConfigSchema>;
32
+ type ResolvedConfig = z.output<typeof ConfigSchema>;
33
+
34
+ interface LoadConfigOptions {
35
+ cwd?: string;
36
+ configFile?: string;
37
+ }
38
+ declare function defineConfig(config: SnoopConfig): SnoopConfig;
39
+ declare function findConfigFile(options?: LoadConfigOptions): Promise<string | undefined>;
40
+ declare function loadConfig(options?: LoadConfigOptions): Promise<ResolvedConfig>;
41
+
42
+ declare const PropSchema: z.ZodObject<{
43
+ name: z.ZodString;
44
+ type: z.ZodOptional<z.ZodString>;
45
+ required: z.ZodDefault<z.ZodBoolean>;
46
+ defaultValue: z.ZodOptional<z.ZodString>;
47
+ }, z.core.$strip>;
48
+ type Prop = z.infer<typeof PropSchema>;
49
+ declare const ComponentNodeSchema: z.ZodObject<{
50
+ id: z.ZodString;
51
+ kind: z.ZodLiteral<"component">;
52
+ name: z.ZodString;
53
+ file: z.ZodString;
54
+ exportName: z.ZodOptional<z.ZodString>;
55
+ loc: z.ZodOptional<z.ZodObject<{
56
+ start: z.ZodObject<{
57
+ line: z.ZodNumber;
58
+ col: z.ZodNumber;
59
+ }, z.core.$strip>;
60
+ end: z.ZodObject<{
61
+ line: z.ZodNumber;
62
+ col: z.ZodNumber;
63
+ }, z.core.$strip>;
64
+ }, z.core.$strip>>;
65
+ props: z.ZodDefault<z.ZodArray<z.ZodObject<{
66
+ name: z.ZodString;
67
+ type: z.ZodOptional<z.ZodString>;
68
+ required: z.ZodDefault<z.ZodBoolean>;
69
+ defaultValue: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>>>;
71
+ }, z.core.$strip>;
72
+ type ComponentNode = z.infer<typeof ComponentNodeSchema>;
73
+ declare const EdgeRelationSchema: z.ZodEnum<{
74
+ renders: "renders";
75
+ imports: "imports";
76
+ }>;
77
+ type EdgeRelation = z.infer<typeof EdgeRelationSchema>;
78
+ declare const EdgeSchema: z.ZodObject<{
79
+ from: z.ZodString;
80
+ to: z.ZodString;
81
+ relation: z.ZodEnum<{
82
+ renders: "renders";
83
+ imports: "imports";
84
+ }>;
85
+ confidence: z.ZodEnum<{
86
+ EXTRACTED: "EXTRACTED";
87
+ INFERRED: "INFERRED";
88
+ }>;
89
+ }, z.core.$strip>;
90
+ type Edge = z.infer<typeof EdgeSchema>;
91
+ declare const ScanErrorSchema: z.ZodObject<{
92
+ code: z.ZodString;
93
+ file: z.ZodString;
94
+ message: z.ZodString;
95
+ }, z.core.$strip>;
96
+ type ScanError = z.infer<typeof ScanErrorSchema>;
97
+ declare const TokenTableSchema: z.ZodRecord<z.ZodString, z.ZodString>;
98
+ type TokenTable = z.infer<typeof TokenTableSchema>;
99
+ declare const ManifestSchema: z.ZodObject<{
100
+ version: z.ZodLiteral<1>;
101
+ tokens: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
102
+ nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
103
+ id: z.ZodString;
104
+ kind: z.ZodLiteral<"component">;
105
+ name: z.ZodString;
106
+ file: z.ZodString;
107
+ exportName: z.ZodOptional<z.ZodString>;
108
+ loc: z.ZodOptional<z.ZodObject<{
109
+ start: z.ZodObject<{
110
+ line: z.ZodNumber;
111
+ col: z.ZodNumber;
112
+ }, z.core.$strip>;
113
+ end: z.ZodObject<{
114
+ line: z.ZodNumber;
115
+ col: z.ZodNumber;
116
+ }, z.core.$strip>;
117
+ }, z.core.$strip>>;
118
+ props: z.ZodDefault<z.ZodArray<z.ZodObject<{
119
+ name: z.ZodString;
120
+ type: z.ZodOptional<z.ZodString>;
121
+ required: z.ZodDefault<z.ZodBoolean>;
122
+ defaultValue: z.ZodOptional<z.ZodString>;
123
+ }, z.core.$strip>>>;
124
+ }, z.core.$strip>>>;
125
+ edges: z.ZodDefault<z.ZodArray<z.ZodObject<{
126
+ from: z.ZodString;
127
+ to: z.ZodString;
128
+ relation: z.ZodEnum<{
129
+ renders: "renders";
130
+ imports: "imports";
131
+ }>;
132
+ confidence: z.ZodEnum<{
133
+ EXTRACTED: "EXTRACTED";
134
+ INFERRED: "INFERRED";
135
+ }>;
136
+ }, z.core.$strip>>>;
137
+ errors: z.ZodDefault<z.ZodArray<z.ZodObject<{
138
+ code: z.ZodString;
139
+ file: z.ZodString;
140
+ message: z.ZodString;
141
+ }, z.core.$strip>>>;
142
+ }, z.core.$strip>;
143
+ type Manifest = z.infer<typeof ManifestSchema>;
144
+ /**
145
+ * Produce deterministic manifest output for golden tests, CI diffs, and
146
+ * reproducible `snoop scan` results.
147
+ */
148
+ declare function sortManifest(manifest: Manifest): Manifest;
149
+
150
+ declare const StyleDeclarationSchema: z.ZodObject<{
151
+ property: z.ZodString;
152
+ value: z.ZodString;
153
+ important: z.ZodDefault<z.ZodBoolean>;
154
+ line: z.ZodNumber;
155
+ col: z.ZodNumber;
156
+ }, z.core.$strip>;
157
+ type StyleDeclaration = z.infer<typeof StyleDeclarationSchema>;
158
+ declare const StyleRuleSchema: z.ZodObject<{
159
+ file: z.ZodString;
160
+ selector: z.ZodString;
161
+ runtimeSelector: z.ZodOptional<z.ZodString>;
162
+ declarations: z.ZodDefault<z.ZodArray<z.ZodObject<{
163
+ property: z.ZodString;
164
+ value: z.ZodString;
165
+ important: z.ZodDefault<z.ZodBoolean>;
166
+ line: z.ZodNumber;
167
+ col: z.ZodNumber;
168
+ }, z.core.$strip>>>;
169
+ atRules: z.ZodDefault<z.ZodArray<z.ZodString>>;
170
+ module: z.ZodDefault<z.ZodBoolean>;
171
+ line: z.ZodNumber;
172
+ col: z.ZodNumber;
173
+ }, z.core.$strip>;
174
+ type StyleRule = z.infer<typeof StyleRuleSchema>;
175
+ declare const InlineStyleSchema: z.ZodObject<{
176
+ src: z.ZodString;
177
+ file: z.ZodString;
178
+ range: z.ZodObject<{
179
+ start: z.ZodObject<{
180
+ line: z.ZodNumber;
181
+ col: z.ZodNumber;
182
+ }, z.core.$strip>;
183
+ end: z.ZodObject<{
184
+ line: z.ZodNumber;
185
+ col: z.ZodNumber;
186
+ }, z.core.$strip>;
187
+ }, z.core.$strip>;
188
+ confidence: z.ZodEnum<{
189
+ EXTRACTED: "EXTRACTED";
190
+ INFERRED: "INFERRED";
191
+ }>;
192
+ }, z.core.$strip>;
193
+ type InlineStyle = z.infer<typeof InlineStyleSchema>;
194
+ declare const StyleErrorSchema: z.ZodObject<{
195
+ code: z.ZodString;
196
+ file: z.ZodString;
197
+ message: z.ZodString;
198
+ }, z.core.$strip>;
199
+ type StyleError = z.infer<typeof StyleErrorSchema>;
200
+ /**
201
+ * Static style knowledge served alongside the manifest. It is not part of the
202
+ * manifest artifact: the browser CSSOM remains the source of truth for values,
203
+ * and this index only supplies file/line provenance and tokens.
204
+ */
205
+ declare const StyleIndexSchema: z.ZodObject<{
206
+ version: z.ZodLiteral<1>;
207
+ tokens: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
208
+ rules: z.ZodDefault<z.ZodArray<z.ZodObject<{
209
+ file: z.ZodString;
210
+ selector: z.ZodString;
211
+ runtimeSelector: z.ZodOptional<z.ZodString>;
212
+ declarations: z.ZodDefault<z.ZodArray<z.ZodObject<{
213
+ property: z.ZodString;
214
+ value: z.ZodString;
215
+ important: z.ZodDefault<z.ZodBoolean>;
216
+ line: z.ZodNumber;
217
+ col: z.ZodNumber;
218
+ }, z.core.$strip>>>;
219
+ atRules: z.ZodDefault<z.ZodArray<z.ZodString>>;
220
+ module: z.ZodDefault<z.ZodBoolean>;
221
+ line: z.ZodNumber;
222
+ col: z.ZodNumber;
223
+ }, z.core.$strip>>>;
224
+ inlineStyles: z.ZodDefault<z.ZodArray<z.ZodObject<{
225
+ src: z.ZodString;
226
+ file: z.ZodString;
227
+ range: z.ZodObject<{
228
+ start: z.ZodObject<{
229
+ line: z.ZodNumber;
230
+ col: z.ZodNumber;
231
+ }, z.core.$strip>;
232
+ end: z.ZodObject<{
233
+ line: z.ZodNumber;
234
+ col: z.ZodNumber;
235
+ }, z.core.$strip>;
236
+ }, z.core.$strip>;
237
+ confidence: z.ZodEnum<{
238
+ EXTRACTED: "EXTRACTED";
239
+ INFERRED: "INFERRED";
240
+ }>;
241
+ }, z.core.$strip>>>;
242
+ tailwind: z.ZodDefault<z.ZodBoolean>;
243
+ errors: z.ZodDefault<z.ZodArray<z.ZodObject<{
244
+ code: z.ZodString;
245
+ file: z.ZodString;
246
+ message: z.ZodString;
247
+ }, z.core.$strip>>>;
248
+ }, z.core.$strip>;
249
+ type StyleIndex = z.infer<typeof StyleIndexSchema>;
250
+ declare function sortStyleIndex(index: StyleIndex): StyleIndex;
251
+
252
+ declare const SeveritySchema: z.ZodEnum<{
253
+ info: "info";
254
+ warning: "warning";
255
+ error: "error";
256
+ }>;
257
+ type Severity = z.infer<typeof SeveritySchema>;
258
+ declare const DiagnosticFixSchema: z.ZodObject<{
259
+ kind: z.ZodLiteral<"replace">;
260
+ text: z.ZodString;
261
+ }, z.core.$strip>;
262
+ type DiagnosticFix = z.infer<typeof DiagnosticFixSchema>;
263
+ declare const DiagnosticSchema: z.ZodObject<{
264
+ code: z.ZodString;
265
+ severity: z.ZodEnum<{
266
+ info: "info";
267
+ warning: "warning";
268
+ error: "error";
269
+ }>;
270
+ confidence: z.ZodEnum<{
271
+ EXTRACTED: "EXTRACTED";
272
+ INFERRED: "INFERRED";
273
+ }>;
274
+ file: z.ZodString;
275
+ range: z.ZodObject<{
276
+ start: z.ZodObject<{
277
+ line: z.ZodNumber;
278
+ col: z.ZodNumber;
279
+ }, z.core.$strip>;
280
+ end: z.ZodObject<{
281
+ line: z.ZodNumber;
282
+ col: z.ZodNumber;
283
+ }, z.core.$strip>;
284
+ }, z.core.$strip>;
285
+ message: z.ZodString;
286
+ fix: z.ZodOptional<z.ZodObject<{
287
+ kind: z.ZodLiteral<"replace">;
288
+ text: z.ZodString;
289
+ }, z.core.$strip>>;
290
+ fingerprint: z.ZodString;
291
+ }, z.core.$strip>;
292
+ type Diagnostic = z.infer<typeof DiagnosticSchema>;
293
+ declare const DiagnosticsFileSchema: z.ZodObject<{
294
+ version: z.ZodLiteral<1>;
295
+ diagnostics: z.ZodDefault<z.ZodArray<z.ZodObject<{
296
+ code: z.ZodString;
297
+ severity: z.ZodEnum<{
298
+ info: "info";
299
+ warning: "warning";
300
+ error: "error";
301
+ }>;
302
+ confidence: z.ZodEnum<{
303
+ EXTRACTED: "EXTRACTED";
304
+ INFERRED: "INFERRED";
305
+ }>;
306
+ file: z.ZodString;
307
+ range: z.ZodObject<{
308
+ start: z.ZodObject<{
309
+ line: z.ZodNumber;
310
+ col: z.ZodNumber;
311
+ }, z.core.$strip>;
312
+ end: z.ZodObject<{
313
+ line: z.ZodNumber;
314
+ col: z.ZodNumber;
315
+ }, z.core.$strip>;
316
+ }, z.core.$strip>;
317
+ message: z.ZodString;
318
+ fix: z.ZodOptional<z.ZodObject<{
319
+ kind: z.ZodLiteral<"replace">;
320
+ text: z.ZodString;
321
+ }, z.core.$strip>>;
322
+ fingerprint: z.ZodString;
323
+ }, z.core.$strip>>>;
324
+ }, z.core.$strip>;
325
+ type DiagnosticsFile = z.infer<typeof DiagnosticsFileSchema>;
326
+ declare function sortDiagnostics(file: DiagnosticsFile): DiagnosticsFile;
327
+
328
+ interface ScanProjectOptions {
329
+ cwd?: string;
330
+ include?: string[];
331
+ exclude?: string[];
332
+ /** Extra CSS token files from `snoop.config.ts`. */
333
+ tokens?: string[];
334
+ /** Cache parsed files by content hash. Enabled by default. */
335
+ cache?: boolean;
336
+ /** Resolve Vite CSS Modules class names. The dev plugin supplies this. */
337
+ resolveCssModules?: (files: string[]) => Promise<Record<string, Record<string, string>>>;
338
+ }
339
+ interface ScanStats {
340
+ files: number;
341
+ parsedFiles: number;
342
+ cachedFiles: number;
343
+ components: number;
344
+ edges: number;
345
+ errors: number;
346
+ }
347
+ interface ScanResult {
348
+ manifest: Manifest;
349
+ styles: StyleIndex;
350
+ diagnostics: DiagnosticsFile;
351
+ stats: ScanStats;
352
+ }
353
+ /**
354
+ * Scan a project and return a deterministic manifest. Failures are per file:
355
+ * a broken file becomes an entry in `manifest.errors` and never stops the scan.
356
+ */
357
+ declare function scanProject(options?: ScanProjectOptions): Promise<ScanResult>;
358
+ declare function writeManifest(outPath: string, manifest: Manifest): Promise<void>;
359
+
360
+ declare const ConfidenceSchema: z.ZodEnum<{
361
+ EXTRACTED: "EXTRACTED";
362
+ INFERRED: "INFERRED";
363
+ }>;
364
+ type Confidence = z.infer<typeof ConfidenceSchema>;
365
+ declare const PositionSchema: z.ZodObject<{
366
+ line: z.ZodNumber;
367
+ col: z.ZodNumber;
368
+ }, z.core.$strip>;
369
+ type Position = z.infer<typeof PositionSchema>;
370
+ declare const RangeSchema: z.ZodObject<{
371
+ start: z.ZodObject<{
372
+ line: z.ZodNumber;
373
+ col: z.ZodNumber;
374
+ }, z.core.$strip>;
375
+ end: z.ZodObject<{
376
+ line: z.ZodNumber;
377
+ col: z.ZodNumber;
378
+ }, z.core.$strip>;
379
+ }, z.core.$strip>;
380
+ type SourceRange = z.infer<typeof RangeSchema>;
381
+ declare const PosixPathSchema: z.ZodString;
382
+ type PosixPath = z.infer<typeof PosixPathSchema>;
383
+ declare function compareStrings(a: string, b: string): number;
384
+
385
+ declare const MANIFEST_VERSION: 1;
386
+ declare const DIAGNOSTICS_VERSION: 1;
387
+ declare const STYLE_INDEX_VERSION: 1;
388
+
389
+ interface ParseStyleSheetOptions {
390
+ /** Generated class name -> original class name, from Vite's CSS Modules output. */
391
+ classMap?: Record<string, string>;
392
+ }
393
+ interface ParsedStyleSheet {
394
+ rules: StyleRule[];
395
+ /** CSS custom properties found in the sheet, including `@theme` values. */
396
+ tokens: Record<string, string>;
397
+ /** The sheet references Tailwind (`@tailwind` or `@import "tailwindcss"`). */
398
+ tailwind: boolean;
399
+ /** The sheet declares a Tailwind v4 `@theme` block. */
400
+ theme: boolean;
401
+ }
402
+ /**
403
+ * Parse one stylesheet into the static style index. The browser CSSOM remains
404
+ * the source of truth for computed values; this only records where a rule and
405
+ * its declarations live in source.
406
+ */
407
+ declare function parseStyleSheet(file: string, source: string, options?: ParseStyleSheetOptions): ParsedStyleSheet;
408
+ /** Rename classes in a selector using Vite's generated CSS Modules names. */
409
+ declare function rewriteClasses(selector: string, classMap: Record<string, string>): string;
410
+
411
+ /**
412
+ * Wire protocol shared by the dashboard, the runtime agent, and the dev-server
413
+ * bridge.
414
+ *
415
+ * The bridge is a relay: dashboard messages travel to agents, agent messages
416
+ * travel to dashboards. The server never interprets the payload, so both sides
417
+ * can evolve without changing the server.
418
+ */
419
+ type BridgeRole = 'agent' | 'dashboard';
420
+ declare const AGENT_ROLE: BridgeRole;
421
+ declare const DASHBOARD_ROLE: BridgeRole;
422
+ interface Rect {
423
+ x: number;
424
+ y: number;
425
+ width: number;
426
+ height: number;
427
+ top: number;
428
+ left: number;
429
+ right: number;
430
+ bottom: number;
431
+ }
432
+ interface MeasuredElement {
433
+ /** `file:line:col` taken from the `data-snoop-src` attribute. */
434
+ src: string;
435
+ tag: string;
436
+ rect: Rect;
437
+ }
438
+ interface MatchedDeclaration {
439
+ property: string;
440
+ /** The declaration as written, before the browser resolves variables. */
441
+ value: string;
442
+ important: boolean;
443
+ }
444
+ interface MatchedRule {
445
+ /** Selector text from the browser CSSOM. */
446
+ selector: string;
447
+ declarations: MatchedDeclaration[];
448
+ /** Source order across the document's stylesheets. */
449
+ order: number;
450
+ /** Enclosing conditional at-rules, outermost first. */
451
+ atRules: string[];
452
+ }
453
+ interface ElementDetail {
454
+ src: string;
455
+ tag: string;
456
+ rect: Rect;
457
+ /** Curated computed-style values for the selected element only. */
458
+ style: Record<string, string>;
459
+ /** Class names currently on the element. */
460
+ classes: string[];
461
+ /** Inline declarations, limited to the curated style properties. */
462
+ inlineStyle: Record<string, string>;
463
+ /** Stylesheet rules that match the element, in document order. */
464
+ matchedRules: MatchedRule[];
465
+ }
466
+ /** Messages sent by the runtime agent to the dashboard. */
467
+ type AgentMessage = {
468
+ kind: 'ready';
469
+ } | {
470
+ kind: 'presence';
471
+ connected: boolean;
472
+ } | {
473
+ kind: 'elements';
474
+ elements: MeasuredElement[];
475
+ } | {
476
+ kind: 'detail';
477
+ detail: ElementDetail;
478
+ } | {
479
+ kind: 'click';
480
+ src: string;
481
+ } | {
482
+ kind: 'hover';
483
+ src: string | null;
484
+ };
485
+ /** Messages sent by the dashboard to the runtime agent. */
486
+ type DashboardMessage = {
487
+ kind: 'measure';
488
+ enabled: boolean;
489
+ } | {
490
+ kind: 'inspect';
491
+ enabled: boolean;
492
+ } | {
493
+ kind: 'isolate';
494
+ enabled: boolean;
495
+ } | {
496
+ kind: 'select';
497
+ srcs: string[];
498
+ /** Scroll the first source to the centre of the viewport. */
499
+ reveal?: boolean;
500
+ } | {
501
+ kind: 'sync';
502
+ };
503
+ type RelayPayload = AgentMessage | DashboardMessage;
504
+ interface RelayEnvelope {
505
+ type: 'relay';
506
+ payload: RelayPayload;
507
+ }
508
+ declare function isAgentMessage(value: unknown): value is AgentMessage;
509
+ declare function isDashboardMessage(value: unknown): value is DashboardMessage;
510
+ declare function isRelayEnvelope(value: unknown): value is RelayEnvelope;
511
+ declare function parseRole(value: string | null | undefined): BridgeRole;
512
+ declare function isRecord(value: unknown): value is Record<string, unknown>;
513
+
514
+ type StyleSourceKind = 'inline' | 'stylesheet' | 'css-module' | 'tailwind' | 'unknown';
515
+ interface StyleSource {
516
+ kind: StyleSourceKind;
517
+ confidence: Confidence;
518
+ file?: string;
519
+ line?: number;
520
+ col?: number;
521
+ selector?: string;
522
+ atRules?: string[];
523
+ /** Number of static rules that matched the same selector and property. */
524
+ candidates?: number;
525
+ }
526
+ type StyleProvenance = Record<string, StyleSource>;
527
+ interface StyleIndexer {
528
+ resolve(detail: ElementDetail): StyleProvenance;
529
+ }
530
+ /**
531
+ * Combine the browser's matched rules with the static CSS index. The browser
532
+ * decides the winning declaration; the index says where that declaration was
533
+ * written. Ambiguity is reported as INFERRED instead of guessed.
534
+ */
535
+ declare function createStyleIndexer(index: StyleIndex): StyleIndexer;
536
+
537
+ interface ScanStylesOptions {
538
+ cwd?: string;
539
+ /** Extra token files from `snoop.config.ts`; read even outside `src`. */
540
+ tokenFiles?: readonly string[];
541
+ exclude?: readonly string[];
542
+ /** Inline `style` props found by the component scanner. */
543
+ inlineStyles?: readonly InlineStyle[];
544
+ /**
545
+ * Resolve Vite's CSS Modules class names for module files. The plugin
546
+ * supplies this; the CLI leaves it out and keeps original selectors.
547
+ */
548
+ resolveCssModules?: (files: string[]) => Promise<Record<string, Record<string, string>>>;
549
+ }
550
+ /** Scan CSS and build the static half of style provenance. */
551
+ declare function scanStyles(options?: ScanStylesOptions): Promise<StyleIndex>;
552
+
553
+ /**
554
+ * Selector helpers shared by the static CSS parser and the dashboard. They are
555
+ * deliberately dependency-free so they can run in the browser dashboard and in
556
+ * the Node tests without pulling PostCSS into the client bundle.
557
+ */
558
+ interface Specificity {
559
+ id: number;
560
+ class: number;
561
+ type: number;
562
+ }
563
+ /**
564
+ * Normalize a selector list for lookup. Whitespace and spaces around
565
+ * combinators are insignificant, but the contents of strings, attribute
566
+ * selectors, and pseudo-class arguments are preserved.
567
+ */
568
+ declare function normalizeSelector(selector: string): string;
569
+ /**
570
+ * Compute selector specificity with a small, dependency-free parser. The
571
+ * cascade only needs the values to be ordered correctly; this follows the
572
+ * Selectors Level 4 rules for `:is`, `:not`, `:has`, `:where`, and
573
+ * `:nth-child(… of …)`.
574
+ */
575
+ declare function specificityOf(selector: string): Specificity;
576
+ declare function compareSpecificity(a: Specificity, b: Specificity): number;
577
+
578
+ interface TailwindThemeResult {
579
+ tokens: Record<string, string>;
580
+ found: boolean;
581
+ errors: StyleError[];
582
+ }
583
+ /**
584
+ * Read Tailwind v3 theme values through Tailwind's own `resolveConfig` and keep
585
+ * only values the project changed from the default theme. Tailwind v4 values
586
+ * arrive as CSS custom properties from `@theme` and are collected by the CSS
587
+ * parser instead.
588
+ */
589
+ declare function extractTailwindTheme(cwd: string): Promise<TailwindThemeResult>;
590
+
591
+ type RuleName = 'token/hardcoded-match' | 'token/near-match' | 'token/undefined-var';
592
+ interface RuleContext {
593
+ manifest: Manifest;
594
+ styleIndex: StyleIndex;
595
+ config: ResolvedConfig;
596
+ }
597
+ interface RuleResult {
598
+ diagnostics: Diagnostic[];
599
+ }
600
+ type Rule = (context: RuleContext) => RuleResult;
601
+ declare const RULE_NAMES: RuleName[];
602
+ declare function createRulesEngine(context: RuleContext, enabled?: Partial<Record<RuleName, boolean>>): RuleResult;
603
+
604
+ declare const VERSION: string;
605
+
606
+ export { AGENT_ROLE, ComponentNodeSchema, ConfidenceSchema, ConfigSchema, DASHBOARD_ROLE, DEFAULT_EXCLUDE, DEFAULT_INCLUDE, DIAGNOSTICS_VERSION, DiagnosticFixSchema, DiagnosticSchema, DiagnosticsFileSchema, EdgeRelationSchema, EdgeSchema, InlineStyleSchema, MANIFEST_VERSION, ManifestSchema, PositionSchema, PosixPathSchema, PropSchema, RULE_NAMES, RangeSchema, RuleSettingSchema, STYLE_INDEX_VERSION, ScanErrorSchema, SeveritySchema, StyleDeclarationSchema, StyleErrorSchema, StyleIndexSchema, StyleRuleSchema, TokenTableSchema, VERSION, compareSpecificity, compareStrings, createRulesEngine, createStyleIndexer, defineConfig, extractTailwindTheme, findConfigFile, isAgentMessage, isDashboardMessage, isRecord, isRelayEnvelope, loadConfig, normalizeSelector, parseRole, parseStyleSheet, rewriteClasses, scanProject, scanStyles, sortDiagnostics, sortManifest, sortStyleIndex, specificityOf, writeManifest };
607
+ export type { AgentMessage, BridgeRole, ComponentNode, Confidence, DashboardMessage, Diagnostic, DiagnosticFix, DiagnosticsFile, Edge, EdgeRelation, ElementDetail, InlineStyle, Manifest, MatchedDeclaration, MatchedRule, MeasuredElement, ParsedStyleSheet, Position, PosixPath, Prop, Rect, RelayEnvelope, RelayPayload, ResolvedConfig, Rule, RuleContext, RuleName, RuleResult, RuleSetting, ScanError, ScanProjectOptions, ScanResult, ScanStats, ScanStylesOptions, Severity, SnoopConfig, SourceRange, Specificity, StyleDeclaration, StyleError, StyleIndex, StyleIndexer, StyleProvenance, StyleRule, StyleSource, StyleSourceKind, TailwindThemeResult, TokenTable };