@oxog/react-check 1.1.0 → 1.1.2

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.
package/dist/index.js CHANGED
@@ -737,6 +737,8 @@ var init_browser = __esm({
737
737
  "--disable-setuid-sandbox",
738
738
  "--disable-dev-shm-usage",
739
739
  "--disable-gpu",
740
+ "--ignore-certificate-errors",
741
+ "--ignore-certificate-errors-spki-list",
740
742
  `--window-size=${this.options.width},${this.options.height}`,
741
743
  ...this.options.args
742
744
  ];
@@ -793,25 +795,37 @@ var init_browser = __esm({
793
795
  });
794
796
  }
795
797
  /**
796
- * Navigate to a URL
798
+ * Navigate to a URL with retry support
797
799
  * @param url - URL to navigate to
800
+ * @param retries - Number of retries (default: 3)
801
+ * @param retryDelay - Delay between retries in ms (default: 2000)
798
802
  */
799
- async navigate(url) {
803
+ async navigate(url, retries = 3, retryDelay = 2e3) {
800
804
  if (!this.page) {
801
805
  throw new Error("Browser not launched");
802
806
  }
803
- try {
804
- await this.page.goto(url, {
805
- waitUntil: "networkidle2",
806
- timeout: this.options.timeout
807
- });
808
- this.emit("navigated", { url });
809
- logger3.info(`Navigated to ${url}`);
810
- } catch (error) {
811
- const err = error instanceof Error ? error : new Error(String(error));
812
- this.emit("error", err);
813
- throw err;
807
+ let lastError = null;
808
+ for (let attempt = 1; attempt <= retries; attempt++) {
809
+ try {
810
+ await this.page.goto(url, {
811
+ waitUntil: "networkidle2",
812
+ timeout: this.options.timeout
813
+ });
814
+ this.emit("navigated", { url });
815
+ logger3.info(`Navigated to ${url}`);
816
+ return;
817
+ } catch (error) {
818
+ lastError = error instanceof Error ? error : new Error(String(error));
819
+ this.emit("error", lastError);
820
+ if (lastError.message.includes("ERR_CONNECTION_REFUSED") && attempt < retries) {
821
+ logger3.warn(`Connection refused, retrying in ${retryDelay}ms... (${attempt}/${retries})`);
822
+ await new Promise((resolve2) => setTimeout(resolve2, retryDelay));
823
+ continue;
824
+ }
825
+ throw lastError;
826
+ }
814
827
  }
828
+ throw lastError ?? new Error("Navigation failed");
815
829
  }
816
830
  /**
817
831
  * Execute script in page context
@@ -4552,348 +4566,103 @@ init_browser();
4552
4566
 
4553
4567
  // src/browser/scanner.ts
4554
4568
  init_event_emitter();
4569
+
4570
+ // src/browser/overlay.ts
4555
4571
  var DEFAULT_CONFIG2 = {
4556
- trackUnnecessary: true,
4557
- fpsThreshold: 30,
4572
+ enabled: true,
4558
4573
  highlightRenders: true,
4559
- animationSpeed: "fast"
4574
+ animationSpeed: "fast",
4575
+ showBadges: true,
4576
+ showToolbar: true
4560
4577
  };
4561
- var BrowserScanner = class extends EventEmitter {
4562
- /** Scanner configuration */
4578
+ var SEVERITY_COLORS = {
4579
+ critical: "#ef4444",
4580
+ warning: "#eab308",
4581
+ info: "#3b82f6",
4582
+ healthy: "#22c55e",
4583
+ unnecessary: "#6b7280"
4584
+ };
4585
+ var ANIMATION_DURATIONS = {
4586
+ slow: 1e3,
4587
+ fast: 300,
4588
+ off: 0
4589
+ };
4590
+ var FLASH_COLORS = {
4591
+ critical: "rgba(239, 68, 68, 0.35)",
4592
+ warning: "rgba(234, 179, 8, 0.3)",
4593
+ info: "rgba(59, 130, 246, 0.25)",
4594
+ healthy: "rgba(34, 197, 94, 0.2)",
4595
+ unnecessary: "rgba(107, 114, 128, 0.15)"
4596
+ };
4597
+ var Overlay = class {
4598
+ /** Shadow root for isolation */
4599
+ shadowRoot = null;
4600
+ /** Host element */
4601
+ host = null;
4602
+ /** Overlay configuration */
4563
4603
  config;
4564
- /** Whether scanner is running */
4565
- running = false;
4566
- /** React version detected */
4567
- reactVersion = "unknown";
4568
- /** Previous fiber states for comparison */
4569
- prevFiberStates = /* @__PURE__ */ new WeakMap();
4570
- /** Component render counts */
4604
+ /** Highlight elements */
4605
+ highlights = /* @__PURE__ */ new Map();
4606
+ /** Badge elements */
4607
+ badges = /* @__PURE__ */ new Map();
4608
+ /** Render counts for badges */
4571
4609
  renderCounts = /* @__PURE__ */ new Map();
4572
- /** Original DevTools hook methods */
4573
- originalOnCommitFiberRoot = null;
4574
- /** Window reference */
4575
- win;
4610
+ /** Toolbar element */
4611
+ toolbar = null;
4612
+ /** Whether overlay is visible */
4613
+ visible = true;
4576
4614
  /**
4577
- * Create a new browser scanner
4578
- * @param config - Scanner configuration
4579
- * @param win - Window object (for testing)
4615
+ * Create a new overlay
4616
+ * @param config - Overlay configuration
4580
4617
  */
4581
- constructor(config = {}, win) {
4582
- super();
4618
+ constructor(config = {}) {
4583
4619
  this.config = { ...DEFAULT_CONFIG2, ...config };
4584
- this.win = win ?? (typeof window !== "undefined" ? window : {});
4585
4620
  }
4586
4621
  /**
4587
- * Start the scanner
4622
+ * Initialize the overlay
4588
4623
  */
4589
- start() {
4590
- if (this.running) return;
4591
- try {
4592
- this.hookIntoReact();
4593
- this.running = true;
4594
- } catch (error) {
4595
- this.emit("error", error instanceof Error ? error : new Error(String(error)));
4624
+ init() {
4625
+ this.host = document.createElement("div");
4626
+ this.host.id = "reactcheck-overlay-host";
4627
+ this.host.style.cssText = `
4628
+ position: fixed;
4629
+ top: 0;
4630
+ left: 0;
4631
+ width: 100%;
4632
+ height: 100%;
4633
+ pointer-events: none;
4634
+ z-index: 2147483647;
4635
+ `;
4636
+ this.shadowRoot = this.host.attachShadow({ mode: "closed" });
4637
+ this.injectStyles();
4638
+ if (this.config.showToolbar) {
4639
+ this.createToolbar();
4596
4640
  }
4641
+ document.body.appendChild(this.host);
4597
4642
  }
4598
4643
  /**
4599
- * Stop the scanner
4600
- */
4601
- stop() {
4602
- if (!this.running) return;
4603
- this.unhookFromReact();
4604
- this.running = false;
4605
- }
4606
- /**
4607
- * Reset the scanner state
4644
+ * Destroy the overlay
4608
4645
  */
4609
- reset() {
4646
+ destroy() {
4647
+ this.highlights.clear();
4648
+ this.badges.clear();
4610
4649
  this.renderCounts.clear();
4611
- this.prevFiberStates = /* @__PURE__ */ new WeakMap();
4612
- }
4613
- /**
4614
- * Hook into React DevTools global hook
4615
- */
4616
- hookIntoReact() {
4617
- const hook = this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
4618
- if (!hook) {
4619
- this.installHook();
4620
- return;
4650
+ if (this.host) {
4651
+ this.host.remove();
4652
+ this.host = null;
4621
4653
  }
4622
- this.originalOnCommitFiberRoot = hook.onCommitFiberRoot.bind(hook);
4623
- hook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
4624
- if (this.originalOnCommitFiberRoot) {
4625
- this.originalOnCommitFiberRoot(rendererID, root, priorityLevel);
4626
- }
4627
- this.processCommit(root.current);
4628
- };
4629
- this.reactVersion = this.detectReactVersion(hook);
4630
- this.emit("ready", { reactVersion: this.reactVersion });
4654
+ this.shadowRoot = null;
4655
+ this.toolbar = null;
4631
4656
  }
4632
4657
  /**
4633
- * Install our own hook if DevTools hook is not present
4658
+ * Inject CSS styles into shadow DOM
4634
4659
  */
4635
- installHook() {
4636
- const hook = {
4637
- renderers: /* @__PURE__ */ new Map(),
4638
- supportsFiber: true,
4639
- inject: (renderer) => {
4640
- const id = hook.renderers.size + 1;
4641
- hook.renderers.set(id, renderer);
4642
- return id;
4643
- },
4644
- onCommitFiberRoot: (_rendererID, root, _priorityLevel) => {
4645
- this.processCommit(root.current);
4646
- },
4647
- onCommitFiberUnmount: () => {
4648
- }
4649
- };
4650
- this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
4651
- this.emit("ready", { reactVersion: "unknown (hook installed)" });
4652
- }
4653
- /**
4654
- * Unhook from React
4655
- */
4656
- unhookFromReact() {
4657
- const hook = this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
4658
- if (hook && this.originalOnCommitFiberRoot) {
4659
- hook.onCommitFiberRoot = this.originalOnCommitFiberRoot;
4660
- this.originalOnCommitFiberRoot = null;
4661
- }
4662
- }
4663
- /**
4664
- * Detect React version from hook
4665
- * @param hook - DevTools hook
4666
- * @returns React version string
4667
- */
4668
- detectReactVersion(hook) {
4669
- if (hook.renderers.size === 0) {
4670
- return "unknown";
4671
- }
4672
- const renderer = hook.renderers.values().next().value;
4673
- if (renderer && typeof renderer === "object" && "version" in renderer) {
4674
- return String(renderer.version);
4675
- }
4676
- return "unknown";
4677
- }
4678
- /**
4679
- * Process a fiber commit
4680
- * @param rootFiber - Root fiber of the committed tree
4681
- */
4682
- processCommit(rootFiber) {
4683
- this.walkFiber(rootFiber, null);
4684
- }
4685
- /**
4686
- * Walk the fiber tree
4687
- * @param fiber - Current fiber
4688
- * @param parent - Parent component name
4689
- */
4690
- walkFiber(fiber, parent) {
4691
- if (!fiber) return;
4692
- if (isUserComponent(fiber)) {
4693
- this.processFiber(fiber, parent);
4694
- parent = getComponentName(fiber);
4695
- }
4696
- this.walkFiber(fiber.child, parent);
4697
- this.walkFiber(fiber.sibling, parent);
4698
- }
4699
- /**
4700
- * Process a single fiber
4701
- * @param fiber - Fiber to process
4702
- * @param parent - Parent component name
4703
- */
4704
- processFiber(fiber, _parent) {
4705
- const componentName = getComponentName(fiber);
4706
- if (this.shouldFilterComponent(componentName)) {
4707
- return;
4708
- }
4709
- const prevState = this.prevFiberStates.get(fiber);
4710
- const phase = prevState ? "update" : "mount";
4711
- const renderInfo = createRenderInfo(
4712
- fiber,
4713
- phase,
4714
- prevState?.props,
4715
- prevState?.state
4716
- );
4717
- const currentCount = this.renderCounts.get(componentName) ?? 0;
4718
- const newCount = currentCount + 1;
4719
- this.renderCounts.set(componentName, newCount);
4720
- renderInfo.renderCount = newCount;
4721
- this.prevFiberStates.set(fiber, {
4722
- props: fiber.memoizedProps,
4723
- state: fiber.memoizedState
4724
- });
4725
- this.emit("render", renderInfo);
4726
- }
4727
- /**
4728
- * Check if component should be filtered out
4729
- * @param name - Component name
4730
- * @returns true if should be filtered
4731
- */
4732
- shouldFilterComponent(name) {
4733
- if (name.startsWith("__")) return true;
4734
- if (name === "Fragment") return true;
4735
- if (name === "Suspense") return true;
4736
- if (name === "Profiler") return true;
4737
- const { include, exclude } = this.config;
4738
- if (include && include.length > 0) {
4739
- const included = include.some((pattern) => this.matchPattern(name, pattern));
4740
- if (!included) return true;
4741
- }
4742
- if (exclude && exclude.length > 0) {
4743
- const excluded = exclude.some((pattern) => this.matchPattern(name, pattern));
4744
- if (excluded) return true;
4745
- }
4746
- return false;
4747
- }
4748
- /**
4749
- * Simple glob pattern matching
4750
- * @param name - Component name
4751
- * @param pattern - Glob pattern
4752
- * @returns true if matches
4753
- */
4754
- matchPattern(name, pattern) {
4755
- const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
4756
- try {
4757
- const regex = new RegExp(`^${regexPattern}$`);
4758
- return regex.test(name);
4759
- } catch {
4760
- return false;
4761
- }
4762
- }
4763
- /**
4764
- * Get current configuration
4765
- * @returns Scanner configuration
4766
- */
4767
- getConfig() {
4768
- return { ...this.config };
4769
- }
4770
- /**
4771
- * Update configuration
4772
- * @param config - Partial configuration
4773
- */
4774
- configure(config) {
4775
- this.config = { ...this.config, ...config };
4776
- }
4777
- /**
4778
- * Check if scanner is running
4779
- * @returns true if running
4780
- */
4781
- isRunning() {
4782
- return this.running;
4783
- }
4784
- /**
4785
- * Get detected React version
4786
- * @returns React version string
4787
- */
4788
- getReactVersion() {
4789
- return this.reactVersion;
4790
- }
4791
- /**
4792
- * Get render count for a component
4793
- * @param name - Component name
4794
- * @returns Render count
4795
- */
4796
- getRenderCount(name) {
4797
- return this.renderCounts.get(name) ?? 0;
4798
- }
4799
- /**
4800
- * Get all render counts
4801
- * @returns Map of component names to render counts
4802
- */
4803
- getAllRenderCounts() {
4804
- return new Map(this.renderCounts);
4805
- }
4806
- };
4807
-
4808
- // src/browser/overlay.ts
4809
- var DEFAULT_CONFIG3 = {
4810
- enabled: true,
4811
- highlightRenders: true,
4812
- animationSpeed: "fast",
4813
- showBadges: true,
4814
- showToolbar: true
4815
- };
4816
- var SEVERITY_COLORS = {
4817
- critical: "#ef4444",
4818
- warning: "#eab308",
4819
- info: "#3b82f6",
4820
- healthy: "#22c55e",
4821
- unnecessary: "#6b7280"
4822
- };
4823
- var ANIMATION_DURATIONS = {
4824
- slow: 1e3,
4825
- fast: 300,
4826
- off: 0
4827
- };
4828
- var Overlay = class {
4829
- /** Shadow root for isolation */
4830
- shadowRoot = null;
4831
- /** Host element */
4832
- host = null;
4833
- /** Overlay configuration */
4834
- config;
4835
- /** Highlight elements */
4836
- highlights = /* @__PURE__ */ new Map();
4837
- /** Badge elements */
4838
- badges = /* @__PURE__ */ new Map();
4839
- /** Render counts for badges */
4840
- renderCounts = /* @__PURE__ */ new Map();
4841
- /** Toolbar element */
4842
- toolbar = null;
4843
- /** Whether overlay is visible */
4844
- visible = true;
4845
- /**
4846
- * Create a new overlay
4847
- * @param config - Overlay configuration
4848
- */
4849
- constructor(config = {}) {
4850
- this.config = { ...DEFAULT_CONFIG3, ...config };
4851
- }
4852
- /**
4853
- * Initialize the overlay
4854
- */
4855
- init() {
4856
- this.host = document.createElement("div");
4857
- this.host.id = "reactcheck-overlay-host";
4858
- this.host.style.cssText = `
4859
- position: fixed;
4860
- top: 0;
4861
- left: 0;
4862
- width: 100%;
4863
- height: 100%;
4864
- pointer-events: none;
4865
- z-index: 2147483647;
4866
- `;
4867
- this.shadowRoot = this.host.attachShadow({ mode: "closed" });
4868
- this.injectStyles();
4869
- if (this.config.showToolbar) {
4870
- this.createToolbar();
4871
- }
4872
- document.body.appendChild(this.host);
4873
- }
4874
- /**
4875
- * Destroy the overlay
4876
- */
4877
- destroy() {
4878
- this.highlights.clear();
4879
- this.badges.clear();
4880
- this.renderCounts.clear();
4881
- if (this.host) {
4882
- this.host.remove();
4883
- this.host = null;
4884
- }
4885
- this.shadowRoot = null;
4886
- this.toolbar = null;
4887
- }
4888
- /**
4889
- * Inject CSS styles into shadow DOM
4890
- */
4891
- injectStyles() {
4892
- if (!this.shadowRoot) return;
4893
- const style = document.createElement("style");
4894
- style.textContent = `
4895
- * {
4896
- box-sizing: border-box;
4660
+ injectStyles() {
4661
+ if (!this.shadowRoot) return;
4662
+ const style = document.createElement("style");
4663
+ style.textContent = `
4664
+ * {
4665
+ box-sizing: border-box;
4897
4666
  }
4898
4667
 
4899
4668
  .highlight {
@@ -4901,12 +4670,65 @@ var Overlay = class {
4901
4670
  pointer-events: none;
4902
4671
  border-width: 2px;
4903
4672
  border-style: solid;
4904
- transition: opacity 0.3s ease-out;
4905
4673
  z-index: 1;
4674
+ animation: highlight-pulse 0.5s ease-out;
4906
4675
  }
4907
4676
 
4908
4677
  .highlight.fade {
4909
4678
  opacity: 0;
4679
+ transition: opacity 0.3s ease-out;
4680
+ }
4681
+
4682
+ .flash-overlay {
4683
+ position: fixed;
4684
+ pointer-events: none;
4685
+ z-index: 0;
4686
+ animation: flash-pulse 0.4s ease-out forwards;
4687
+ border-radius: 4px;
4688
+ }
4689
+
4690
+ @keyframes flash-pulse {
4691
+ 0% {
4692
+ opacity: 1;
4693
+ transform: scale(1);
4694
+ }
4695
+ 50% {
4696
+ opacity: 0.8;
4697
+ transform: scale(1.02);
4698
+ }
4699
+ 100% {
4700
+ opacity: 0;
4701
+ transform: scale(1);
4702
+ }
4703
+ }
4704
+
4705
+ @keyframes highlight-pulse {
4706
+ 0% {
4707
+ opacity: 0;
4708
+ box-shadow: 0 0 0 0 currentColor;
4709
+ }
4710
+ 30% {
4711
+ opacity: 1;
4712
+ box-shadow: 0 0 8px 2px currentColor;
4713
+ }
4714
+ 100% {
4715
+ opacity: 1;
4716
+ box-shadow: 0 0 0 0 transparent;
4717
+ }
4718
+ }
4719
+
4720
+ @keyframes badge-pop {
4721
+ 0% {
4722
+ transform: scale(0.8);
4723
+ opacity: 0;
4724
+ }
4725
+ 50% {
4726
+ transform: scale(1.1);
4727
+ }
4728
+ 100% {
4729
+ transform: scale(1);
4730
+ opacity: 1;
4731
+ }
4910
4732
  }
4911
4733
 
4912
4734
  .badge {
@@ -5124,7 +4946,7 @@ var Overlay = class {
5124
4946
  });
5125
4947
  }
5126
4948
  /**
5127
- * Highlight a component render
4949
+ * Highlight a component render with flash effect
5128
4950
  * @param render - Render information
5129
4951
  * @param element - DOM element to highlight
5130
4952
  */
@@ -5133,7 +4955,9 @@ var Overlay = class {
5133
4955
  const rect = element.getBoundingClientRect();
5134
4956
  if (rect.width === 0 || rect.height === 0) return;
5135
4957
  const severity = this.getSeverity(render);
5136
- const color = SEVERITY_COLORS[severity];
4958
+ const borderColor = SEVERITY_COLORS[severity];
4959
+ const flashColor = FLASH_COLORS[severity];
4960
+ this.createFlashOverlay(rect, flashColor);
5137
4961
  let highlight = this.highlights.get(render.componentName);
5138
4962
  if (!highlight) {
5139
4963
  highlight = document.createElement("div");
@@ -5141,15 +4965,20 @@ var Overlay = class {
5141
4965
  this.shadowRoot.appendChild(highlight);
5142
4966
  this.highlights.set(render.componentName, highlight);
5143
4967
  }
4968
+ highlight.style.animation = "none";
4969
+ highlight.offsetHeight;
4970
+ highlight.style.animation = "";
5144
4971
  highlight.style.cssText = `
5145
4972
  position: fixed;
5146
4973
  left: ${rect.left}px;
5147
4974
  top: ${rect.top}px;
5148
4975
  width: ${rect.width}px;
5149
4976
  height: ${rect.height}px;
5150
- border: 2px solid ${color};
4977
+ border: 2px solid ${borderColor};
4978
+ color: ${borderColor};
5151
4979
  pointer-events: none;
5152
4980
  z-index: 1;
4981
+ animation: highlight-pulse 0.5s ease-out;
5153
4982
  `;
5154
4983
  highlight.classList.remove("fade");
5155
4984
  const duration = ANIMATION_DURATIONS[this.config.animationSpeed];
@@ -5159,10 +4988,31 @@ var Overlay = class {
5159
4988
  }, duration);
5160
4989
  }
5161
4990
  if (this.config.showBadges) {
5162
- this.updateBadge(render, rect, color);
4991
+ this.updateBadge(render, rect, borderColor);
5163
4992
  }
5164
4993
  this.updateStats();
5165
4994
  }
4995
+ /**
4996
+ * Create a flash overlay effect on the element
4997
+ * @param rect - Element bounding rectangle
4998
+ * @param color - Flash color
4999
+ */
5000
+ createFlashOverlay(rect, color) {
5001
+ if (!this.shadowRoot) return;
5002
+ const flash = document.createElement("div");
5003
+ flash.className = "flash-overlay";
5004
+ flash.style.cssText = `
5005
+ left: ${rect.left}px;
5006
+ top: ${rect.top}px;
5007
+ width: ${rect.width}px;
5008
+ height: ${rect.height}px;
5009
+ background: ${color};
5010
+ `;
5011
+ this.shadowRoot.appendChild(flash);
5012
+ setTimeout(() => {
5013
+ flash.remove();
5014
+ }, 500);
5015
+ }
5166
5016
  /**
5167
5017
  * Update or create a badge for a component
5168
5018
  * @param render - Render information
@@ -5180,6 +5030,7 @@ var Overlay = class {
5180
5030
  this.shadowRoot.appendChild(badge);
5181
5031
  this.badges.set(render.componentName, badge);
5182
5032
  }
5033
+ const isNewBadge = !this.badges.has(render.componentName);
5183
5034
  badge.textContent = `${render.componentName}: ${count}`;
5184
5035
  badge.style.cssText = `
5185
5036
  position: fixed;
@@ -5195,7 +5046,14 @@ var Overlay = class {
5195
5046
  pointer-events: none;
5196
5047
  z-index: 2;
5197
5048
  white-space: nowrap;
5049
+ ${isNewBadge ? "animation: badge-pop 0.3s ease-out;" : ""}
5198
5050
  `;
5051
+ if (!isNewBadge) {
5052
+ badge.style.transform = "scale(1.15)";
5053
+ setTimeout(() => {
5054
+ if (badge) badge.style.transform = "scale(1)";
5055
+ }, 150);
5056
+ }
5199
5057
  }
5200
5058
  /**
5201
5059
  * Get severity level for a render
@@ -5314,6 +5172,331 @@ var Overlay = class {
5314
5172
  }
5315
5173
  };
5316
5174
 
5175
+ // src/browser/scanner.ts
5176
+ var DEFAULT_CONFIG3 = {
5177
+ trackUnnecessary: true,
5178
+ fpsThreshold: 30,
5179
+ highlightRenders: true,
5180
+ animationSpeed: "fast"
5181
+ };
5182
+ var BrowserScanner = class extends EventEmitter {
5183
+ /** Scanner configuration */
5184
+ config;
5185
+ /** Whether scanner is running */
5186
+ running = false;
5187
+ /** React version detected */
5188
+ reactVersion = "unknown";
5189
+ /** Previous fiber states for comparison */
5190
+ prevFiberStates = /* @__PURE__ */ new WeakMap();
5191
+ /** Component render counts */
5192
+ renderCounts = /* @__PURE__ */ new Map();
5193
+ /** Original DevTools hook methods */
5194
+ originalOnCommitFiberRoot = null;
5195
+ /** Window reference */
5196
+ win;
5197
+ /** Overlay for visual feedback */
5198
+ overlay = null;
5199
+ /**
5200
+ * Create a new browser scanner
5201
+ * @param config - Scanner configuration
5202
+ * @param win - Window object (for testing)
5203
+ */
5204
+ constructor(config = {}, win) {
5205
+ super();
5206
+ this.config = { ...DEFAULT_CONFIG3, ...config };
5207
+ this.win = win ?? (typeof window !== "undefined" ? window : {});
5208
+ }
5209
+ /**
5210
+ * Get DOM element from fiber node
5211
+ * React stores the DOM node in fiber.stateNode for host components
5212
+ * or we need to walk down to find the first DOM node
5213
+ * @param fiber - Fiber node
5214
+ * @returns DOM Element or null
5215
+ */
5216
+ getDOMElement(fiber) {
5217
+ if (fiber.stateNode instanceof Element) {
5218
+ return fiber.stateNode;
5219
+ }
5220
+ let current = fiber.child;
5221
+ while (current) {
5222
+ if (current.stateNode instanceof Element) {
5223
+ return current.stateNode;
5224
+ }
5225
+ if (current.child) {
5226
+ current = current.child;
5227
+ } else if (current.sibling) {
5228
+ current = current.sibling;
5229
+ } else {
5230
+ let parent = current.return;
5231
+ while (parent && parent !== fiber && !parent.sibling) {
5232
+ parent = parent.return;
5233
+ }
5234
+ current = parent && parent !== fiber ? parent.sibling : null;
5235
+ }
5236
+ }
5237
+ return null;
5238
+ }
5239
+ /**
5240
+ * Enable visual overlay for render highlighting
5241
+ */
5242
+ enableOverlay() {
5243
+ if (this.overlay) return;
5244
+ this.overlay = new Overlay({
5245
+ enabled: true,
5246
+ highlightRenders: this.config.highlightRenders ?? true,
5247
+ animationSpeed: this.config.animationSpeed ?? "fast",
5248
+ showBadges: true,
5249
+ showToolbar: true
5250
+ });
5251
+ this.overlay.init();
5252
+ }
5253
+ /**
5254
+ * Disable visual overlay
5255
+ */
5256
+ disableOverlay() {
5257
+ if (this.overlay) {
5258
+ this.overlay.destroy();
5259
+ this.overlay = null;
5260
+ }
5261
+ }
5262
+ /**
5263
+ * Get overlay instance
5264
+ * @returns Overlay instance or null
5265
+ */
5266
+ getOverlay() {
5267
+ return this.overlay;
5268
+ }
5269
+ /**
5270
+ * Start the scanner
5271
+ */
5272
+ start() {
5273
+ if (this.running) return;
5274
+ try {
5275
+ this.hookIntoReact();
5276
+ this.running = true;
5277
+ } catch (error) {
5278
+ this.emit("error", error instanceof Error ? error : new Error(String(error)));
5279
+ }
5280
+ }
5281
+ /**
5282
+ * Stop the scanner
5283
+ */
5284
+ stop() {
5285
+ if (!this.running) return;
5286
+ this.unhookFromReact();
5287
+ this.disableOverlay();
5288
+ this.running = false;
5289
+ }
5290
+ /**
5291
+ * Reset the scanner state
5292
+ */
5293
+ reset() {
5294
+ this.renderCounts.clear();
5295
+ this.prevFiberStates = /* @__PURE__ */ new WeakMap();
5296
+ }
5297
+ /**
5298
+ * Hook into React DevTools global hook
5299
+ */
5300
+ hookIntoReact() {
5301
+ const hook = this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
5302
+ if (!hook) {
5303
+ this.installHook();
5304
+ return;
5305
+ }
5306
+ this.originalOnCommitFiberRoot = hook.onCommitFiberRoot.bind(hook);
5307
+ hook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
5308
+ if (this.originalOnCommitFiberRoot) {
5309
+ this.originalOnCommitFiberRoot(rendererID, root, priorityLevel);
5310
+ }
5311
+ this.processCommit(root.current);
5312
+ };
5313
+ this.reactVersion = this.detectReactVersion(hook);
5314
+ this.emit("ready", { reactVersion: this.reactVersion });
5315
+ }
5316
+ /**
5317
+ * Install our own hook if DevTools hook is not present
5318
+ */
5319
+ installHook() {
5320
+ const hook = {
5321
+ renderers: /* @__PURE__ */ new Map(),
5322
+ supportsFiber: true,
5323
+ inject: (renderer) => {
5324
+ const id = hook.renderers.size + 1;
5325
+ hook.renderers.set(id, renderer);
5326
+ return id;
5327
+ },
5328
+ onCommitFiberRoot: (_rendererID, root, _priorityLevel) => {
5329
+ this.processCommit(root.current);
5330
+ },
5331
+ onCommitFiberUnmount: () => {
5332
+ }
5333
+ };
5334
+ this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
5335
+ this.emit("ready", { reactVersion: "unknown (hook installed)" });
5336
+ }
5337
+ /**
5338
+ * Unhook from React
5339
+ */
5340
+ unhookFromReact() {
5341
+ const hook = this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;
5342
+ if (hook && this.originalOnCommitFiberRoot) {
5343
+ hook.onCommitFiberRoot = this.originalOnCommitFiberRoot;
5344
+ this.originalOnCommitFiberRoot = null;
5345
+ }
5346
+ }
5347
+ /**
5348
+ * Detect React version from hook
5349
+ * @param hook - DevTools hook
5350
+ * @returns React version string
5351
+ */
5352
+ detectReactVersion(hook) {
5353
+ if (hook.renderers.size === 0) {
5354
+ return "unknown";
5355
+ }
5356
+ const renderer = hook.renderers.values().next().value;
5357
+ if (renderer && typeof renderer === "object" && "version" in renderer) {
5358
+ return String(renderer.version);
5359
+ }
5360
+ return "unknown";
5361
+ }
5362
+ /**
5363
+ * Process a fiber commit
5364
+ * @param rootFiber - Root fiber of the committed tree
5365
+ */
5366
+ processCommit(rootFiber) {
5367
+ this.walkFiber(rootFiber, null);
5368
+ }
5369
+ /**
5370
+ * Walk the fiber tree
5371
+ * @param fiber - Current fiber
5372
+ * @param parent - Parent component name
5373
+ */
5374
+ walkFiber(fiber, parent) {
5375
+ if (!fiber) return;
5376
+ if (isUserComponent(fiber)) {
5377
+ this.processFiber(fiber, parent);
5378
+ parent = getComponentName(fiber);
5379
+ }
5380
+ this.walkFiber(fiber.child, parent);
5381
+ this.walkFiber(fiber.sibling, parent);
5382
+ }
5383
+ /**
5384
+ * Process a single fiber
5385
+ * @param fiber - Fiber to process
5386
+ * @param parent - Parent component name
5387
+ */
5388
+ processFiber(fiber, _parent) {
5389
+ const componentName = getComponentName(fiber);
5390
+ if (this.shouldFilterComponent(componentName)) {
5391
+ return;
5392
+ }
5393
+ const prevState = this.prevFiberStates.get(fiber);
5394
+ const phase = prevState ? "update" : "mount";
5395
+ const renderInfo = createRenderInfo(
5396
+ fiber,
5397
+ phase,
5398
+ prevState?.props,
5399
+ prevState?.state
5400
+ );
5401
+ const currentCount = this.renderCounts.get(componentName) ?? 0;
5402
+ const newCount = currentCount + 1;
5403
+ this.renderCounts.set(componentName, newCount);
5404
+ renderInfo.renderCount = newCount;
5405
+ this.prevFiberStates.set(fiber, {
5406
+ props: fiber.memoizedProps,
5407
+ state: fiber.memoizedState
5408
+ });
5409
+ if (this.overlay && this.config.highlightRenders) {
5410
+ const domElement = this.getDOMElement(fiber);
5411
+ if (domElement) {
5412
+ this.overlay.highlight(renderInfo, domElement);
5413
+ } else {
5414
+ this.overlay.recordRender(renderInfo);
5415
+ }
5416
+ }
5417
+ this.emit("render", renderInfo);
5418
+ }
5419
+ /**
5420
+ * Check if component should be filtered out
5421
+ * @param name - Component name
5422
+ * @returns true if should be filtered
5423
+ */
5424
+ shouldFilterComponent(name) {
5425
+ if (name.startsWith("__")) return true;
5426
+ if (name === "Fragment") return true;
5427
+ if (name === "Suspense") return true;
5428
+ if (name === "Profiler") return true;
5429
+ const { include, exclude } = this.config;
5430
+ if (include && include.length > 0) {
5431
+ const included = include.some((pattern) => this.matchPattern(name, pattern));
5432
+ if (!included) return true;
5433
+ }
5434
+ if (exclude && exclude.length > 0) {
5435
+ const excluded = exclude.some((pattern) => this.matchPattern(name, pattern));
5436
+ if (excluded) return true;
5437
+ }
5438
+ return false;
5439
+ }
5440
+ /**
5441
+ * Simple glob pattern matching
5442
+ * @param name - Component name
5443
+ * @param pattern - Glob pattern
5444
+ * @returns true if matches
5445
+ */
5446
+ matchPattern(name, pattern) {
5447
+ const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, ".");
5448
+ try {
5449
+ const regex = new RegExp(`^${regexPattern}$`);
5450
+ return regex.test(name);
5451
+ } catch {
5452
+ return false;
5453
+ }
5454
+ }
5455
+ /**
5456
+ * Get current configuration
5457
+ * @returns Scanner configuration
5458
+ */
5459
+ getConfig() {
5460
+ return { ...this.config };
5461
+ }
5462
+ /**
5463
+ * Update configuration
5464
+ * @param config - Partial configuration
5465
+ */
5466
+ configure(config) {
5467
+ this.config = { ...this.config, ...config };
5468
+ }
5469
+ /**
5470
+ * Check if scanner is running
5471
+ * @returns true if running
5472
+ */
5473
+ isRunning() {
5474
+ return this.running;
5475
+ }
5476
+ /**
5477
+ * Get detected React version
5478
+ * @returns React version string
5479
+ */
5480
+ getReactVersion() {
5481
+ return this.reactVersion;
5482
+ }
5483
+ /**
5484
+ * Get render count for a component
5485
+ * @param name - Component name
5486
+ * @returns Render count
5487
+ */
5488
+ getRenderCount(name) {
5489
+ return this.renderCounts.get(name) ?? 0;
5490
+ }
5491
+ /**
5492
+ * Get all render counts
5493
+ * @returns Map of component names to render counts
5494
+ */
5495
+ getAllRenderCounts() {
5496
+ return new Map(this.renderCounts);
5497
+ }
5498
+ };
5499
+
5317
5500
  // src/browser/inject.ts
5318
5501
  var ReactCheckInjector = class {
5319
5502
  /** Browser scanner instance */
@@ -5457,8 +5640,42 @@ var ReactCheckInjector = class {
5457
5640
  case "config":
5458
5641
  this.handleConfig(message.payload);
5459
5642
  break;
5643
+ case "highlight":
5644
+ break;
5645
+ case "toggle-overlay":
5646
+ this.handleToggleOverlay(message.payload.enabled);
5647
+ break;
5648
+ }
5649
+ }
5650
+ /**
5651
+ * Toggle overlay visibility
5652
+ * @param enabled - Whether overlay should be visible
5653
+ */
5654
+ handleToggleOverlay(enabled) {
5655
+ if (enabled) {
5656
+ this.overlay.show();
5657
+ this.overlay.configure({ highlightRenders: true });
5658
+ console.log("[ReactCheck] Overlay enabled");
5659
+ } else {
5660
+ this.overlay.hide();
5661
+ this.overlay.configure({ highlightRenders: false });
5662
+ console.log("[ReactCheck] Overlay disabled");
5460
5663
  }
5461
5664
  }
5665
+ /**
5666
+ * Get overlay visibility status
5667
+ * @returns Whether overlay is visible
5668
+ */
5669
+ isOverlayEnabled() {
5670
+ return this.overlay.isVisible();
5671
+ }
5672
+ /**
5673
+ * Toggle overlay (public method for console access)
5674
+ */
5675
+ toggleOverlay() {
5676
+ const enabled = !this.overlay.isVisible();
5677
+ this.handleToggleOverlay(enabled);
5678
+ }
5462
5679
  /**
5463
5680
  * Handle config update
5464
5681
  * @param config - New configuration