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