@oxog/react-check 1.2.0 → 1.3.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 (64) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/README.md +177 -62
  3. package/dist/browser-inject.global.js +13 -13
  4. package/dist/chain.cjs +8 -531
  5. package/dist/chain.cjs.map +1 -1
  6. package/dist/chain.d.cts +2 -2
  7. package/dist/chain.d.ts +2 -2
  8. package/dist/chain.js +2 -533
  9. package/dist/chain.js.map +1 -1
  10. package/dist/chunk-35I3PLS3.js +751 -0
  11. package/dist/chunk-35I3PLS3.js.map +1 -0
  12. package/dist/chunk-7R4KKJTW.cjs +255 -0
  13. package/dist/chunk-7R4KKJTW.cjs.map +1 -0
  14. package/dist/chunk-DSXOHC6R.cjs +755 -0
  15. package/dist/chunk-DSXOHC6R.cjs.map +1 -0
  16. package/dist/chunk-DWM55ACO.cjs +294 -0
  17. package/dist/chunk-DWM55ACO.cjs.map +1 -0
  18. package/dist/chunk-GS7T56RP.cjs +9 -0
  19. package/dist/chunk-GS7T56RP.cjs.map +1 -0
  20. package/dist/chunk-LFY7MUHJ.cjs +483 -0
  21. package/dist/chunk-LFY7MUHJ.cjs.map +1 -0
  22. package/dist/chunk-NLWGB4IE.cjs +380 -0
  23. package/dist/chunk-NLWGB4IE.cjs.map +1 -0
  24. package/dist/chunk-PIXJPQO7.js +481 -0
  25. package/dist/chunk-PIXJPQO7.js.map +1 -0
  26. package/dist/chunk-REEPUD73.js +362 -0
  27. package/dist/chunk-REEPUD73.js.map +1 -0
  28. package/dist/chunk-RQYHXWUC.js +292 -0
  29. package/dist/chunk-RQYHXWUC.js.map +1 -0
  30. package/dist/chunk-WLN7ZVO4.js +253 -0
  31. package/dist/chunk-WLN7ZVO4.js.map +1 -0
  32. package/dist/cli.js +1195 -297
  33. package/dist/cli.js.map +1 -1
  34. package/dist/detect.cjs +22 -324
  35. package/dist/detect.cjs.map +1 -1
  36. package/dist/detect.d.cts +8 -2
  37. package/dist/detect.d.ts +8 -2
  38. package/dist/detect.js +1 -324
  39. package/dist/detect.js.map +1 -1
  40. package/dist/{event-emitter-CxKUDo9q.d.cts → event-emitter-BVYUPYLd.d.cts} +3 -2
  41. package/dist/{event-emitter-CxKUDo9q.d.ts → event-emitter-BVYUPYLd.d.ts} +3 -2
  42. package/dist/fix.cjs +6 -715
  43. package/dist/fix.cjs.map +1 -1
  44. package/dist/fix.d.cts +8 -2
  45. package/dist/fix.d.ts +8 -2
  46. package/dist/fix.js +2 -719
  47. package/dist/fix.js.map +1 -1
  48. package/dist/index.cjs +1400 -3075
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +237 -57
  51. package/dist/index.d.ts +237 -57
  52. package/dist/index.js +1222 -2970
  53. package/dist/index.js.map +1 -1
  54. package/dist/{scanner-Cc2187fH.d.ts → scanner-BJFA0354.d.ts} +33 -4
  55. package/dist/{scanner-S7BtVIpW.d.cts → scanner-DZL2rIFv.d.cts} +33 -4
  56. package/dist/scanner.cjs +8 -1652
  57. package/dist/scanner.cjs.map +1 -1
  58. package/dist/scanner.d.cts +3 -3
  59. package/dist/scanner.d.ts +3 -3
  60. package/dist/scanner.js +4 -1656
  61. package/dist/scanner.js.map +1 -1
  62. package/dist/{types-DuZyBVVV.d.cts → types-BMDemwIs.d.cts} +35 -10
  63. package/dist/{types-DuZyBVVV.d.ts → types-BMDemwIs.d.ts} +35 -10
  64. package/package.json +16 -9
@@ -0,0 +1,751 @@
1
+ import { ChainAnalyzer } from './chunk-RQYHXWUC.js';
2
+ import { FixSuggester } from './chunk-PIXJPQO7.js';
3
+ import { EventEmitter } from './chunk-WLN7ZVO4.js';
4
+
5
+ // src/core/stats.ts
6
+ var DEFAULT_THRESHOLDS = {
7
+ critical: 50,
8
+ warning: 20,
9
+ fps: 30
10
+ };
11
+ var StatsCollector = class extends EventEmitter {
12
+ /** Map of component names to their statistics */
13
+ components = /* @__PURE__ */ new Map();
14
+ /** Threshold configuration */
15
+ thresholds;
16
+ /** Session start time */
17
+ sessionStart;
18
+ /** Total render count across all components */
19
+ totalRenders = 0;
20
+ /** FPS samples for averaging */
21
+ fpsSamples = [];
22
+ /** Maximum FPS samples to keep */
23
+ maxFpsSamples = 100;
24
+ /**
25
+ * Create a new StatsCollector
26
+ * @param thresholds - Threshold configuration
27
+ */
28
+ constructor(thresholds = {}) {
29
+ super();
30
+ this.thresholds = { ...DEFAULT_THRESHOLDS, ...thresholds };
31
+ this.sessionStart = Date.now();
32
+ }
33
+ /**
34
+ * Add a render event to the statistics
35
+ * @param render - Render information
36
+ */
37
+ addRender(render) {
38
+ const stats = this.getOrCreateStats(render.componentName);
39
+ const previousSeverity = stats.severity;
40
+ stats.renders++;
41
+ this.totalRenders++;
42
+ stats.totalRenderTime += render.renderTime;
43
+ stats.avgRenderTime = stats.totalRenderTime / stats.renders;
44
+ stats.maxRenderTime = Math.max(stats.maxRenderTime, render.renderTime);
45
+ stats.minRenderTime = Math.min(stats.minRenderTime, render.renderTime);
46
+ if (!render.necessary) {
47
+ stats.unnecessary++;
48
+ }
49
+ if (stats.firstRender === 0) {
50
+ stats.firstRender = render.timestamp;
51
+ }
52
+ stats.lastRender = render.timestamp;
53
+ if (render.changedProps && render.changedProps.length > 0) {
54
+ stats.propsChanged = true;
55
+ }
56
+ if (render.changedState && render.changedState.length > 0) {
57
+ stats.stateChanged = true;
58
+ }
59
+ const sessionDuration = Date.now() - this.sessionStart;
60
+ const sessionMinutes = sessionDuration / 6e4;
61
+ stats.expectedRenders = Math.max(1, Math.ceil(sessionMinutes * 5));
62
+ this.updateSeverity(stats);
63
+ this.emit("update", stats);
64
+ if (stats.severity !== previousSeverity) {
65
+ this.emit("severityChange", {
66
+ component: stats.name,
67
+ from: previousSeverity,
68
+ to: stats.severity
69
+ });
70
+ if (stats.severity === "critical" && previousSeverity !== "critical") {
71
+ this.emit("critical", stats);
72
+ } else if (stats.severity === "warning" && previousSeverity === "healthy") {
73
+ this.emit("warning", stats);
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * Record an FPS sample
79
+ * @param fps - FPS value
80
+ */
81
+ addFpsSample(fps) {
82
+ this.fpsSamples.push(fps);
83
+ if (this.fpsSamples.length > this.maxFpsSamples) {
84
+ this.fpsSamples.shift();
85
+ }
86
+ }
87
+ /**
88
+ * Get or create stats for a component
89
+ * @param name - Component name
90
+ * @returns Component stats
91
+ */
92
+ getOrCreateStats(name) {
93
+ let stats = this.components.get(name);
94
+ if (!stats) {
95
+ stats = this.createEmptyStats(name);
96
+ this.components.set(name, stats);
97
+ }
98
+ return stats;
99
+ }
100
+ /**
101
+ * Create empty stats for a component
102
+ * @param name - Component name
103
+ * @returns Empty component stats
104
+ */
105
+ createEmptyStats(name) {
106
+ return {
107
+ name,
108
+ renders: 0,
109
+ expectedRenders: 1,
110
+ avgRenderTime: 0,
111
+ maxRenderTime: 0,
112
+ minRenderTime: Infinity,
113
+ totalRenderTime: 0,
114
+ unnecessary: 0,
115
+ severity: "healthy",
116
+ chain: [],
117
+ fixes: [],
118
+ firstRender: 0,
119
+ lastRender: 0,
120
+ propsChanged: false,
121
+ stateChanged: false
122
+ };
123
+ }
124
+ /**
125
+ * Update severity for a component based on thresholds
126
+ * @param stats - Component stats to update
127
+ */
128
+ updateSeverity(stats) {
129
+ if (stats.renders >= this.thresholds.critical) {
130
+ stats.severity = "critical";
131
+ } else if (stats.renders >= this.thresholds.warning) {
132
+ stats.severity = "warning";
133
+ } else {
134
+ stats.severity = "healthy";
135
+ }
136
+ }
137
+ /**
138
+ * Get stats for a specific component
139
+ * @param name - Component name
140
+ * @returns Component stats or undefined
141
+ */
142
+ getComponentStats(name) {
143
+ return this.components.get(name);
144
+ }
145
+ /**
146
+ * Get all component stats
147
+ * @returns Array of component stats
148
+ */
149
+ getAllStats() {
150
+ return Array.from(this.components.values());
151
+ }
152
+ /**
153
+ * Get a snapshot of all stats sorted by severity/render count
154
+ * @returns Sorted array of component stats
155
+ */
156
+ getSnapshot() {
157
+ return this.getAllStats().sort((a, b) => {
158
+ const severityOrder = {
159
+ critical: 0,
160
+ warning: 1,
161
+ info: 2,
162
+ healthy: 3
163
+ };
164
+ const severityDiff = severityOrder[a.severity] - severityOrder[b.severity];
165
+ if (severityDiff !== 0) return severityDiff;
166
+ return b.renders - a.renders;
167
+ });
168
+ }
169
+ /**
170
+ * Get components by severity
171
+ * @param severity - Severity level to filter
172
+ * @returns Array of matching component stats
173
+ */
174
+ getComponentsBySeverity(severity) {
175
+ return this.getAllStats().filter((s) => s.severity === severity);
176
+ }
177
+ /**
178
+ * Get session summary
179
+ * @returns Session summary statistics
180
+ */
181
+ getSummary() {
182
+ const stats = this.getAllStats();
183
+ const criticalCount = stats.filter((s) => s.severity === "critical").length;
184
+ const warningCount = stats.filter((s) => s.severity === "warning").length;
185
+ const healthyCount = stats.filter((s) => s.severity === "healthy").length;
186
+ const unnecessaryCount = stats.reduce((sum, s) => sum + s.unnecessary, 0);
187
+ let avgFps = 60;
188
+ let minFps = 60;
189
+ if (this.fpsSamples.length > 0) {
190
+ avgFps = this.fpsSamples.reduce((a, b) => a + b, 0) / this.fpsSamples.length;
191
+ minFps = Math.min(...this.fpsSamples);
192
+ }
193
+ return {
194
+ totalComponents: stats.length,
195
+ totalRenders: this.totalRenders,
196
+ criticalIssues: criticalCount,
197
+ warnings: warningCount,
198
+ healthy: healthyCount,
199
+ avgFps: Math.round(avgFps),
200
+ minFps: Math.round(minFps),
201
+ unnecessaryRenders: unnecessaryCount
202
+ };
203
+ }
204
+ /**
205
+ * Get the most problematic components
206
+ * @param limit - Maximum number to return
207
+ * @returns Top problematic components
208
+ */
209
+ getTopProblems(limit = 10) {
210
+ return this.getSnapshot().filter((s) => s.severity !== "healthy").slice(0, limit);
211
+ }
212
+ /**
213
+ * Update chain information for a component
214
+ * @param componentName - Component name
215
+ * @param chain - Render chain
216
+ */
217
+ setComponentChain(componentName, chain) {
218
+ const stats = this.components.get(componentName);
219
+ if (stats) {
220
+ stats.chain = chain;
221
+ }
222
+ }
223
+ /**
224
+ * Update parent information for a component
225
+ * @param componentName - Component name
226
+ * @param parentName - Parent component name
227
+ */
228
+ setComponentParent(componentName, parentName) {
229
+ const stats = this.components.get(componentName);
230
+ if (stats) {
231
+ stats.parent = parentName;
232
+ }
233
+ }
234
+ /**
235
+ * Reset all statistics
236
+ */
237
+ reset() {
238
+ this.components.clear();
239
+ this.totalRenders = 0;
240
+ this.fpsSamples = [];
241
+ this.sessionStart = Date.now();
242
+ }
243
+ /**
244
+ * Update threshold configuration
245
+ * @param thresholds - New thresholds
246
+ */
247
+ setThresholds(thresholds) {
248
+ this.thresholds = { ...this.thresholds, ...thresholds };
249
+ for (const stats of this.components.values()) {
250
+ const previousSeverity = stats.severity;
251
+ this.updateSeverity(stats);
252
+ if (stats.severity !== previousSeverity) {
253
+ this.emit("severityChange", {
254
+ component: stats.name,
255
+ from: previousSeverity,
256
+ to: stats.severity
257
+ });
258
+ }
259
+ }
260
+ }
261
+ /**
262
+ * Get current thresholds
263
+ * @returns Current threshold configuration
264
+ */
265
+ getThresholds() {
266
+ return { ...this.thresholds };
267
+ }
268
+ /**
269
+ * Get session duration in milliseconds
270
+ * @returns Session duration
271
+ */
272
+ getSessionDuration() {
273
+ return Date.now() - this.sessionStart;
274
+ }
275
+ /**
276
+ * Get total render count
277
+ * @returns Total renders across all components
278
+ */
279
+ getTotalRenders() {
280
+ return this.totalRenders;
281
+ }
282
+ /**
283
+ * Get component count
284
+ * @returns Number of tracked components
285
+ */
286
+ getComponentCount() {
287
+ return this.components.size;
288
+ }
289
+ /**
290
+ * Check if FPS is below threshold
291
+ * @returns true if average FPS is below threshold
292
+ */
293
+ isFpsBelowThreshold() {
294
+ if (this.fpsSamples.length === 0) return false;
295
+ const avgFps = this.fpsSamples.reduce((a, b) => a + b, 0) / this.fpsSamples.length;
296
+ return avgFps < this.thresholds.fps;
297
+ }
298
+ /**
299
+ * Export stats for serialization
300
+ * @returns Serializable stats object
301
+ */
302
+ export() {
303
+ return {
304
+ components: this.getSnapshot(),
305
+ summary: this.getSummary(),
306
+ thresholds: this.getThresholds(),
307
+ sessionDuration: this.getSessionDuration()
308
+ };
309
+ }
310
+ };
311
+
312
+ // src/utils/pattern.ts
313
+ function matchComponentPattern(name, pattern) {
314
+ let source = "";
315
+ let prev = "";
316
+ for (const ch of pattern) {
317
+ if (ch === "*" && prev === "*") continue;
318
+ prev = ch;
319
+ if (ch === "*") source += ".*";
320
+ else if (ch === "?") source += ".";
321
+ else source += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
322
+ }
323
+ return new RegExp(`^${source}$`).test(name);
324
+ }
325
+
326
+ // src/core/scanner.ts
327
+ function toRuleLevels(rules) {
328
+ const levels = {};
329
+ for (const [id, setting] of Object.entries(rules)) {
330
+ const level = Array.isArray(setting) ? setting[0] : setting;
331
+ if (level === "off" || level === "warn" || level === "error") {
332
+ levels[id] = level;
333
+ }
334
+ }
335
+ return levels;
336
+ }
337
+ var DEFAULT_CONFIG = {
338
+ trackUnnecessary: true,
339
+ fpsThreshold: 30,
340
+ highlightRenders: true,
341
+ animationSpeed: "fast"
342
+ };
343
+ var DEFAULT_THRESHOLDS2 = {
344
+ critical: 50,
345
+ warning: 20,
346
+ fps: 30
347
+ };
348
+ var Scanner = class extends EventEmitter {
349
+ /** Statistics collector */
350
+ stats;
351
+ /** Chain analyzer */
352
+ chainAnalyzer;
353
+ /** Fix suggester */
354
+ fixSuggester;
355
+ /** Components whose stats changed since their suggestions were last generated */
356
+ staleSuggestions = /* @__PURE__ */ new Set();
357
+ /** Scanner configuration */
358
+ config;
359
+ /** Whether scanner is currently running */
360
+ running = false;
361
+ /** Last recorded FPS */
362
+ lastFps = 60;
363
+ /** FPS tracking */
364
+ frameCount = 0;
365
+ lastFpsUpdate = 0;
366
+ fpsInterval = null;
367
+ /** Batch processing */
368
+ renderBatch = [];
369
+ batchTimeout = null;
370
+ batchSize = 10;
371
+ batchDelay = 100;
372
+ /**
373
+ * Create a new Scanner instance
374
+ * @param options - Configuration options
375
+ */
376
+ constructor(options = {}) {
377
+ super();
378
+ this.config = { ...DEFAULT_CONFIG, ...options.config };
379
+ const thresholds = { ...DEFAULT_THRESHOLDS2, ...options.thresholds };
380
+ this.stats = new StatsCollector(thresholds);
381
+ this.chainAnalyzer = new ChainAnalyzer();
382
+ this.fixSuggester = new FixSuggester(options.rules ? { rules: toRuleLevels(options.rules) } : {});
383
+ this.setupEventForwarding();
384
+ }
385
+ /**
386
+ * Set up event forwarding from sub-modules
387
+ */
388
+ setupEventForwarding() {
389
+ this.stats.on("update", (stats) => {
390
+ this.staleSuggestions.add(stats.name);
391
+ this.emit("stats", stats);
392
+ });
393
+ this.stats.on("severityChange", (change) => {
394
+ this.emit("severityChange", change);
395
+ const stats = this.stats.getComponentStats(change.component);
396
+ if (stats && (change.to === "critical" || change.to === "warning")) {
397
+ const suggestions = this.fixSuggester.analyze(stats);
398
+ for (const suggestion of suggestions) {
399
+ this.emit("fix", suggestion);
400
+ }
401
+ }
402
+ });
403
+ this.chainAnalyzer.on("chain", (chain) => {
404
+ this.emit("chain", chain);
405
+ for (const componentName of chain.chain) {
406
+ this.stats.setComponentChain(componentName, chain.chain);
407
+ }
408
+ });
409
+ }
410
+ /**
411
+ * Start the scanner
412
+ */
413
+ start() {
414
+ if (this.running) return;
415
+ this.running = true;
416
+ this.lastFpsUpdate = Date.now();
417
+ this.frameCount = 0;
418
+ this.startFpsMonitoring();
419
+ this.emit("start", void 0);
420
+ }
421
+ /**
422
+ * Stop the scanner
423
+ */
424
+ stop() {
425
+ if (!this.running) return;
426
+ this.running = false;
427
+ this.stopFpsMonitoring();
428
+ this.flushBatch();
429
+ this.emit("stop", void 0);
430
+ }
431
+ /**
432
+ * Reset the scanner, clearing all data
433
+ */
434
+ reset() {
435
+ this.stop();
436
+ this.stats.reset();
437
+ this.chainAnalyzer.reset();
438
+ this.fixSuggester.clearSuggestions();
439
+ this.staleSuggestions.clear();
440
+ this.renderBatch = [];
441
+ this.emit("reset", void 0);
442
+ }
443
+ /**
444
+ * Process a render event
445
+ * @param render - Render information
446
+ * @param parent - Optional parent component name (defaults to `render.parent`,
447
+ * which the injected browser script fills in from the fiber tree)
448
+ */
449
+ addRender(render, parent) {
450
+ if (!this.running) return;
451
+ if (!this.isComponentIncluded(render.componentName)) return;
452
+ const parentName = parent ?? (typeof render.parent === "string" && render.parent !== "" ? render.parent : void 0);
453
+ this.renderBatch.push(render);
454
+ this.stats.addRender(render);
455
+ if (parentName !== void 0) {
456
+ this.stats.setComponentParent(render.componentName, parentName);
457
+ }
458
+ this.chainAnalyzer.addRender(render, parentName);
459
+ this.emit("render", render);
460
+ this.scheduleBatchProcessing();
461
+ }
462
+ /**
463
+ * Check a component name against the configured include/exclude patterns
464
+ * @param name - Component name
465
+ * @returns true if renders of this component should be tracked
466
+ */
467
+ isComponentIncluded(name) {
468
+ const { include, exclude } = this.config;
469
+ if (include && include.length > 0 && !include.some((p) => matchComponentPattern(name, p))) {
470
+ return false;
471
+ }
472
+ if (exclude && exclude.length > 0 && exclude.some((p) => matchComponentPattern(name, p))) {
473
+ return false;
474
+ }
475
+ return true;
476
+ }
477
+ /**
478
+ * Record a painted frame for FPS calculation (the scanner derives FPS from
479
+ * frames recorded during each one-second window)
480
+ */
481
+ recordFrame() {
482
+ this.frameCount++;
483
+ }
484
+ /**
485
+ * Record an FPS sample measured elsewhere (e.g. by requestAnimationFrame in
486
+ * the browser)
487
+ * @param fps - Frames per second
488
+ */
489
+ recordFps(fps) {
490
+ if (!this.running || !Number.isFinite(fps) || fps < 0) return;
491
+ this.lastFps = Math.round(fps);
492
+ this.stats.addFpsSample(this.lastFps);
493
+ if (this.lastFps < this.getFpsThreshold()) {
494
+ this.emit("fps-drop", this.lastFps);
495
+ }
496
+ }
497
+ /**
498
+ * FPS threshold below which `fps-drop` is emitted
499
+ * @returns Threshold
500
+ */
501
+ getFpsThreshold() {
502
+ return this.stats.getThresholds().fps ?? this.config.fpsThreshold;
503
+ }
504
+ /**
505
+ * Schedule batch processing
506
+ */
507
+ scheduleBatchProcessing() {
508
+ if (this.batchTimeout) return;
509
+ if (this.renderBatch.length >= this.batchSize) {
510
+ this.flushBatch();
511
+ } else {
512
+ this.batchTimeout = setTimeout(() => {
513
+ this.flushBatch();
514
+ }, this.batchDelay);
515
+ const timer = this.batchTimeout;
516
+ timer.unref?.();
517
+ }
518
+ }
519
+ /**
520
+ * Flush the render batch
521
+ */
522
+ flushBatch() {
523
+ if (this.batchTimeout) {
524
+ clearTimeout(this.batchTimeout);
525
+ this.batchTimeout = null;
526
+ }
527
+ if (this.renderBatch.length === 0) return;
528
+ this.processBatch(this.renderBatch);
529
+ this.renderBatch = [];
530
+ }
531
+ /**
532
+ * Process a batch of renders for patterns
533
+ * @param batch - Render batch
534
+ */
535
+ processBatch(batch) {
536
+ const byComponent = /* @__PURE__ */ new Map();
537
+ for (const render of batch) {
538
+ const existing = byComponent.get(render.componentName) ?? [];
539
+ existing.push(render);
540
+ byComponent.set(render.componentName, existing);
541
+ }
542
+ for (const [componentName, renders] of byComponent) {
543
+ if (renders.length >= 3) {
544
+ const stats = this.stats.getComponentStats(componentName);
545
+ if (stats) {
546
+ const suggestions = this.fixSuggester.analyze(stats);
547
+ for (const suggestion of suggestions) {
548
+ this.emit("fix", suggestion);
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+ /**
555
+ * Start FPS monitoring
556
+ */
557
+ startFpsMonitoring() {
558
+ this.fpsInterval = setInterval(() => {
559
+ const now = Date.now();
560
+ const elapsed = now - this.lastFpsUpdate;
561
+ const frames = this.frameCount;
562
+ this.frameCount = 0;
563
+ this.lastFpsUpdate = now;
564
+ if (elapsed > 0 && frames > 0) {
565
+ this.recordFps(frames * 1e3 / elapsed);
566
+ }
567
+ }, 1e3);
568
+ const interval = this.fpsInterval;
569
+ interval.unref?.();
570
+ }
571
+ /**
572
+ * Stop FPS monitoring
573
+ */
574
+ stopFpsMonitoring() {
575
+ if (this.fpsInterval) {
576
+ clearInterval(this.fpsInterval);
577
+ this.fpsInterval = null;
578
+ }
579
+ }
580
+ /**
581
+ * Get current FPS
582
+ * @returns Current FPS value
583
+ */
584
+ getFps() {
585
+ return this.lastFps;
586
+ }
587
+ /**
588
+ * Check if scanner is running
589
+ * @returns true if running
590
+ */
591
+ isRunning() {
592
+ return this.running;
593
+ }
594
+ /**
595
+ * Get scanner configuration
596
+ * @returns Current configuration
597
+ */
598
+ getConfig() {
599
+ return { ...this.config };
600
+ }
601
+ /**
602
+ * Update scanner configuration
603
+ * @param config - Partial configuration to update
604
+ */
605
+ configure(config) {
606
+ this.config = { ...this.config, ...config };
607
+ }
608
+ /**
609
+ * Update threshold configuration
610
+ * @param thresholds - New thresholds
611
+ */
612
+ setThresholds(thresholds) {
613
+ this.stats.setThresholds(thresholds);
614
+ }
615
+ /**
616
+ * Get current thresholds
617
+ * @returns Current threshold configuration
618
+ */
619
+ getThresholds() {
620
+ return this.stats.getThresholds();
621
+ }
622
+ /**
623
+ * Get component statistics
624
+ * @param name - Component name (optional, returns all if not specified)
625
+ * @returns Component stats
626
+ */
627
+ getStats(name) {
628
+ if (name) {
629
+ return this.stats.getComponentStats(name);
630
+ }
631
+ return this.stats.getAllStats();
632
+ }
633
+ /**
634
+ * Get a snapshot of all stats sorted by severity
635
+ * @returns Sorted stats array
636
+ */
637
+ getSnapshot() {
638
+ return this.stats.getSnapshot();
639
+ }
640
+ /**
641
+ * Get session summary
642
+ * @returns Session summary statistics
643
+ */
644
+ getSummary() {
645
+ return this.stats.getSummary();
646
+ }
647
+ /**
648
+ * Get top problematic components
649
+ * @param limit - Maximum number to return
650
+ * @returns Top problems
651
+ */
652
+ getTopProblems(limit = 10) {
653
+ return this.stats.getTopProblems(limit);
654
+ }
655
+ /**
656
+ * Get all fix suggestions
657
+ * @returns All suggestions
658
+ */
659
+ getSuggestions() {
660
+ this.refreshSuggestions();
661
+ return this.fixSuggester.getAllSuggestions();
662
+ }
663
+ /**
664
+ * Re-generate cached suggestions whose component received renders since they
665
+ * were created, so their text, numbers and severity match the current stats
666
+ * @param componentName - Only refresh this component (all when omitted)
667
+ */
668
+ refreshSuggestions(componentName) {
669
+ const names = componentName !== void 0 ? [componentName] : [...this.staleSuggestions];
670
+ for (const name of names) {
671
+ if (!this.staleSuggestions.has(name)) continue;
672
+ this.staleSuggestions.delete(name);
673
+ if (!this.fixSuggester.hasSuggestions(name)) continue;
674
+ const stats = this.stats.getComponentStats(name);
675
+ if (stats) {
676
+ this.fixSuggester.analyze(stats);
677
+ }
678
+ }
679
+ }
680
+ /**
681
+ * Get suggestions for a specific component
682
+ * @param componentName - Component name
683
+ * @returns Component suggestions
684
+ */
685
+ getComponentSuggestions(componentName) {
686
+ this.refreshSuggestions(componentName);
687
+ return this.fixSuggester.getSuggestions(componentName);
688
+ }
689
+ /**
690
+ * Set parent relationship for a component
691
+ * @param child - Child component name
692
+ * @param parent - Parent component name
693
+ */
694
+ setParent(child, parent) {
695
+ this.chainAnalyzer.setParent(child, parent);
696
+ this.stats.setComponentParent(child, parent);
697
+ }
698
+ /**
699
+ * Get the render chain for a component
700
+ * @param componentName - Component name
701
+ * @returns Render chain
702
+ */
703
+ getComponentChain(componentName) {
704
+ return this.chainAnalyzer.getComponentChain(componentName);
705
+ }
706
+ /**
707
+ * Get session duration
708
+ * @returns Duration in milliseconds
709
+ */
710
+ getSessionDuration() {
711
+ return this.stats.getSessionDuration();
712
+ }
713
+ /**
714
+ * Export scanner data for reporting
715
+ * @returns Exportable data object
716
+ */
717
+ export() {
718
+ return {
719
+ stats: this.stats.export(),
720
+ suggestions: this.getSuggestions(),
721
+ config: this.getConfig()
722
+ };
723
+ }
724
+ /**
725
+ * Analyze a specific component and generate suggestions
726
+ * @param componentName - Component name
727
+ * @returns Fix suggestions for the component
728
+ */
729
+ analyzeComponent(componentName) {
730
+ const stats = this.stats.getComponentStats(componentName);
731
+ if (!stats) return [];
732
+ return this.fixSuggester.analyze(stats);
733
+ }
734
+ /**
735
+ * Analyze all components and generate suggestions
736
+ * @returns All fix suggestions
737
+ */
738
+ analyzeAll() {
739
+ const allStats = this.stats.getAllStats();
740
+ const allSuggestions = [];
741
+ for (const stats of allStats) {
742
+ const suggestions = this.fixSuggester.analyze(stats);
743
+ allSuggestions.push(...suggestions);
744
+ }
745
+ return allSuggestions;
746
+ }
747
+ };
748
+
749
+ export { Scanner, StatsCollector, matchComponentPattern };
750
+ //# sourceMappingURL=chunk-35I3PLS3.js.map
751
+ //# sourceMappingURL=chunk-35I3PLS3.js.map