@buoy-gg/highlight-updates 3.0.1 → 3.0.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.
Files changed (83) hide show
  1. package/lib/commonjs/highlight-updates/HighlightUpdatesOverlay.js +285 -1
  2. package/lib/commonjs/highlight-updates/components/HighlightFilterView.js +1371 -1
  3. package/lib/commonjs/highlight-updates/components/HighlightUpdatesModal.js +564 -1
  4. package/lib/commonjs/highlight-updates/components/IdentifierBadge.js +267 -1
  5. package/lib/commonjs/highlight-updates/components/IsolatedRenderList.js +178 -1
  6. package/lib/commonjs/highlight-updates/components/ModalHeaderContent.js +309 -1
  7. package/lib/commonjs/highlight-updates/components/RenderCauseBadge.js +500 -1
  8. package/lib/commonjs/highlight-updates/components/RenderDetailView.js +803 -1
  9. package/lib/commonjs/highlight-updates/components/RenderHistoryViewer.js +894 -1
  10. package/lib/commonjs/highlight-updates/components/RenderListItem.js +220 -1
  11. package/lib/commonjs/highlight-updates/components/RendersCopySettingsView.js +562 -1
  12. package/lib/commonjs/highlight-updates/components/StatsDisplay.js +70 -1
  13. package/lib/commonjs/highlight-updates/components/index.js +97 -1
  14. package/lib/commonjs/highlight-updates/types/copySettings.js +107 -1
  15. package/lib/commonjs/highlight-updates/utils/HighlightUpdatesController.js +1819 -1
  16. package/lib/commonjs/highlight-updates/utils/PerformanceLogger.js +359 -1
  17. package/lib/commonjs/highlight-updates/utils/ProfilerInterceptor.js +371 -1
  18. package/lib/commonjs/highlight-updates/utils/RenderCauseDetector.js +1828 -1
  19. package/lib/commonjs/highlight-updates/utils/RenderTracker.js +919 -1
  20. package/lib/commonjs/highlight-updates/utils/ViewTypeMapper.js +264 -1
  21. package/lib/commonjs/highlight-updates/utils/copySettingsStorage.js +49 -1
  22. package/lib/commonjs/highlight-updates/utils/renderExportFormatter.js +58 -1
  23. package/lib/commonjs/highlight-updates/utils/rendersExportFormatter.js +485 -1
  24. package/lib/commonjs/index.js +320 -1
  25. package/lib/commonjs/preset.js +278 -1
  26. package/lib/commonjs/sync/highlightUpdatesSyncAdapter.js +83 -0
  27. package/lib/module/highlight-updates/HighlightUpdatesOverlay.js +278 -1
  28. package/lib/module/highlight-updates/components/HighlightFilterView.js +1365 -1
  29. package/lib/module/highlight-updates/components/HighlightUpdatesModal.js +558 -1
  30. package/lib/module/highlight-updates/components/IdentifierBadge.js +259 -1
  31. package/lib/module/highlight-updates/components/IsolatedRenderList.js +174 -1
  32. package/lib/module/highlight-updates/components/ModalHeaderContent.js +304 -1
  33. package/lib/module/highlight-updates/components/RenderCauseBadge.js +491 -1
  34. package/lib/module/highlight-updates/components/RenderDetailView.js +797 -1
  35. package/lib/module/highlight-updates/components/RenderHistoryViewer.js +888 -1
  36. package/lib/module/highlight-updates/components/RenderListItem.js +215 -1
  37. package/lib/module/highlight-updates/components/RendersCopySettingsView.js +558 -1
  38. package/lib/module/highlight-updates/components/StatsDisplay.js +67 -1
  39. package/lib/module/highlight-updates/components/index.js +16 -1
  40. package/lib/module/highlight-updates/types/copySettings.js +102 -1
  41. package/lib/module/highlight-updates/utils/HighlightUpdatesController.js +1815 -1
  42. package/lib/module/highlight-updates/utils/PerformanceLogger.js +353 -1
  43. package/lib/module/highlight-updates/utils/ProfilerInterceptor.js +358 -1
  44. package/lib/module/highlight-updates/utils/RenderCauseDetector.js +1818 -1
  45. package/lib/module/highlight-updates/utils/RenderTracker.js +916 -1
  46. package/lib/module/highlight-updates/utils/ViewTypeMapper.js +255 -1
  47. package/lib/module/highlight-updates/utils/copySettingsStorage.js +43 -1
  48. package/lib/module/highlight-updates/utils/renderExportFormatter.js +54 -1
  49. package/lib/module/highlight-updates/utils/rendersExportFormatter.js +478 -1
  50. package/lib/module/index.js +74 -1
  51. package/lib/module/preset.js +272 -1
  52. package/lib/module/sync/highlightUpdatesSyncAdapter.js +78 -0
  53. package/lib/typescript/highlight-updates/HighlightUpdatesOverlay.d.ts.map +1 -0
  54. package/lib/typescript/highlight-updates/components/HighlightFilterView.d.ts.map +1 -0
  55. package/lib/typescript/highlight-updates/components/HighlightUpdatesModal.d.ts.map +1 -0
  56. package/lib/typescript/highlight-updates/components/IdentifierBadge.d.ts.map +1 -0
  57. package/lib/typescript/highlight-updates/components/IsolatedRenderList.d.ts.map +1 -0
  58. package/lib/typescript/highlight-updates/components/ModalHeaderContent.d.ts.map +1 -0
  59. package/lib/typescript/highlight-updates/components/RenderCauseBadge.d.ts.map +1 -0
  60. package/lib/typescript/highlight-updates/components/RenderDetailView.d.ts.map +1 -0
  61. package/lib/typescript/highlight-updates/components/RenderHistoryViewer.d.ts.map +1 -0
  62. package/lib/typescript/highlight-updates/components/RenderListItem.d.ts.map +1 -0
  63. package/lib/typescript/highlight-updates/components/RendersCopySettingsView.d.ts.map +1 -0
  64. package/lib/typescript/highlight-updates/components/StatsDisplay.d.ts.map +1 -0
  65. package/lib/typescript/highlight-updates/components/index.d.ts.map +1 -0
  66. package/lib/typescript/highlight-updates/types/copySettings.d.ts.map +1 -0
  67. package/lib/typescript/highlight-updates/utils/HighlightUpdatesController.d.ts +90 -0
  68. package/lib/typescript/highlight-updates/utils/HighlightUpdatesController.d.ts.map +1 -0
  69. package/lib/typescript/highlight-updates/utils/PerformanceLogger.d.ts.map +1 -0
  70. package/lib/typescript/highlight-updates/utils/ProfilerInterceptor.d.ts.map +1 -0
  71. package/lib/typescript/highlight-updates/utils/RenderCauseDetector.d.ts.map +1 -0
  72. package/lib/typescript/highlight-updates/utils/RenderTracker.d.ts +10 -0
  73. package/lib/typescript/highlight-updates/utils/RenderTracker.d.ts.map +1 -0
  74. package/lib/typescript/highlight-updates/utils/ViewTypeMapper.d.ts.map +1 -0
  75. package/lib/typescript/highlight-updates/utils/copySettingsStorage.d.ts.map +1 -0
  76. package/lib/typescript/highlight-updates/utils/renderExportFormatter.d.ts.map +1 -0
  77. package/lib/typescript/highlight-updates/utils/rendersExportFormatter.d.ts.map +1 -0
  78. package/lib/typescript/index.d.ts +1 -0
  79. package/lib/typescript/index.d.ts.map +1 -0
  80. package/lib/typescript/preset.d.ts.map +1 -0
  81. package/lib/typescript/sync/highlightUpdatesSyncAdapter.d.ts +36 -0
  82. package/lib/typescript/sync/highlightUpdatesSyncAdapter.d.ts.map +1 -0
  83. package/package.json +7 -7
@@ -1 +1,1819 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _ProfilerInterceptor=require("./ProfilerInterceptor"),_RenderTracker=require("./RenderTracker"),_PerformanceLogger=require("./PerformanceLogger"),_RenderCauseDetector=require("./RenderCauseDetector"),_sharedUi=require("@buoy-gg/shared-ui");let globalEnabled=!1,backgroundTrackingEnabled=!1,initialized=!1,hook=null,highlightCallback=null,badgePressCallback=null,traceUpdatesUnsubscribe=null,isProcessing=!1,isFrozen=!1;const freezeListeners=new Set,stateListeners=new Set,nodeRenderCounts=new Map,COLORS=["#37afa9","#63b19e","#80b393","#97b488","#abb67d","#beb771","#cfb965","#dfba57","#efbb49","#febc38"],DEBUG=!1;function debugLog(e,n){}function getPublicInstance(e){if(!e)return null;const n=e;return n.canonical?.publicInstance?n.canonical.publicInstance:n.canonical&&"function"==typeof n.canonical.measure?n.canonical:"function"==typeof n.measure?n:null}function getNativeTag(e){if(null==e)return null;const n=e;if(null!=n.__nativeTag)return n.__nativeTag;if(null!=n._nativeTag)return n._nativeTag;if(null!=n.nativeTag)return n.nativeTag;if(n.canonical){if(null!=n.canonical.__nativeTag)return n.canonical.__nativeTag;if(null!=n.canonical._nativeTag)return n.canonical._nativeTag}return null}function extractComponentInfo(e){const n=e,t={viewType:"Unknown"};n?.canonical?.viewConfig?.uiViewClassName?t.viewType=n.canonical.viewConfig.uiViewClassName:n?.viewConfig?.uiViewClassName&&(t.viewType=n.viewConfig.uiViewClassName);const r=n?.canonical?.internalInstanceHandle||n?._internalInstanceHandle||n?._internalFiberInstanceHandleDEV,a=n?.canonical?.currentProps,i=n?.canonical?.pendingProps,o=r?.pendingProps,s=r?.memoizedProps;return t.testID=a?.testID||i?.testID||o?.testID||s?.testID||void 0,t.nativeID=a?.nativeID||i?.nativeID||o?.nativeID||s?.nativeID||void 0,t.accessibilityLabel=a?.accessibilityLabel||i?.accessibilityLabel||o?.accessibilityLabel||s?.accessibilityLabel||void 0,t.componentName=getOwningComponentName(r)||void 0,t}function describeNodeForLog(e){const n=e,t=getPublicInstance(e),r={nativeTag:(getNativeTag(e)||getNativeTag(t))??"unknown",type:n?.canonical?"Fabric":"Legacy",hasMeasure:"function"==typeof t?.measure};if(n){if(r.stateNodeKeys=Object.keys(n).slice(0,20),n.node&&(r.nodeKeys=Object.keys(n.node).slice(0,20)),n.viewConfig&&(r.viewConfig={uiViewClassName:n.viewConfig.uiViewClassName,validAttributes:n.viewConfig.validAttributes?Object.keys(n.viewConfig.validAttributes).slice(0,10):void 0}),n.canonical){const e=n.canonical;if(r.canonicalKeys=Object.keys(e).slice(0,20),e.viewConfig&&(r.canonicalViewConfig={uiViewClassName:e.viewConfig.uiViewClassName}),null!=e.nativeTag&&(r.canonicalNativeTag=e.nativeTag),e.internalInstanceHandle){const n=e.internalInstanceHandle;if(r.fiberKeys=Object.keys(n).slice(0,30),n.type&&(r.fiberType="function"==typeof n.type?n.type.name||n.type.displayName||"function":n.type),n.elementType&&(r.fiberElementType="function"==typeof n.elementType?n.elementType.name||n.elementType.displayName||"function":n.elementType),n._debugOwner){const e=n._debugOwner;r.fiberDebugOwner=e.type?.name||e.type?.displayName||e.elementType?.name||"unknown"}n._debugSource&&(r.fiberDebugSource=n._debugSource),null!=n.tag&&(r.fiberTag=n.tag),n.pendingProps&&(n.pendingProps.nativeID&&(r.fiberPendingNativeID=n.pendingProps.nativeID),n.pendingProps.testID&&(r.fiberPendingTestID=n.pendingProps.testID)),n.memoizedProps&&(n.memoizedProps.nativeID&&(r.fiberMemoizedNativeID=n.memoizedProps.nativeID),n.memoizedProps.testID&&(r.fiberMemoizedTestID=n.memoizedProps.testID))}if(e.publicInstance){const n=e.publicInstance;r.publicInstanceKeys=Object.keys(n).slice(0,20),null!=n.nativeID&&(r.nativeID=n.nativeID),null!=n._nativeID&&(r._nativeID=n._nativeID),n.props&&(r.publicInstanceProps=Object.keys(n.props).slice(0,15),n.props.nativeID&&(r.propsNativeID=n.props.nativeID),n.props.testID&&(r.propsTestID=n.props.testID),n.props.accessibilityLabel&&(r.accessibilityLabel=n.props.accessibilityLabel))}e.currentProps&&(r.currentPropsKeys=Object.keys(e.currentProps).slice(0,15),null!=e.currentProps.nativeID&&(r.currentPropsNativeID=e.currentProps.nativeID),null!=e.currentProps.testID&&(r.currentPropsTestID=e.currentProps.testID),null!=e.currentProps.accessibilityLabel&&(r.currentPropsAccessLabel=e.currentProps.accessibilityLabel)),e.pendingProps&&(r.pendingPropsKeys=Object.keys(e.pendingProps).slice(0,15),null!=e.pendingProps.nativeID&&(r.pendingPropsNativeID=e.pendingProps.nativeID),null!=e.pendingProps.testID&&(r.pendingPropsTestID=e.pendingProps.testID))}if(n._debugOwner){const e=n._debugOwner;r.debugOwnerType=e.type?.name||e.type?.displayName||typeof e.type}n._debugSource&&(r.debugSource=n._debugSource)}return r}const DEBUG_LOGGING=!1;let renderingLock=!1,renderingLockTimeout=null;const RENDER_LOCK_DURATION=350,renderedOverlayTags=new Set;function isOurOverlayTag(e){return null!=e&&renderedOverlayTags.has(e)}const HIGHLIGHT_OVERLAY_COMPONENTS=new Set(["HighlightUpdatesOverlay","HighlightUpdatesModal","HighlightFilterView","RenderDetailView","RenderListItem","RenderListItemInner","RenderHistoryViewer","RenderHistoryFooter","RenderCauseBadge","TwoLevelCauseBadge","EnhancedCauseDisplay","IsolatedRenderList","IsolatedRenderListInner","StatsDisplay","StatsDisplayInner","CurrentStateView","EventStepperFooter","EventsModal","UnifiedEventList","UnifiedEventItem","UnifiedEventDetail","UnifiedEventFilters","UnifiedEventViewer","ReactQueryEventDetail","EventsCopySettingsView"]),HIGHLIGHT_OVERLAY_NATIVE_IDS=new Set(["highlight-updates-overlay","__rn_buoy__highlight-modal"]),HIGHLIGHT_OVERLAY_PREFIXES=["HighlightUpdates","RenderList","RenderDetail","RenderHistory","RenderCause","EventStepper","UnifiedEvent","EventsModal","EventsCopy"],OTHER_DEV_TOOLS_COMPONENTS=new Set(["JsModalComponent","JsModal","TypePicker","PatternInput","PatternChip","DetectedItemsSection","DetectedCategoryBadge","IdentifierBadge","CategoryBadge","AppRenderer","AppOverlay","FloatingTools","DialDevTools","DevToolsVisibilityProvider","AppHostProvider","MinimizedToolsProvider","ModalHeader","TabSelector","SectionHeader","DraggableHeader","WindowControls","TreeDiffViewer","DataViewer","SplitDiffViewer","VirtualizedDataExplorer","DiffSummary","TypeLegend","IndentGuides","IndentGuidesOverlay","CyberpunkInput","DiffView","AnswerCard","DetailsSection","DetailRow","QuickActionsSection","FilterOptionCard","SearchSection","SearchSectionInner","HeaderActions","HeaderActionsInner","MainListHeader","FilterViewHeader","DetailViewHeader","FloatingMenu","FloatingDevTools","MinimizedToolsStack","MinimizedToolsContext","GlitchToolButton","ExpandablePopover","CollapsedPeek","ExpandedWrapper","DialIcon","DialMenu","DialIconItem","OnboardingTooltip","MenuLauncherIcon","DevToolsSettingsModal","SettingsModal","ImageOverlayModal","ImageOverlayStandalone","ToolCard","ToolIcon","GripVerticalIcon","UserStatus","Divider","ChevronDown","ChevronUp","ChevronLeft","ChevronRight","ChevronDownIcon","ChevronUpIcon","ChevronLeftIcon","ChevronRightIcon","LogBox","LogBoxLog","LogBoxLogNotification","LogBoxNotificationContainer","_LogBoxNotificationContainer","LogBoxInspector","LogBoxInspectorContainer","LogBoxInspectorHeader","LogBoxInspectorBody","LogBoxInspectorFooter","LogBoxInspectorMessageHeader","LogBoxInspectorStackFrame","LogBoxInspectorSection","LogBoxButton","LogBoxMessage"]),OTHER_DEV_TOOLS_PREFIXES=["JsModal","TreeDiff","DataViewer","DiffView","DiffSummary","Virtualized","Floating","Minimized","Dial","Expandable","Chevron","Glitch","Settings","Onboarding","DevTools","ImageOverlay"],OTHER_DEV_TOOLS_NATIVE_IDS=new Set(["jsmodal-root","image-overlay-standalone","logbox_inspector","logbox"]),devToolsNodeCache=new Map,CACHE_MAX_SIZE=500;function clearDevToolsCache(){devToolsNodeCache.clear()}function isHighlightOverlayNativeID(e){return!(!e||!HIGHLIGHT_OVERLAY_NATIVE_IDS.has(e)&&!e.startsWith("__highlight_"))}function isOtherDevToolsNativeID(e){if(!e)return!1;if(OTHER_DEV_TOOLS_NATIVE_IDS.has(e))return!0;const n=e.charCodeAt(0);return!(95!==n||!e.startsWith("__rn_buoy__"))||!(108!==n||!e.startsWith("logbox"))}function getComponentName(e){if(!e)return null;const n=e.type;if(n){if("string"==typeof n)return n;if(n.name)return n.name;if(n.displayName)return n.displayName}const t=e.elementType;if(t){if(t.name)return t.name;if(t.displayName)return t.displayName}return null}const INTERNAL_COMPONENT_NAMES=new Set(["View","Text","TextImpl","Image","ScrollView","FlatList","SectionList","TouchableOpacity","TouchableHighlight","TouchableWithoutFeedback","Pressable","TextInput","Switch","ActivityIndicator","Modal","StatusBar","KeyboardAvoidingView","AnimatedComponent","AnimatedComponentWrapper","ScreenContainer","ScreenStack","Screen","ScreenContentWrapper","Svg","G","Path","Rect","Circle","Line","Polygon","Polyline","Ellipse","Text as SVGText","TSpan","TextPath","Use","Symbol","Defs","ClipPath","LinearGradient","RadialGradient","Stop","Mask","Pattern","Image as SVGImage","SafeAreaProvider","SafeAreaView","SafeAreaListener","GestureHandlerRootView","GestureDetector","ReanimatedView","ReanimatedText","ReanimatedImage","ReanimatedScrollView","Fragment","Suspense","Provider","Consumer","Context","ForwardRef"]);function isInternalComponent(e){return!e||!!INTERNAL_COMPONENT_NAMES.has(e)||"Unknown"===e||"Component"===e||!!e.startsWith("Animated")}function getOwningComponentName(e){if(!e)return null;let n=e._debugOwner||e.return,t=0,r=null;for(;n&&t<30;){const e=getComponentName(n);if(e&&"string"!=typeof n.type&&(r||(r=e),!isInternalComponent(e)))return e;n=n.return,t++}return r}function isOurOverlayNode(e){const n=e,t=n?.canonical?.internalInstanceHandle||n?._internalInstanceHandle||n?._internalFiberInstanceHandleDEV,r=getNativeTag(e)||getNativeTag(n?.canonical?.publicInstance),a=_RenderTracker.RenderTracker.getSettings().excludeDevTools;if(null!=r&&a){const e=devToolsNodeCache.get(r);if(void 0!==e)return e}let i=!1;const o=t?.pendingProps?.nativeID||t?.memoizedProps?.nativeID||n?.canonical?.currentProps?.nativeID||null;if((isHighlightOverlayNativeID(o)||a&&isOtherDevToolsNativeID(o))&&(i=!0),!i&&t){let e=t,n=0;for(;e&&n<30;){const t=getComponentName(e);if(t){if(HIGHLIGHT_OVERLAY_COMPONENTS.has(t)){i=!0;break}for(const e of HIGHLIGHT_OVERLAY_PREFIXES)if(t.startsWith(e)){i=!0;break}if(i)break;if(a){if(OTHER_DEV_TOOLS_COMPONENTS.has(t)){i=!0;break}for(const e of OTHER_DEV_TOOLS_PREFIXES)if(t.startsWith(e)){i=!0;break}if(i)break}}const r=e.pendingProps?.nativeID||e.memoizedProps?.nativeID;if(isHighlightOverlayNativeID(r)){i=!0;break}if(a&&isOtherDevToolsNativeID(r)){i=!0;break}e=e.return,n++}}if(i&&null!=r&&a){if(devToolsNodeCache.size>=500){const e=Array.from(devToolsNodeCache.keys());for(let n=0;n<250;n++)devToolsNodeCache.delete(e[n])}devToolsNodeCache.set(r,i)}return i}function getColorForRenderCount(e){const n=Math.min(e-1,COLORS.length-1);return COLORS[Math.max(0,n)]}function handleTraceUpdates(e){if(0===e.size)return;if(!globalEnabled&&!backgroundTrackingEnabled)return;if(_RenderTracker.RenderTracker.getState().isPaused)return;_PerformanceLogger.PerformanceLogger.isEnabled()&&(0,_PerformanceLogger.markEventReceived)();const n=_RenderTracker.RenderTracker.getBatchSize(),t=_PerformanceLogger.PerformanceLogger.startBatch(e.size,n),r=[];let a=0,i=0;const o=_RenderTracker.RenderTracker.hasActiveFilters();for(const n of e)if(n&&"object"==typeof n)try{if(isOurOverlayNode(n)){a++;continue}const e=getPublicInstance(n),t=getNativeTag(n)||getNativeTag(e);if(null==t)continue;const s=extractComponentInfo(n);if(o&&!_RenderTracker.RenderTracker.passesFilters(s)){i++;continue}let l,c;_RenderTracker.RenderTracker.getSettings().showRenderCount?(l=(nodeRenderCounts.get(t)||0)+1,nodeRenderCounts.set(t,l),c=getColorForRenderCount(l)):(l=0,c=COLORS[0]),r.push({node:n,color:c,count:l})}catch{}if(t.markFilteringComplete(a+i,r.length),0===r.length)return void t.finish();const s=_RenderTracker.RenderTracker.getRenderEventCallbackCount()>0;if(!highlightCallback&&!s)return void(isProcessing=!1);t.markMeasurementStart();const l=r.slice(0,n).map(({node:e,color:n,count:t})=>new Promise(r=>{const a=getPublicInstance(e);if(!a)return void r({rect:null,stateNode:e,color:n,count:t});const i=getNativeTag(e)||getNativeTag(a);if(null!=i)try{a.measure((a,o,s,l,c,d)=>{r(null!=c&&null!=d&&null!=s&&null!=l?{rect:{id:i,x:c,y:d,width:s,height:l,color:n,count:t},stateNode:e,color:n,count:t}:{rect:null,stateNode:e,color:n,count:t})})}catch(a){r({rect:null,stateNode:e,color:n,count:t})}else r({rect:null,stateNode:e,color:n,count:t})}));Promise.all(l).then(e=>{const n=e.filter(e=>null!==e.rect),r=n.map(e=>e.rect);t.markMeasurementComplete(n.length,e.length-n.length);const a=_RenderTracker.RenderTracker.getSettings(),i=a.trackRenderCauses&&a.showRenderCount;let o=null;if(i){o=new Set;for(const{rect:e}of n)e&&o.add(e.id)}if(globalEnabled){_RenderTracker.RenderTracker.startBatch();for(const{rect:e,stateNode:t,color:r,count:s}of n)if(e){const n=extractComponentInfo(t);let l;if(i&&o){const n=t,r=n?.canonical?.internalInstanceHandle;l=(0,_RenderCauseDetector.detectRenderCause)(e.id,r,o,a.debugLogLevel)}_RenderTracker.RenderTracker.trackRender({nativeTag:e.id,viewType:n.viewType,testID:n.testID,nativeID:n.nativeID,accessibilityLabel:n.accessibilityLabel,componentName:n.componentName,measurements:{x:e.x,y:e.y,width:e.width,height:e.height},color:r,count:s,renderCause:l})}_RenderTracker.RenderTracker.endBatch()}else for(const{rect:e,stateNode:t,color:r,count:s}of n)if(e){const n=extractComponentInfo(t);let l;if(i&&o){const n=t,r=n?.canonical?.internalInstanceHandle;l=(0,_RenderCauseDetector.detectRenderCause)(e.id,r,o,a.debugLogLevel)}_RenderTracker.RenderTracker.emitRenderEvent({nativeTag:e.id,viewType:n.viewType,testID:n.testID,nativeID:n.nativeID,accessibilityLabel:n.accessibilityLabel,componentName:n.componentName,measurements:{x:e.x,y:e.y,width:e.width,height:e.height},color:r,count:s,renderCause:l})}t.markTrackingComplete(),r.length>0&&highlightCallback&&globalEnabled&&highlightCallback(r),t.markCallbackComplete(),t.finish()}).catch(e=>{console.error("[HighlightUpdates] Error in measurement pipeline:",e),t.finish()})}function setTraceUpdatesOnRenderers(e){if(!hook?.rendererInterfaces)return void debugLog("No rendererInterfaces available");let n=0;if(hook.rendererInterfaces.forEach((t,r)=>{if("function"==typeof t.setTraceUpdatesEnabled)try{t.setTraceUpdatesEnabled(e),n++,debugLog(`Renderer ${r}: setTraceUpdatesEnabled(${e})`)}catch(e){debugLog(`Renderer ${r}: error setting trace updates`,e)}else debugLog(`Renderer ${r}: no setTraceUpdatesEnabled method`)}),debugLog(`Set trace updates ${e?"enabled":"disabled"} on ${n} renderer(s)`),hook.reactDevtoolsAgent?.setTraceUpdatesEnabled)try{hook.reactDevtoolsAgent.setTraceUpdatesEnabled(e),debugLog("Also set trace updates on agent")}catch(e){debugLog("Error setting trace updates on agent",e)}}function subscribeToTraceUpdates(){hook&&(traceUpdatesUnsubscribe||(debugLog("Subscribing to traceUpdates event"),"function"==typeof hook.sub?(traceUpdatesUnsubscribe=hook.sub("traceUpdates",handleTraceUpdates),debugLog("Subscribed using hook.sub()")):debugLog("hook.sub not available, traceUpdates may not work"),setTraceUpdatesOnRenderers(!0)))}function unsubscribeFromTraceUpdates(){setTraceUpdatesOnRenderers(!1),traceUpdatesUnsubscribe&&(traceUpdatesUnsubscribe(),traceUpdatesUnsubscribe=null,debugLog("Unsubscribed from traceUpdates event"))}function setHighlightCallback(e){highlightCallback=e,debugLog("Highlight callback "+(e?"set":"cleared"))}function setBadgePressCallback(e){badgePressCallback=e,debugLog("Badge press callback "+(e?"set":"cleared"))}function getBadgePressCallback(){return badgePressCallback}function handleBadgePress(e){badgePressCallback&&badgePressCallback(e)}let spotlightCallback=null,currentSpotlightTag=null;function setSpotlightCallback(e){spotlightCallback=e,e&&null!==currentSpotlightTag&&e(currentSpotlightTag)}function setSpotlight(e){currentSpotlightTag=e,spotlightCallback&&spotlightCallback(e)}function getSpotlight(){return currentSpotlightTag}function notifyStateListeners(){stateListeners.forEach(e=>{try{e(globalEnabled)}catch(e){console.error("[HighlightUpdates] Error in state listener:",e)}})}function subscribe(e){return stateListeners.add(e),e(globalEnabled),()=>{stateListeners.delete(e)}}function initialize(){if("undefined"!=typeof __DEV__&&!__DEV__)return debugLog("Only available in development builds"),!1;if(initialized)return!0;if(hook=window?.__REACT_DEVTOOLS_GLOBAL_HOOK__||null,!hook)return debugLog("React DevTools hook not found"),!1;if(debugLog("Hook found"),debugLog(`Hook has sub: ${"function"==typeof hook.sub}`),debugLog(`Hook has on: ${"function"==typeof hook.on}`),debugLog(`Hook has emit: ${"function"==typeof hook.emit}`),(0,_ProfilerInterceptor.installProfilerInterceptor)(),hook.rendererInterfaces&&hook.rendererInterfaces.size>0)return initialized=!0,debugLog(`Initialized with ${hook.rendererInterfaces.size} renderer(s)`),exposeGlobally(),!0;const e=setInterval(()=>{hook?.rendererInterfaces&&hook.rendererInterfaces.size>0&&(clearInterval(e),initialized=!0,debugLog(`Initialized with ${hook.rendererInterfaces.size} renderer(s) (delayed)`),exposeGlobally())},100);return setTimeout(()=>clearInterval(e),1e4),!1}function exposeGlobally(){"undefined"!=typeof window&&(window.__HIGHLIGHT_UPDATES_CONTROLLER__={enable:enable,disable:disable,toggle:toggle,isEnabled:isEnabled,setEnabled:setEnabled,subscribe:subscribe,initialize:initialize,destroy:destroy,isInitialized:()=>initialized,setHighlightCallback:setHighlightCallback})}function enable(){("undefined"==typeof __DEV__||__DEV__)&&(initialized||initialize(),globalEnabled||(debugLog("Enabling highlights"),backgroundTrackingEnabled||subscribeToTraceUpdates(),_RenderTracker.RenderTracker.start(),globalEnabled=!0,notifyStateListeners(),(0,_sharedUi.notifySubscriberCountChange)("render")))}function disable(){("undefined"==typeof __DEV__||__DEV__)&&globalEnabled&&(debugLog("Disabling highlights"),renderingLock=!1,isProcessing=!1,renderingLockTimeout&&(clearTimeout(renderingLockTimeout),renderingLockTimeout=null),renderedOverlayTags.clear(),devToolsNodeCache.clear(),(0,_RenderCauseDetector.clearRenderCauseState)(),backgroundTrackingEnabled||unsubscribeFromTraceUpdates(),_RenderTracker.RenderTracker.stop(),globalEnabled=!1,notifyStateListeners(),(0,_sharedUi.notifySubscriberCountChange)("render"))}function enableBackgroundTracking(){("undefined"==typeof __DEV__||__DEV__)&&(backgroundTrackingEnabled||(initialized||initialize(),debugLog("Enabling background tracking"),globalEnabled||subscribeToTraceUpdates(),backgroundTrackingEnabled=!0))}function disableBackgroundTracking(){("undefined"==typeof __DEV__||__DEV__)&&backgroundTrackingEnabled&&(debugLog("Disabling background tracking"),backgroundTrackingEnabled=!1,globalEnabled||unsubscribeFromTraceUpdates())}function isBackgroundTrackingEnabled(){return backgroundTrackingEnabled}function toggle(){("undefined"==typeof __DEV__||__DEV__)&&(globalEnabled?disable():enable())}function clearRenderCounts(){nodeRenderCounts.clear(),_RenderTracker.RenderTracker.clear(),debugLog("Cleared render counts")}function isEnabled(){return globalEnabled}function setEnabled(e){e?enable():disable()}function isInitialized(){return initialized}function notifyFreezeListeners(){freezeListeners.forEach(e=>{try{e(isFrozen)}catch(e){console.error("[HighlightUpdates] Error in freeze listener:",e)}})}function subscribeToFreeze(e){return freezeListeners.add(e),e(isFrozen),()=>{freezeListeners.delete(e)}}function freeze(){("undefined"==typeof __DEV__||__DEV__)&&(isFrozen||(isFrozen=!0,debugLog("Freeze mode enabled"),notifyFreezeListeners()))}function unfreeze(){("undefined"==typeof __DEV__||__DEV__)&&isFrozen&&(isFrozen=!1,debugLog("Freeze mode disabled"),highlightCallback&&highlightCallback([]),notifyFreezeListeners())}function toggleFreeze(){isFrozen?unfreeze():freeze()}function getFrozen(){return isFrozen}function destroy(){initialized&&(unsubscribeFromTraceUpdates(),(0,_ProfilerInterceptor.uninstallProfilerInterceptor)(),(0,_ProfilerInterceptor.setComparisonCallback)(null),isFrozen=!1,freezeListeners.clear(),globalEnabled=!1,hook=null,highlightCallback=null,initialized=!1,"undefined"!=typeof window&&delete window.__HIGHLIGHT_UPDATES_CONTROLLER__,debugLog("Destroyed"))}const HighlightUpdatesController={subscribe:subscribe,enable:enable,disable:disable,toggle:toggle,isEnabled:isEnabled,setEnabled:setEnabled,initialize:initialize,destroy:destroy,isInitialized:isInitialized,setHighlightCallback:setHighlightCallback,clearRenderCounts:clearRenderCounts,freeze:freeze,unfreeze:unfreeze,toggleFreeze:toggleFreeze,getFrozen:getFrozen,subscribeToFreeze:subscribeToFreeze,setBadgePressCallback:setBadgePressCallback,getBadgePressCallback:getBadgePressCallback,handleBadgePress:handleBadgePress,setSpotlightCallback:setSpotlightCallback,setSpotlight:setSpotlight,getSpotlight:getSpotlight,clearDevToolsCache:clearDevToolsCache,enableBackgroundTracking:enableBackgroundTracking,disableBackgroundTracking:disableBackgroundTracking,isBackgroundTrackingEnabled:isBackgroundTrackingEnabled};var _default=exports.default=HighlightUpdatesController;
1
+ /**
2
+ * Highlight Updates Controller
3
+ *
4
+ * Standalone implementation that replicates React DevTools' "Highlight updates
5
+ * when components render" feature WITHOUT requiring DevTools to be connected.
6
+ *
7
+ * Architecture:
8
+ * This controller directly enables the DevTools backend's traceUpdates feature
9
+ * by calling setTraceUpdatesEnabled(true) on each renderer interface. This is
10
+ * the same function that DevTools' frontend calls when you check the
11
+ * "Highlight updates when components render" checkbox.
12
+ *
13
+ * Key insight: The rendererInterfaces are available on the global hook even
14
+ * without DevTools frontend connected. We just need to enable tracing directly.
15
+ *
16
+ * Flow:
17
+ * 1. User enables highlights via toggle()
18
+ * 2. We call rendererInterface.setTraceUpdatesEnabled(true) on all renderers
19
+ * 3. DevTools backend now tracks renders and emits 'traceUpdates' events
20
+ * 4. We subscribe to 'traceUpdates' via hook.sub()
21
+ * 5. When components re-render, we receive the Set of host stateNodes
22
+ * 6. We measure each node and render colored border highlights
23
+ *
24
+ * This gives us 100% accuracy with DevTools behavior because we're using the
25
+ * exact same detection code - we're just enabling it programmatically.
26
+ */
27
+
28
+ "use strict";
29
+
30
+ Object.defineProperty(exports, "__esModule", {
31
+ value: true
32
+ });
33
+ exports.default = void 0;
34
+ var _ProfilerInterceptor = require("./ProfilerInterceptor");
35
+ var _reactNative = require("react-native");
36
+ var _RenderTracker = require("./RenderTracker");
37
+ var _PerformanceLogger = require("./PerformanceLogger");
38
+ var _RenderCauseDetector = require("./RenderCauseDetector");
39
+ var _sharedUi = require("@buoy-gg/shared-ui");
40
+ // State
41
+ let globalEnabled = false; // User-controlled toggle for visual highlights
42
+ // When true, tracking + measurement + storage all run as normal, but the
43
+ // visual highlight boxes are NOT drawn. Lets the desktop "screenshot this
44
+ // component" flow get the render history + measurements with no on-device
45
+ // overlay. Independent of globalEnabled; reset whenever the visual tool is
46
+ // enabled (the Renders tab always wants its boxes).
47
+ let highlightsSuppressed = false;
48
+ let backgroundTrackingEnabled = false; // Auto-enabled when event callbacks exist (Events tool)
49
+ let initialized = false;
50
+ let hook = null;
51
+ let highlightCallback = null;
52
+ let badgePressCallback = null;
53
+ let traceUpdatesUnsubscribe = null;
54
+ let isProcessing = false;
55
+
56
+ // Freeze frame state
57
+ let isFrozen = false;
58
+ const freezeListeners = new Set();
59
+ const stateListeners = new Set();
60
+
61
+ // Track render counts per node (for color assignment like DevTools)
62
+ // Map from nativeTag to render count - nativeTag is stable across re-renders
63
+ const nodeRenderCounts = new Map();
64
+
65
+ // Color palette for highlights (same as DevTools)
66
+ // From: react-devtools-core/dist/backend.js line 6361
67
+ const COLORS = ["#37afa9", "#63b19e", "#80b393", "#97b488", "#abb67d", "#beb771", "#cfb965", "#dfba57", "#efbb49", "#febc38"];
68
+
69
+ // Set to true for verbose debugging of our implementation
70
+ // Disabled for now to focus on profiler logs only
71
+ const DEBUG = false;
72
+ function debugLog(message, data) {
73
+ if (!DEBUG) return;
74
+ if (data !== undefined) {
75
+ console.log(`[HighlightUpdates] ${message}`, data);
76
+ } else {
77
+ console.log(`[HighlightUpdates] ${message}`);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Get the public instance from a stateNode (the node passed in traceUpdates)
83
+ */
84
+ function getPublicInstance(stateNode) {
85
+ if (!stateNode) return null;
86
+ const node = stateNode;
87
+
88
+ // Fabric: stateNode.canonical.publicInstance
89
+ if (node.canonical?.publicInstance) {
90
+ return node.canonical.publicInstance;
91
+ }
92
+
93
+ // Legacy Fabric: stateNode.canonical with measure
94
+ if (node.canonical && typeof node.canonical.measure === "function") {
95
+ return node.canonical;
96
+ }
97
+
98
+ // Legacy renderer: stateNode has measure directly
99
+ if (typeof node.measure === "function") {
100
+ return node;
101
+ }
102
+ return null;
103
+ }
104
+
105
+ /**
106
+ * Get native tag from public instance or stateNode
107
+ */
108
+ function getNativeTag(instance) {
109
+ if (instance == null) return null;
110
+ const inst = instance;
111
+
112
+ // Try direct properties
113
+ if (inst.__nativeTag != null) return inst.__nativeTag;
114
+ if (inst._nativeTag != null) return inst._nativeTag;
115
+ if (inst.nativeTag != null) return inst.nativeTag;
116
+
117
+ // Try canonical
118
+ if (inst.canonical) {
119
+ if (inst.canonical.__nativeTag != null) return inst.canonical.__nativeTag;
120
+ if (inst.canonical._nativeTag != null) return inst.canonical._nativeTag;
121
+ }
122
+ return null;
123
+ }
124
+
125
+ /**
126
+ * Extract component info from a stateNode for RenderTracker
127
+ */
128
+ function extractComponentInfo(stateNode) {
129
+ const node = stateNode;
130
+ const info = {
131
+ viewType: "Unknown"
132
+ };
133
+
134
+ // Get viewType from viewConfig
135
+ if (node?.canonical?.viewConfig?.uiViewClassName) {
136
+ info.viewType = node.canonical.viewConfig.uiViewClassName;
137
+ } else if (node?.viewConfig?.uiViewClassName) {
138
+ info.viewType = node.viewConfig.uiViewClassName;
139
+ }
140
+
141
+ // Try to get props from various locations
142
+ // Fabric: canonical.internalInstanceHandle, Paper: _internalInstanceHandle, RN CLI DEV: _internalFiberInstanceHandleDEV
143
+ const fiber = node?.canonical?.internalInstanceHandle || node?._internalInstanceHandle || node?._internalFiberInstanceHandleDEV;
144
+ const currentProps = node?.canonical?.currentProps;
145
+ const pendingProps = node?.canonical?.pendingProps;
146
+ const fiberPendingProps = fiber?.pendingProps;
147
+ const fiberMemoizedProps = fiber?.memoizedProps;
148
+
149
+ // Extract testID
150
+ info.testID = currentProps?.testID || pendingProps?.testID || fiberPendingProps?.testID || fiberMemoizedProps?.testID || undefined;
151
+
152
+ // Extract nativeID
153
+ info.nativeID = currentProps?.nativeID || pendingProps?.nativeID || fiberPendingProps?.nativeID || fiberMemoizedProps?.nativeID || undefined;
154
+
155
+ // Extract accessibilityLabel
156
+ info.accessibilityLabel = currentProps?.accessibilityLabel || pendingProps?.accessibilityLabel || fiberPendingProps?.accessibilityLabel || fiberMemoizedProps?.accessibilityLabel || undefined;
157
+
158
+ // Extract componentName - use getOwningComponentName to get the React component
159
+ // that rendered this host component
160
+ info.componentName = getOwningComponentName(fiber) || undefined;
161
+ return info;
162
+ }
163
+
164
+ /**
165
+ * Describe a node for logging (extensive version for debugging)
166
+ */
167
+ function describeNodeForLog(stateNode) {
168
+ const node = stateNode;
169
+ const publicInstance = getPublicInstance(stateNode);
170
+ const nativeTag = getNativeTag(stateNode) || getNativeTag(publicInstance);
171
+ const info = {
172
+ nativeTag: nativeTag ?? "unknown",
173
+ type: node?.canonical ? "Fabric" : "Legacy",
174
+ hasMeasure: typeof publicInstance?.measure === "function"
175
+ };
176
+
177
+ // Extract as much info as possible from the stateNode
178
+ if (node) {
179
+ // Direct properties on stateNode
180
+ info.stateNodeKeys = Object.keys(node).slice(0, 20);
181
+
182
+ // Check the 'node' property (might have useful info)
183
+ if (node.node) {
184
+ info.nodeKeys = Object.keys(node.node).slice(0, 20);
185
+ }
186
+
187
+ // Check for viewConfig (contains component type info)
188
+ if (node.viewConfig) {
189
+ info.viewConfig = {
190
+ uiViewClassName: node.viewConfig.uiViewClassName,
191
+ validAttributes: node.viewConfig.validAttributes ? Object.keys(node.viewConfig.validAttributes).slice(0, 10) : undefined
192
+ };
193
+ }
194
+
195
+ // Check canonical structure (Fabric)
196
+ if (node.canonical) {
197
+ const canonical = node.canonical;
198
+ info.canonicalKeys = Object.keys(canonical).slice(0, 20);
199
+ if (canonical.viewConfig) {
200
+ info.canonicalViewConfig = {
201
+ uiViewClassName: canonical.viewConfig.uiViewClassName
202
+ };
203
+ }
204
+ if (canonical.nativeTag != null) {
205
+ info.canonicalNativeTag = canonical.nativeTag;
206
+ }
207
+
208
+ // Check internalInstanceHandle (THE FIBER!)
209
+ if (canonical.internalInstanceHandle) {
210
+ const fiber = canonical.internalInstanceHandle;
211
+ info.fiberKeys = Object.keys(fiber).slice(0, 30);
212
+
213
+ // Component type info
214
+ if (fiber.type) {
215
+ info.fiberType = typeof fiber.type === "function" ? fiber.type.name || fiber.type.displayName || "function" : fiber.type;
216
+ }
217
+ if (fiber.elementType) {
218
+ info.fiberElementType = typeof fiber.elementType === "function" ? fiber.elementType.name || fiber.elementType.displayName || "function" : fiber.elementType;
219
+ }
220
+
221
+ // Debug info on fiber
222
+ if (fiber._debugOwner) {
223
+ const owner = fiber._debugOwner;
224
+ info.fiberDebugOwner = owner.type?.name || owner.type?.displayName || owner.elementType?.name || "unknown";
225
+ }
226
+ if (fiber._debugSource) {
227
+ info.fiberDebugSource = fiber._debugSource;
228
+ }
229
+
230
+ // Fiber tag (tells us what kind of fiber it is)
231
+ if (fiber.tag != null) {
232
+ info.fiberTag = fiber.tag;
233
+ }
234
+
235
+ // pendingProps on fiber might have testID/nativeID
236
+ if (fiber.pendingProps) {
237
+ if (fiber.pendingProps.nativeID) info.fiberPendingNativeID = fiber.pendingProps.nativeID;
238
+ if (fiber.pendingProps.testID) info.fiberPendingTestID = fiber.pendingProps.testID;
239
+ }
240
+ if (fiber.memoizedProps) {
241
+ if (fiber.memoizedProps.nativeID) info.fiberMemoizedNativeID = fiber.memoizedProps.nativeID;
242
+ if (fiber.memoizedProps.testID) info.fiberMemoizedTestID = fiber.memoizedProps.testID;
243
+ }
244
+ }
245
+
246
+ // Check publicInstance
247
+ if (canonical.publicInstance) {
248
+ const pub = canonical.publicInstance;
249
+ info.publicInstanceKeys = Object.keys(pub).slice(0, 20);
250
+
251
+ // Look for nativeID
252
+ if (pub.nativeID != null) info.nativeID = pub.nativeID;
253
+ if (pub._nativeID != null) info._nativeID = pub._nativeID;
254
+
255
+ // Look for props
256
+ if (pub.props) {
257
+ info.publicInstanceProps = Object.keys(pub.props).slice(0, 15);
258
+ if (pub.props.nativeID) info.propsNativeID = pub.props.nativeID;
259
+ if (pub.props.testID) info.propsTestID = pub.props.testID;
260
+ if (pub.props.accessibilityLabel) info.accessibilityLabel = pub.props.accessibilityLabel;
261
+ }
262
+ }
263
+
264
+ // Check for currentProps - log actual VALUES
265
+ if (canonical.currentProps) {
266
+ info.currentPropsKeys = Object.keys(canonical.currentProps).slice(0, 15);
267
+ // Log actual values of identifying props
268
+ if (canonical.currentProps.nativeID != null) info.currentPropsNativeID = canonical.currentProps.nativeID;
269
+ if (canonical.currentProps.testID != null) info.currentPropsTestID = canonical.currentProps.testID;
270
+ if (canonical.currentProps.accessibilityLabel != null) info.currentPropsAccessLabel = canonical.currentProps.accessibilityLabel;
271
+ }
272
+
273
+ // Check for pendingProps
274
+ if (canonical.pendingProps) {
275
+ info.pendingPropsKeys = Object.keys(canonical.pendingProps).slice(0, 15);
276
+ if (canonical.pendingProps.nativeID != null) info.pendingPropsNativeID = canonical.pendingProps.nativeID;
277
+ if (canonical.pendingProps.testID != null) info.pendingPropsTestID = canonical.pendingProps.testID;
278
+ }
279
+ }
280
+
281
+ // Check for fiber reference directly on node
282
+ if (node._debugOwner) {
283
+ const owner = node._debugOwner;
284
+ info.debugOwnerType = owner.type?.name || owner.type?.displayName || typeof owner.type;
285
+ }
286
+ if (node._debugSource) {
287
+ info.debugSource = node._debugSource;
288
+ }
289
+ }
290
+ return info;
291
+ }
292
+
293
+ // Set to true to enable debug logging
294
+ const DEBUG_LOGGING = false;
295
+
296
+ // Lock to prevent infinite loops when rendering our overlay
297
+ let renderingLock = false;
298
+ let renderingLockTimeout = null;
299
+
300
+ // How long to ignore new events after starting a render (ms)
301
+ // Should match HIGHLIGHT_DURATION in the overlay to prevent false triggers
302
+ const RENDER_LOCK_DURATION = 350;
303
+
304
+ // Track nativeTags of components we're currently highlighting
305
+ // This helps us identify (and skip) our own overlay Views if they re-render
306
+ const renderedOverlayTags = new Set();
307
+
308
+ /**
309
+ * Check if a nativeTag belongs to our overlay (was rendered by us previously)
310
+ */
311
+ function isOurOverlayTag(nativeTag) {
312
+ if (nativeTag == null) return false;
313
+ return renderedOverlayTags.has(nativeTag);
314
+ }
315
+
316
+ // ============================================================================
317
+ // OPTIMIZED DEV TOOLS DETECTION
318
+ // ============================================================================
319
+ // Performance optimizations applied:
320
+ // 1. Result caching by nativeTag (same tag = same result)
321
+ // 2. Set-based O(1) lookups instead of multiple string comparisons
322
+ // 3. Component name check FIRST (appears early in tree, ~depth 5-8)
323
+ // 4. Early exit on first match
324
+ // 5. Cached property access to avoid repeated traversal
325
+ // ============================================================================
326
+
327
+ // Components that MUST always be excluded to prevent infinite loops.
328
+ // Includes the Highlight Updates overlay AND the Events tool (which subscribes
329
+ // to render callbacks via RenderTracker.onRenderEvent - tracking its renders
330
+ // would create an infinite callback loop).
331
+ const HIGHLIGHT_OVERLAY_COMPONENTS = new Set([
332
+ // Highlight Updates overlay components
333
+ "HighlightUpdatesOverlay", "HighlightUpdatesModal", "HighlightFilterView", "RenderDetailView", "RenderListItem", "RenderListItemInner", "RenderHistoryViewer", "RenderHistoryFooter", "RenderCauseBadge", "TwoLevelCauseBadge", "EnhancedCauseDisplay", "IsolatedRenderList", "IsolatedRenderListInner", "StatsDisplay", "StatsDisplayInner", "CurrentStateView", "EventStepperFooter",
334
+ // Events tool components - subscribes to onRenderEvent, tracking these causes infinite loops
335
+ "EventsModal", "UnifiedEventList", "UnifiedEventItem", "UnifiedEventDetail", "UnifiedEventFilters", "UnifiedEventViewer", "ReactQueryEventDetail", "EventsCopySettingsView"]);
336
+
337
+ // Native IDs that MUST always be excluded (highlight overlay)
338
+ const HIGHLIGHT_OVERLAY_NATIVE_IDS = new Set(["highlight-updates-overlay", "__rn_buoy__highlight-modal"]);
339
+
340
+ // Prefixes for always-excluded components (highlight overlay + events tool)
341
+ const HIGHLIGHT_OVERLAY_PREFIXES = ["HighlightUpdates", "RenderList", "RenderDetail", "RenderHistory", "RenderCause", "EventStepper",
342
+ // Events tool - subscribes to onRenderEvent, must always be excluded
343
+ "UnifiedEvent", "EventsModal", "EventsCopy"];
344
+
345
+ // Other dev tools components - can be toggled via excludeDevTools setting
346
+ const OTHER_DEV_TOOLS_COMPONENTS = new Set([
347
+ // React Buoy devtools components
348
+ "JsModalComponent", "JsModal", "TypePicker", "PatternInput", "PatternChip", "DetectedItemsSection", "DetectedCategoryBadge", "IdentifierBadge", "CategoryBadge", "AppRenderer", "AppOverlay", "FloatingTools", "DialDevTools", "DevToolsVisibilityProvider", "AppHostProvider", "MinimizedToolsProvider",
349
+ // Shared UI components used in modals
350
+ "ModalHeader", "TabSelector", "SectionHeader", "DraggableHeader", "WindowControls",
351
+ // Shared UI data viewer components (JSON diff viewers, etc.)
352
+ "TreeDiffViewer", "DataViewer", "SplitDiffViewer", "VirtualizedDataExplorer", "DiffSummary", "TypeLegend", "IndentGuides", "IndentGuidesOverlay", "CyberpunkInput", "DiffView", "AnswerCard", "DetailsSection", "DetailRow", "QuickActionsSection", "FilterOptionCard",
353
+ // Modal header sub-components
354
+ "SearchSection", "SearchSectionInner", "HeaderActions", "HeaderActionsInner", "MainListHeader", "FilterViewHeader", "DetailViewHeader",
355
+ // Floating menu components (minimized tools, dial, etc.)
356
+ "FloatingMenu", "FloatingDevTools", "MinimizedToolsStack", "MinimizedToolsContext", "GlitchToolButton", "ExpandablePopover", "CollapsedPeek", "ExpandedWrapper", "DialIcon", "DialMenu", "DialIconItem", "OnboardingTooltip", "MenuLauncherIcon", "DevToolsSettingsModal", "SettingsModal",
357
+ // Image Overlay components
358
+ "ImageOverlayModal", "ImageOverlayStandalone", "ToolCard", "ToolIcon", "GripVerticalIcon", "UserStatus", "Divider",
359
+ // Shared UI icon components (Chevrons, etc.)
360
+ "ChevronDown", "ChevronUp", "ChevronLeft", "ChevronRight", "ChevronDownIcon", "ChevronUpIcon", "ChevronLeftIcon", "ChevronRightIcon",
361
+ // React Native LogBox components (shown on reload/errors)
362
+ "LogBox", "LogBoxLog", "LogBoxLogNotification", "LogBoxNotificationContainer", "_LogBoxNotificationContainer", "LogBoxInspector", "LogBoxInspectorContainer", "LogBoxInspectorHeader", "LogBoxInspectorBody", "LogBoxInspectorFooter", "LogBoxInspectorMessageHeader", "LogBoxInspectorStackFrame", "LogBoxInspectorSection", "LogBoxButton", "LogBoxMessage"]);
363
+
364
+ // Other dev tools prefixes - can be toggled via excludeDevTools setting
365
+ const OTHER_DEV_TOOLS_PREFIXES = ["JsModal", "TreeDiff", "DataViewer", "DiffView", "DiffSummary", "Virtualized",
366
+ // Floating menu prefixes
367
+ "Floating", "Minimized", "Dial", "Expandable", "Chevron", "Glitch", "Settings", "Onboarding", "DevTools", "ImageOverlay"];
368
+
369
+ // Other dev tools native IDs - can be toggled
370
+ const OTHER_DEV_TOOLS_NATIVE_IDS = new Set(["jsmodal-root", "image-overlay-standalone",
371
+ // LogBox native IDs
372
+ "logbox_inspector", "logbox"]);
373
+
374
+ // Cache: nativeTag -> isDevTools (avoid re-walking tree for same node)
375
+ const devToolsNodeCache = new Map();
376
+ const CACHE_MAX_SIZE = 500;
377
+
378
+ /**
379
+ * Clear the devtools node cache.
380
+ * Call this when the excludeDevTools setting changes to re-evaluate all nodes.
381
+ */
382
+ function clearDevToolsCache() {
383
+ devToolsNodeCache.clear();
384
+ }
385
+
386
+ /**
387
+ * Check if a nativeID belongs to highlight overlay (always excluded)
388
+ */
389
+ function isHighlightOverlayNativeID(nativeID) {
390
+ if (!nativeID) return false;
391
+ // Direct Set lookup (O(1))
392
+ if (HIGHLIGHT_OVERLAY_NATIVE_IDS.has(nativeID)) return true;
393
+ // Prefix check for highlight overlay
394
+ if (nativeID.startsWith("__highlight_")) return true;
395
+ return false;
396
+ }
397
+
398
+ /**
399
+ * Check if a nativeID belongs to other dev tools (optionally excluded)
400
+ */
401
+ function isOtherDevToolsNativeID(nativeID) {
402
+ if (!nativeID) return false;
403
+ // Direct Set lookup (O(1))
404
+ if (OTHER_DEV_TOOLS_NATIVE_IDS.has(nativeID)) return true;
405
+ // Prefix checks for other devtools nativeIDs
406
+ const firstChar = nativeID.charCodeAt(0);
407
+ if (firstChar === 95) {
408
+ // '_' = 95
409
+ if (nativeID.startsWith("__rn_buoy__")) return true;
410
+ }
411
+ // Check for LogBox nativeIDs (start with 'l')
412
+ if (firstChar === 108 && nativeID.startsWith("logbox")) {
413
+ // 'l' = 108
414
+ return true;
415
+ }
416
+ return false;
417
+ }
418
+
419
+ /**
420
+ * Get component name from fiber (cached property access pattern)
421
+ * For host components (RCTView, RCTText), returns the native type.
422
+ * Use getOwningComponentName to get the React component that rendered it.
423
+ */
424
+ function getComponentName(fiber) {
425
+ if (!fiber) return null;
426
+ // Most common: type.name
427
+ const type = fiber.type;
428
+ if (type) {
429
+ if (typeof type === 'string') return type;
430
+ if (type.name) return type.name;
431
+ if (type.displayName) return type.displayName;
432
+ }
433
+ // Fallback: elementType
434
+ const elementType = fiber.elementType;
435
+ if (elementType) {
436
+ if (elementType.name) return elementType.name;
437
+ if (elementType.displayName) return elementType.displayName;
438
+ }
439
+ return null;
440
+ }
441
+
442
+ // Common React Native internal component names to skip when finding user components
443
+ const INTERNAL_COMPONENT_NAMES = new Set([
444
+ // React Native core
445
+ 'View', 'Text', 'TextImpl', 'Image', 'ScrollView', 'FlatList', 'SectionList', 'TouchableOpacity', 'TouchableHighlight', 'TouchableWithoutFeedback', 'Pressable', 'TextInput', 'Switch', 'ActivityIndicator', 'Modal', 'StatusBar', 'KeyboardAvoidingView',
446
+ // Animated components
447
+ 'AnimatedComponent', 'AnimatedComponentWrapper',
448
+ // React Navigation / Screens
449
+ 'ScreenContainer', 'ScreenStack', 'Screen', 'ScreenContentWrapper',
450
+ // SVG components
451
+ 'Svg', 'G', 'Path', 'Rect', 'Circle', 'Line', 'Polygon', 'Polyline', 'Ellipse', 'Text as SVGText', 'TSpan', 'TextPath', 'Use', 'Symbol', 'Defs', 'ClipPath', 'LinearGradient', 'RadialGradient', 'Stop', 'Mask', 'Pattern', 'Image as SVGImage',
452
+ // SafeArea
453
+ 'SafeAreaProvider', 'SafeAreaView', 'SafeAreaListener',
454
+ // Gesture Handler
455
+ 'GestureHandlerRootView', 'GestureDetector',
456
+ // Reanimated
457
+ 'ReanimatedView', 'ReanimatedText', 'ReanimatedImage', 'ReanimatedScrollView',
458
+ // Common wrapper names
459
+ 'Fragment', 'Suspense', 'Provider', 'Consumer', 'Context', 'ForwardRef']);
460
+
461
+ /**
462
+ * Check if a component name is an internal/wrapper component that should be skipped
463
+ */
464
+ function isInternalComponent(name) {
465
+ if (!name) return true;
466
+ if (INTERNAL_COMPONENT_NAMES.has(name)) return true;
467
+ // Skip anonymous components and common patterns
468
+ if (name === 'Unknown' || name === 'Component') return true;
469
+ // Skip Animated.* wrappers
470
+ if (name.startsWith('Animated')) return true;
471
+ return false;
472
+ }
473
+
474
+ /**
475
+ * Get the owning React component name for a host fiber.
476
+ * Walks up the fiber tree to find the first user-defined component,
477
+ * skipping React Native internal components.
478
+ */
479
+ function getOwningComponentName(fiber) {
480
+ if (!fiber) return null;
481
+
482
+ // Walk up the fiber tree looking for a user-defined component
483
+ let current = fiber._debugOwner || fiber.return;
484
+ let depth = 0;
485
+ let firstNonHostName = null;
486
+ while (current && depth < 30) {
487
+ const name = getComponentName(current);
488
+
489
+ // Skip host components (their type is a string like "RCTView")
490
+ if (name && typeof current.type !== 'string') {
491
+ // Remember the first non-host component as fallback
492
+ if (!firstNonHostName) {
493
+ firstNonHostName = name;
494
+ }
495
+ // Return this component if it's not an internal wrapper
496
+ if (!isInternalComponent(name)) {
497
+ return name;
498
+ }
499
+ }
500
+ current = current.return;
501
+ depth++;
502
+ }
503
+
504
+ // Fallback to first non-host component found (even if internal)
505
+ return firstNonHostName;
506
+ }
507
+
508
+ /**
509
+ * Check if a stateNode belongs to our dev tools.
510
+ *
511
+ * OPTIMIZED: Uses caching, O(1) Set lookups, and early exit patterns.
512
+ * Walks up fiber tree checking component names (fast) before nativeIDs.
513
+ *
514
+ * When excludeDevTools setting is false, only the Highlight Updates overlay
515
+ * is excluded (to prevent infinite loops). Other dev tools will be highlighted.
516
+ */
517
+ function isOurOverlayNode(stateNode) {
518
+ const node = stateNode;
519
+ // Fabric: fiber is at canonical.internalInstanceHandle
520
+ // Paper/Legacy: fiber is at _internalInstanceHandle directly on stateNode
521
+ // RN CLI DEV: fiber is at _internalFiberInstanceHandleDEV
522
+ const fiber = node?.canonical?.internalInstanceHandle || node?._internalInstanceHandle || node?._internalFiberInstanceHandleDEV;
523
+
524
+ // Get nativeTag for caching
525
+ const nativeTag = getNativeTag(stateNode) || getNativeTag(node?.canonical?.publicInstance);
526
+
527
+ // Check if we should exclude all dev tools or just highlight overlay
528
+ const excludeDevTools = _RenderTracker.RenderTracker.getSettings().excludeDevTools;
529
+
530
+ // Check cache first (O(1)) - but only for the current excludeDevTools setting
531
+ // When excludeDevTools is false, skip cache to re-evaluate all nodes
532
+ if (nativeTag != null && excludeDevTools) {
533
+ const cached = devToolsNodeCache.get(nativeTag);
534
+ if (cached !== undefined) {
535
+ return cached;
536
+ }
537
+ }
538
+ let result = false;
539
+
540
+ // Fast path: check direct nativeID
541
+ const directNativeID = fiber?.pendingProps?.nativeID || fiber?.memoizedProps?.nativeID || node?.canonical?.currentProps?.nativeID || null;
542
+
543
+ // Always check highlight overlay nativeIDs first (must always be excluded)
544
+ if (isHighlightOverlayNativeID(directNativeID)) {
545
+ result = true;
546
+ } else if (excludeDevTools && isOtherDevToolsNativeID(directNativeID)) {
547
+ // Only check other dev tools if excludeDevTools is enabled
548
+ result = true;
549
+ }
550
+ if (!result && fiber) {
551
+ // Walk up fiber tree - check component names FIRST (they appear early)
552
+ let current = fiber;
553
+ let depth = 0;
554
+
555
+ // Reduced max depth - component names appear by depth 15 typically
556
+ while (current && depth < 30) {
557
+ // Component name check FIRST (faster, appears earlier in tree)
558
+ const name = getComponentName(current);
559
+ if (name) {
560
+ // Always check highlight overlay components (must always be excluded)
561
+ if (HIGHLIGHT_OVERLAY_COMPONENTS.has(name)) {
562
+ result = true;
563
+ break;
564
+ }
565
+ // Check highlight overlay prefixes
566
+ for (const prefix of HIGHLIGHT_OVERLAY_PREFIXES) {
567
+ if (name.startsWith(prefix)) {
568
+ result = true;
569
+ break;
570
+ }
571
+ }
572
+ if (result) break;
573
+
574
+ // Only check other dev tools if excludeDevTools is enabled
575
+ if (excludeDevTools) {
576
+ if (OTHER_DEV_TOOLS_COMPONENTS.has(name)) {
577
+ result = true;
578
+ break;
579
+ }
580
+ // Check other dev tools prefixes
581
+ for (const prefix of OTHER_DEV_TOOLS_PREFIXES) {
582
+ if (name.startsWith(prefix)) {
583
+ result = true;
584
+ break;
585
+ }
586
+ }
587
+ if (result) break;
588
+ }
589
+ }
590
+
591
+ // NativeID check (only if component name didn't match)
592
+ const nativeID = current.pendingProps?.nativeID || current.memoizedProps?.nativeID;
593
+ if (isHighlightOverlayNativeID(nativeID)) {
594
+ result = true;
595
+ break;
596
+ }
597
+ if (excludeDevTools && isOtherDevToolsNativeID(nativeID)) {
598
+ result = true;
599
+ break;
600
+ }
601
+ current = current.return;
602
+ depth++;
603
+ }
604
+ }
605
+
606
+ // Only cache positive results when excludeDevTools is true (default mode)
607
+ // Don't cache when excludeDevTools is false to avoid complex cache invalidation
608
+ if (result && nativeTag != null && excludeDevTools) {
609
+ if (devToolsNodeCache.size >= CACHE_MAX_SIZE) {
610
+ // Clear oldest entries (simple strategy - clear half)
611
+ const entries = Array.from(devToolsNodeCache.keys());
612
+ for (let i = 0; i < CACHE_MAX_SIZE / 2; i++) {
613
+ devToolsNodeCache.delete(entries[i]);
614
+ }
615
+ }
616
+ devToolsNodeCache.set(nativeTag, result);
617
+ }
618
+ return result;
619
+ }
620
+
621
+ /**
622
+ * Get color based on render count (same algorithm as DevTools)
623
+ * More renders = warmer color (cyan → yellow)
624
+ */
625
+ function getColorForRenderCount(count) {
626
+ // Clamp to color array bounds
627
+ const index = Math.min(count - 1, COLORS.length - 1);
628
+ return COLORS[Math.max(0, index)];
629
+ }
630
+
631
+ /**
632
+ * Handle traceUpdates event from DevTools backend
633
+ * This is called with a Set of stateNodes that should be highlighted
634
+ *
635
+ * Strategy to prevent infinite loops:
636
+ * 1. Use a rendering lock while rendering highlights
637
+ * 2. Use an isProcessing flag to prevent concurrent processing
638
+ * 3. If Chrome DevTools agent is available, use native overlay (faster, no React)
639
+ * 4. Otherwise, use our React overlay with locks to prevent cascading renders
640
+ */
641
+ function handleTraceUpdates(nodes) {
642
+ if (nodes.size === 0) {
643
+ return;
644
+ }
645
+
646
+ // Skip if neither visual toggle nor background tracking is enabled
647
+ if (!globalEnabled && !backgroundTrackingEnabled) {
648
+ return;
649
+ }
650
+
651
+ // Skip processing when paused - don't count renders or show highlights
652
+ const trackerState = _RenderTracker.RenderTracker.getState();
653
+ if (trackerState.isPaused) {
654
+ return;
655
+ }
656
+
657
+ // Mark event received for end-to-end timing
658
+ if (_PerformanceLogger.PerformanceLogger.isEnabled()) {
659
+ (0, _PerformanceLogger.markEventReceived)();
660
+ }
661
+
662
+ // Start performance timing
663
+ const batchSize = _RenderTracker.RenderTracker.getBatchSize();
664
+ const perfTimer = _PerformanceLogger.PerformanceLogger.startBatch(nodes.size, batchSize);
665
+
666
+ // NOTE: Lock-based skipping disabled - relying on nativeID filtering instead
667
+ // If nativeID filtering doesn't work, re-enable this:
668
+ //
669
+ // if (renderingLock || isProcessing) {
670
+ // if (DEBUG_LOGGING) {
671
+ // console.log(`[HighlightUpdates] SKIPPED - lock:${renderingLock} processing:${isProcessing}`);
672
+ // }
673
+ // return;
674
+ // }
675
+ // isProcessing = true;
676
+
677
+ // Process nodes: track render counts and assign colors
678
+ // Filter out our own overlay nodes to prevent infinite loop
679
+ // Also apply user-defined filters to both overlay AND tracking
680
+ const nodesToDraw = [];
681
+ let skippedOverlayCount = 0;
682
+ let skippedByFilterCount = 0;
683
+ const hasActiveFilters = _RenderTracker.RenderTracker.hasActiveFilters();
684
+ for (const stateNode of nodes) {
685
+ if (stateNode && typeof stateNode === "object") {
686
+ try {
687
+ // Skip our own overlay nodes (identified by nativeID)
688
+ if (isOurOverlayNode(stateNode)) {
689
+ skippedOverlayCount++;
690
+ continue;
691
+ }
692
+
693
+ // Get nativeTag for tracking render counts
694
+ const publicInstance = getPublicInstance(stateNode);
695
+ const nativeTag = getNativeTag(stateNode) || getNativeTag(publicInstance);
696
+ if (nativeTag == null) {
697
+ continue;
698
+ }
699
+
700
+ // Extract component info for filtering
701
+ const componentInfo = extractComponentInfo(stateNode);
702
+
703
+ // Apply user-defined filters - skip components that don't pass filters
704
+ // This affects BOTH the overlay highlights AND the render list
705
+ if (hasActiveFilters && !_RenderTracker.RenderTracker.passesFilters(componentInfo)) {
706
+ skippedByFilterCount++;
707
+ continue;
708
+ }
709
+
710
+ // Check if render counting is enabled
711
+ const showRenderCount = _RenderTracker.RenderTracker.getSettings().showRenderCount;
712
+ let newCount;
713
+ let color;
714
+ if (showRenderCount) {
715
+ // Get current render count and increment (using nativeTag as stable key)
716
+ const currentCount = nodeRenderCounts.get(nativeTag) || 0;
717
+ newCount = currentCount + 1;
718
+ nodeRenderCounts.set(nativeTag, newCount);
719
+ // Assign color based on render count
720
+ color = getColorForRenderCount(newCount);
721
+ } else {
722
+ // Skip counting - use fixed color and count of 0
723
+ newCount = 0;
724
+ color = COLORS[0]; // Use first color (cyan)
725
+ }
726
+ nodesToDraw.push({
727
+ node: stateNode,
728
+ color,
729
+ count: newCount
730
+ });
731
+ } catch {
732
+ // Skip nodes from custom renderers (e.g. React Native Skia) that have
733
+ // non-standard stateNode structures
734
+ }
735
+ }
736
+ }
737
+
738
+ // Mark filtering phase complete (includes both overlay nodes and user-filtered nodes)
739
+ perfTimer.markFilteringComplete(skippedOverlayCount + skippedByFilterCount, nodesToDraw.length);
740
+
741
+ // Only log if there are real updates (not just overlay re-renders)
742
+ if (nodesToDraw.length === 0) {
743
+ // All nodes were overlay nodes - silently skip
744
+ perfTimer.finish(); // Still log the batch even if empty
745
+ return;
746
+ }
747
+
748
+ // Log actual component updates
749
+ if (DEBUG_LOGGING) {
750
+ console.log(`[HighlightUpdates] ${nodesToDraw.length} component(s) re-rendered`);
751
+ }
752
+
753
+ // NOTE: We prefer our React overlay for standalone operation.
754
+ // The native overlay only works when Chrome DevTools profiler is actively enabled.
755
+ // Uncomment below to use native overlay when available:
756
+ //
757
+ // const agent = hook?.reactDevtoolsAgent;
758
+ // if (agent?.emit) {
759
+ // if (DEBUG_LOGGING) {
760
+ // console.log(`[HighlightUpdates] Using native overlay (agent available)`);
761
+ // }
762
+ // agent.emit("drawTraceUpdates", nodesToDraw);
763
+ // isProcessing = false;
764
+ // return;
765
+ // }
766
+
767
+ // Check if we should process - either we have a visual callback OR event callbacks
768
+ const hasEventCallbacks = _RenderTracker.RenderTracker.getRenderEventCallbackCount() > 0;
769
+ if (!highlightCallback && !hasEventCallbacks) {
770
+ if (DEBUG_LOGGING) {
771
+ console.log(`[HighlightUpdates] No highlightCallback and no event callbacks - skipping render`);
772
+ }
773
+ isProcessing = false;
774
+ return;
775
+ }
776
+
777
+ // NOTE: Lock disabled - relying on nativeID filtering instead
778
+
779
+ // Measure each node and call the highlight callback
780
+ // Use batch size from RenderTracker settings (default: 150)
781
+ // Note: batchSize already retrieved above for perfTimer
782
+ perfTimer.markMeasurementStart();
783
+ const measurePromises = nodesToDraw.slice(0, batchSize).map(({
784
+ node: stateNode,
785
+ color,
786
+ count
787
+ }) => new Promise(resolve => {
788
+ const publicInstance = getPublicInstance(stateNode);
789
+ if (!publicInstance) {
790
+ resolve({
791
+ rect: null,
792
+ stateNode,
793
+ color,
794
+ count
795
+ });
796
+ return;
797
+ }
798
+ const nativeTag = getNativeTag(stateNode) || getNativeTag(publicInstance);
799
+ if (nativeTag == null) {
800
+ resolve({
801
+ rect: null,
802
+ stateNode,
803
+ color,
804
+ count
805
+ });
806
+ return;
807
+ }
808
+ try {
809
+ publicInstance.measure((x, y, width, height, pageX, pageY) => {
810
+ if (pageX == null || pageY == null || width == null || height == null) {
811
+ resolve({
812
+ rect: null,
813
+ stateNode,
814
+ color,
815
+ count
816
+ });
817
+ return;
818
+ }
819
+ resolve({
820
+ rect: {
821
+ id: nativeTag,
822
+ x: pageX,
823
+ y: pageY,
824
+ width,
825
+ height,
826
+ color,
827
+ count
828
+ },
829
+ stateNode,
830
+ color,
831
+ count
832
+ });
833
+ });
834
+ } catch (error) {
835
+ resolve({
836
+ rect: null,
837
+ stateNode,
838
+ color,
839
+ count
840
+ });
841
+ }
842
+ }));
843
+ Promise.all(measurePromises).then(results => {
844
+ const validResults = results.filter(r => r.rect !== null);
845
+ const rects = validResults.map(r => r.rect);
846
+
847
+ // Mark measurement phase complete
848
+ perfTimer.markMeasurementComplete(validResults.length, results.length - validResults.length);
849
+
850
+ // Keep a live handle to each measured node so the desktop's "capture this
851
+ // component" flow can re-measure (and scroll to) it on demand later.
852
+ // Defensive: never let registration break the measurement/tracking batch.
853
+ try {
854
+ for (const r of validResults) {
855
+ if (r.rect) registerTrackedNode(r.rect.id, r.stateNode);
856
+ }
857
+ } catch (e) {
858
+ debugLog("registerTrackedNode batch failed", e);
859
+ }
860
+
861
+ // Track renders - behavior differs based on what's enabled:
862
+ // - globalEnabled (visual tool): full tracking with storage and list updates
863
+ // - backgroundTrackingEnabled only (Events tool): emit events only, no storage
864
+ const settings = _RenderTracker.RenderTracker.getSettings();
865
+ const trackCauses = settings.trackRenderCauses && settings.showRenderCount;
866
+ let batchNativeTags = null;
867
+ if (trackCauses) {
868
+ batchNativeTags = new Set();
869
+ for (const {
870
+ rect
871
+ } of validResults) {
872
+ if (rect) {
873
+ batchNativeTags.add(rect.id);
874
+ }
875
+ }
876
+ }
877
+ if (globalEnabled) {
878
+ // Visual tool is on - full tracking with storage and list notifications
879
+ _RenderTracker.RenderTracker.startBatch();
880
+ for (const {
881
+ rect,
882
+ stateNode,
883
+ color,
884
+ count
885
+ } of validResults) {
886
+ if (rect) {
887
+ const componentInfo = extractComponentInfo(stateNode);
888
+ let renderCause;
889
+ if (trackCauses && batchNativeTags) {
890
+ const node = stateNode;
891
+ const fiber = node?.canonical?.internalInstanceHandle;
892
+ renderCause = (0, _RenderCauseDetector.detectRenderCause)(rect.id, fiber, batchNativeTags, settings.debugLogLevel);
893
+ }
894
+ _RenderTracker.RenderTracker.trackRender({
895
+ nativeTag: rect.id,
896
+ viewType: componentInfo.viewType,
897
+ testID: componentInfo.testID,
898
+ nativeID: componentInfo.nativeID,
899
+ accessibilityLabel: componentInfo.accessibilityLabel,
900
+ componentName: componentInfo.componentName,
901
+ measurements: {
902
+ x: rect.x,
903
+ y: rect.y,
904
+ width: rect.width,
905
+ height: rect.height
906
+ },
907
+ color,
908
+ count,
909
+ renderCause
910
+ });
911
+ }
912
+ }
913
+ _RenderTracker.RenderTracker.endBatch();
914
+ } else {
915
+ // Only background tracking (Events tool) - emit events without storage
916
+ for (const {
917
+ rect,
918
+ stateNode,
919
+ color,
920
+ count
921
+ } of validResults) {
922
+ if (rect) {
923
+ const componentInfo = extractComponentInfo(stateNode);
924
+ let renderCause;
925
+ if (trackCauses && batchNativeTags) {
926
+ const node = stateNode;
927
+ const fiber = node?.canonical?.internalInstanceHandle;
928
+ renderCause = (0, _RenderCauseDetector.detectRenderCause)(rect.id, fiber, batchNativeTags, settings.debugLogLevel);
929
+ }
930
+ _RenderTracker.RenderTracker.emitRenderEvent({
931
+ nativeTag: rect.id,
932
+ viewType: componentInfo.viewType,
933
+ testID: componentInfo.testID,
934
+ nativeID: componentInfo.nativeID,
935
+ accessibilityLabel: componentInfo.accessibilityLabel,
936
+ componentName: componentInfo.componentName,
937
+ measurements: {
938
+ x: rect.x,
939
+ y: rect.y,
940
+ width: rect.width,
941
+ height: rect.height
942
+ },
943
+ color,
944
+ count,
945
+ renderCause
946
+ });
947
+ }
948
+ }
949
+ }
950
+
951
+ // Mark tracking phase complete
952
+ perfTimer.markTrackingComplete();
953
+
954
+ // Only show visual highlights when the visual tool is enabled (not just
955
+ // background tracking) AND not running in silent mode (screenshot tool).
956
+ if (rects.length > 0 && highlightCallback && globalEnabled && !highlightsSuppressed) {
957
+ highlightCallback(rects);
958
+ }
959
+
960
+ // Mark callback phase complete and finish timing
961
+ perfTimer.markCallbackComplete();
962
+ perfTimer.finish();
963
+ }).catch(error => {
964
+ console.error("[HighlightUpdates] Error in measurement pipeline:", error);
965
+ perfTimer.finish(); // Still log timing even on error
966
+ });
967
+ }
968
+
969
+ /* ================================================================== *
970
+ * Component locator — powers the desktop "screenshot this component"
971
+ * flow. The dashboard sends a query (testID / nativeID / name / nativeTag);
972
+ * we resolve it to a live native node, best-effort scroll it into view,
973
+ * re-measure its on-screen rectangle, and return that (plus the pixel scale
974
+ * and screen size) so the desktop can crop the simulator screenshot to it.
975
+ * ================================================================== */
976
+
977
+ // nativeTag → live node, weakly held (when WeakRef exists in the runtime) so
978
+ // unmounted views can still be GC'd. WeakRef isn't in this package's TS lib, so
979
+ // reach it through globalThis rather than the (untyped) global.
980
+ const WeakRefCtor = globalThis.WeakRef;
981
+ const nodeRegistry = new Map();
982
+ function registerTrackedNode(nativeTag, stateNode) {
983
+ // WeakRef throws if the target isn't an object, so guard hard — this runs in
984
+ // the measure pipeline and must never break tracking.
985
+ if (nativeTag == null || stateNode == null || typeof stateNode !== "object") {
986
+ return;
987
+ }
988
+ try {
989
+ nodeRegistry.set(nativeTag, WeakRefCtor ? new WeakRefCtor(stateNode) : {
990
+ deref: () => stateNode
991
+ });
992
+ } catch {
993
+ nodeRegistry.set(nativeTag, {
994
+ deref: () => stateNode
995
+ });
996
+ }
997
+ }
998
+ function derefNode(nativeTag) {
999
+ const ref = nodeRegistry.get(nativeTag);
1000
+ const node = ref?.deref();
1001
+ if (!node) nodeRegistry.delete(nativeTag);
1002
+ return node ?? null;
1003
+ }
1004
+
1005
+ /** Promisified absolute measure → on-screen rect in points (or null). */
1006
+ function measureNode(publicInstance) {
1007
+ return new Promise(resolve => {
1008
+ try {
1009
+ publicInstance.measure((_x, _y, width, height, pageX, pageY) => {
1010
+ if (pageX == null || pageY == null || width == null || height == null) {
1011
+ resolve(null);
1012
+ } else {
1013
+ resolve({
1014
+ x: pageX,
1015
+ y: pageY,
1016
+ width,
1017
+ height
1018
+ });
1019
+ }
1020
+ });
1021
+ } catch {
1022
+ resolve(null);
1023
+ }
1024
+ });
1025
+ }
1026
+ function getFiberFromNode(stateNode) {
1027
+ const node = stateNode;
1028
+ return node?.canonical?.internalInstanceHandle || node?._internalInstanceHandle || node?._internalFiberInstanceHandleDEV || null;
1029
+ }
1030
+
1031
+ /**
1032
+ * Walk up the fiber tree from a node to find the nearest ScrollView-like
1033
+ * instance (anything exposing scrollTo + an inner content node).
1034
+ */
1035
+ function findScrollAncestor(stateNode) {
1036
+ let fiber = getFiberFromNode(stateNode);
1037
+ let guard = 0;
1038
+ while (fiber && guard++ < 200) {
1039
+ const inst = fiber.stateNode;
1040
+ if (inst && typeof inst.scrollTo === "function") {
1041
+ const innerNode = typeof inst.getInnerViewNode === "function" && inst.getInnerViewNode() || typeof inst.getScrollableNode === "function" && inst.getScrollableNode() || inst;
1042
+ return {
1043
+ instance: inst,
1044
+ innerNode
1045
+ };
1046
+ }
1047
+ fiber = fiber.return;
1048
+ }
1049
+ return null;
1050
+ }
1051
+
1052
+ /**
1053
+ * Best-effort scroll of an ancestor ScrollView so the target sits near the top
1054
+ * of its viewport. Returns true only if a scroll was actually issued. Never
1055
+ * throws — if anything is missing (no ScrollView, measureLayout unsupported)
1056
+ * it quietly returns false and the caller measures wherever the node is.
1057
+ */
1058
+ async function scrollDescendantIntoView(stateNode, publicInstance, margin) {
1059
+ try {
1060
+ const ancestor = findScrollAncestor(stateNode);
1061
+ if (!ancestor) return false;
1062
+
1063
+ // Position of the target WITHIN the scroll content — independent of the
1064
+ // current scroll offset (the standard RN keyboard-aware-scroll technique).
1065
+ // Try the Fabric path (ref.measureLayout against the inner view instance)
1066
+ // first, then fall back to the legacy UIManager.measureLayout with tags.
1067
+ const inst = publicInstance;
1068
+ let top = null;
1069
+
1070
+ // On some architectures measureLayout invokes NEITHER callback, which would
1071
+ // hang the await forever — always race it against a short timeout.
1072
+ const withTimeout = run => new Promise(resolve => {
1073
+ let done = false;
1074
+ const settle = v => {
1075
+ if (done) return;
1076
+ done = true;
1077
+ resolve(v);
1078
+ };
1079
+ const timer = setTimeout(() => settle(null), 600);
1080
+ try {
1081
+ run(v => {
1082
+ clearTimeout(timer);
1083
+ settle(v);
1084
+ });
1085
+ } catch {
1086
+ clearTimeout(timer);
1087
+ settle(null);
1088
+ }
1089
+ });
1090
+ if (typeof inst.measureLayout === "function") {
1091
+ top = await withTimeout(resolve => inst.measureLayout(ancestor.innerNode, (_left, t) => resolve(t), () => resolve(null)));
1092
+ }
1093
+ if (top == null) {
1094
+ const targetHandle = (0, _reactNative.findNodeHandle)(publicInstance);
1095
+ const innerHandle = typeof ancestor.innerNode === "number" ? ancestor.innerNode : (0, _reactNative.findNodeHandle)(ancestor.innerNode);
1096
+ if (targetHandle != null && innerHandle != null) {
1097
+ top = await withTimeout(resolve => _reactNative.UIManager.measureLayout(targetHandle, innerHandle, () => resolve(null), (_left, t) => resolve(t)));
1098
+ }
1099
+ }
1100
+ if (top == null) return false;
1101
+ ancestor.instance.scrollTo({
1102
+ y: Math.max(0, top - margin),
1103
+ animated: false
1104
+ });
1105
+ // Let the scroll + layout settle before the caller re-measures.
1106
+ await new Promise(r => setTimeout(r, 80));
1107
+ return true;
1108
+ } catch {
1109
+ return false;
1110
+ }
1111
+ }
1112
+ function matchScore(r, q) {
1113
+ const fields = [r.testID, r.nativeID, r.accessibilityLabel, r.componentName, r.viewType, String(r.nativeTag)];
1114
+ let best = 0;
1115
+ for (const f of fields) {
1116
+ if (!f) continue;
1117
+ const lower = f.toLowerCase();
1118
+ if (lower === q) return 3; // exact wins outright
1119
+ if (lower.startsWith(q)) best = Math.max(best, 2);else if (lower.includes(q)) best = Math.max(best, 1);
1120
+ }
1121
+ return best;
1122
+ }
1123
+
1124
+ /**
1125
+ * Resolve a component query to a fresh on-screen rectangle. See
1126
+ * LocateComponentResult for the shape. Always resolves (never rejects).
1127
+ */
1128
+ async function locateComponent(params) {
1129
+ const scrollIntoView = params.scrollIntoView !== false;
1130
+ const margin = typeof params.margin === "number" ? params.margin : 12;
1131
+ const renders = _RenderTracker.RenderTracker.getRenders();
1132
+ if (renders.length === 0) {
1133
+ return {
1134
+ matched: false,
1135
+ reason: "no-renders",
1136
+ candidates: []
1137
+ };
1138
+ }
1139
+
1140
+ // Rank candidates (skip ranking when an explicit nativeTag was given).
1141
+ const q = (params.query ?? "").trim().toLowerCase();
1142
+ const ranked = q ? renders.map(r => ({
1143
+ r,
1144
+ score: matchScore(r, q)
1145
+ })).filter(x => x.score > 0).sort((a, b) => b.score - a.score || b.r.lastRenderTime - a.r.lastRenderTime) : [];
1146
+ const candidates = ranked.slice(0, 8).map(({
1147
+ r
1148
+ }) => ({
1149
+ nativeTag: r.nativeTag,
1150
+ componentName: r.componentName,
1151
+ testID: r.testID,
1152
+ nativeID: r.nativeID,
1153
+ viewType: r.viewType,
1154
+ renderCount: r.renderCount
1155
+ }));
1156
+ const targetTag = params.nativeTag ?? (ranked.length > 0 ? ranked[0].r.nativeTag : undefined);
1157
+ if (targetTag == null) {
1158
+ return {
1159
+ matched: false,
1160
+ reason: "no-match",
1161
+ candidates
1162
+ };
1163
+ }
1164
+ const tracked = renders.find(r => r.nativeTag === targetTag);
1165
+
1166
+ // Try a live re-measure (and scroll) using the registered node.
1167
+ let rect = null;
1168
+ let live = false;
1169
+ let scrolled = false;
1170
+ const node = derefNode(targetTag);
1171
+ if (node) {
1172
+ const publicInstance = getPublicInstance(node);
1173
+ if (publicInstance) {
1174
+ if (scrollIntoView) {
1175
+ scrolled = await scrollDescendantIntoView(node, publicInstance, margin);
1176
+ }
1177
+ rect = await measureNode(publicInstance);
1178
+ live = !!rect;
1179
+ }
1180
+ }
1181
+
1182
+ // Fall back to the last synced measurement if the live path failed.
1183
+ if (!rect && tracked?.measurements) {
1184
+ rect = {
1185
+ ...tracked.measurements
1186
+ };
1187
+ }
1188
+ if (!rect) {
1189
+ return {
1190
+ matched: false,
1191
+ reason: "no-measurement",
1192
+ nativeTag: targetTag,
1193
+ candidates
1194
+ };
1195
+ }
1196
+ const scale = _reactNative.PixelRatio.get();
1197
+ const win = _reactNative.Dimensions.get("window");
1198
+ const inView = rect.x >= -1 && rect.y >= -1 && rect.x + rect.width <= win.width + 1 && rect.y + rect.height <= win.height + 1;
1199
+ return {
1200
+ matched: true,
1201
+ live,
1202
+ scrolled,
1203
+ inView,
1204
+ rect,
1205
+ scale,
1206
+ screen: {
1207
+ width: win.width,
1208
+ height: win.height
1209
+ },
1210
+ nativeTag: targetTag,
1211
+ componentName: tracked?.componentName,
1212
+ testID: tracked?.testID,
1213
+ candidates
1214
+ };
1215
+ }
1216
+
1217
+ /**
1218
+ * Enable or disable trace updates on all renderer interfaces.
1219
+ * This is the key function that makes standalone tracing work!
1220
+ *
1221
+ * The rendererInterfaces map contains the renderer backend for each React root.
1222
+ * Each renderer has a setTraceUpdatesEnabled function that controls whether
1223
+ * it emits 'traceUpdates' events when components re-render.
1224
+ *
1225
+ * See: react-devtools-core/dist/backend.js line 15487-15489
1226
+ */
1227
+ function setTraceUpdatesOnRenderers(enabled) {
1228
+ if (!hook?.rendererInterfaces) {
1229
+ debugLog("No rendererInterfaces available");
1230
+ return;
1231
+ }
1232
+ let count = 0;
1233
+ hook.rendererInterfaces.forEach((rendererInterface, rendererId) => {
1234
+ if (typeof rendererInterface.setTraceUpdatesEnabled === "function") {
1235
+ try {
1236
+ rendererInterface.setTraceUpdatesEnabled(enabled);
1237
+ count++;
1238
+ debugLog(`Renderer ${rendererId}: setTraceUpdatesEnabled(${enabled})`);
1239
+ } catch (error) {
1240
+ debugLog(`Renderer ${rendererId}: error setting trace updates`, error);
1241
+ }
1242
+ } else {
1243
+ debugLog(`Renderer ${rendererId}: no setTraceUpdatesEnabled method`);
1244
+ }
1245
+ });
1246
+ debugLog(`Set trace updates ${enabled ? "enabled" : "disabled"} on ${count} renderer(s)`);
1247
+
1248
+ // Also try the agent if available (in case DevTools is connected)
1249
+ if (hook.reactDevtoolsAgent?.setTraceUpdatesEnabled) {
1250
+ try {
1251
+ hook.reactDevtoolsAgent.setTraceUpdatesEnabled(enabled);
1252
+ debugLog("Also set trace updates on agent");
1253
+ } catch (error) {
1254
+ debugLog("Error setting trace updates on agent", error);
1255
+ }
1256
+ }
1257
+ }
1258
+
1259
+ /**
1260
+ * Subscribe to the traceUpdates event from the hook
1261
+ */
1262
+ function subscribeToTraceUpdates() {
1263
+ if (!hook) return;
1264
+ if (traceUpdatesUnsubscribe) return; // Already subscribed
1265
+
1266
+ debugLog("Subscribing to traceUpdates event");
1267
+
1268
+ // The hook uses EventEmitter pattern with 'sub' method
1269
+ // See: react-devtools-core/dist/backend.js line 17526
1270
+ // hook.sub('traceUpdates', agent.onTraceUpdates)
1271
+ if (typeof hook.sub === "function") {
1272
+ traceUpdatesUnsubscribe = hook.sub("traceUpdates", handleTraceUpdates);
1273
+ debugLog("Subscribed using hook.sub()");
1274
+ } else {
1275
+ debugLog("hook.sub not available, traceUpdates may not work");
1276
+ }
1277
+
1278
+ // CRITICAL: Enable trace updates on all renderers
1279
+ // Without this, the renderers won't emit traceUpdates events
1280
+ setTraceUpdatesOnRenderers(true);
1281
+ }
1282
+
1283
+ /**
1284
+ * Unsubscribe from the traceUpdates event
1285
+ */
1286
+ function unsubscribeFromTraceUpdates() {
1287
+ // Disable trace updates on renderers first
1288
+ setTraceUpdatesOnRenderers(false);
1289
+ if (traceUpdatesUnsubscribe) {
1290
+ traceUpdatesUnsubscribe();
1291
+ traceUpdatesUnsubscribe = null;
1292
+ debugLog("Unsubscribed from traceUpdates event");
1293
+ }
1294
+ }
1295
+
1296
+ /**
1297
+ * Set the callback for rendering highlights
1298
+ */
1299
+ function setHighlightCallback(callback) {
1300
+ highlightCallback = callback;
1301
+ debugLog(`Highlight callback ${callback ? "set" : "cleared"}`);
1302
+ }
1303
+
1304
+ /**
1305
+ * Set the callback for when a badge is pressed.
1306
+ * This is used to navigate to the detail view when a user taps a render count badge.
1307
+ */
1308
+ function setBadgePressCallback(callback) {
1309
+ badgePressCallback = callback;
1310
+ debugLog(`Badge press callback ${callback ? "set" : "cleared"}`);
1311
+ }
1312
+
1313
+ /**
1314
+ * Get the current badge press callback.
1315
+ * Used by the overlay to check if badge presses should be handled.
1316
+ */
1317
+ function getBadgePressCallback() {
1318
+ return badgePressCallback;
1319
+ }
1320
+
1321
+ /**
1322
+ * Handle a badge press event.
1323
+ * Calls the registered callback with the nativeTag of the component.
1324
+ */
1325
+ function handleBadgePress(nativeTag) {
1326
+ if (badgePressCallback) {
1327
+ badgePressCallback(nativeTag);
1328
+ }
1329
+ }
1330
+
1331
+ // Spotlight highlight state - for showing which component is being viewed in detail
1332
+
1333
+ let spotlightCallback = null;
1334
+ let currentSpotlightTag = null;
1335
+
1336
+ /**
1337
+ * Set the callback for spotlight highlighting.
1338
+ * Used by the overlay to show a special highlight for the component being viewed.
1339
+ */
1340
+ function setSpotlightCallback(callback) {
1341
+ spotlightCallback = callback;
1342
+ // If there's an existing spotlight, notify the new callback
1343
+ if (callback && currentSpotlightTag !== null) {
1344
+ callback(currentSpotlightTag);
1345
+ }
1346
+ }
1347
+
1348
+ /**
1349
+ * Set a spotlight highlight on a specific component.
1350
+ * This is used when viewing a component's detail to show which one it is.
1351
+ */
1352
+ function setSpotlight(nativeTag) {
1353
+ if (remoteHandler) {
1354
+ remoteHandler("setSpotlight", {
1355
+ nativeTag
1356
+ });
1357
+ return;
1358
+ }
1359
+ currentSpotlightTag = nativeTag;
1360
+ if (spotlightCallback) {
1361
+ spotlightCallback(nativeTag);
1362
+ }
1363
+ }
1364
+
1365
+ // ============================================================================
1366
+ // REMOTE MIRROR MODE
1367
+ // ============================================================================
1368
+
1369
+ let remoteHandler = null;
1370
+
1371
+ /**
1372
+ * Remote mirror mode (desktop dashboard): while a handler is set, mutations
1373
+ * (toggle/setEnabled/toggleFreeze/clearRenderCounts/setSpotlight) forward
1374
+ * (method, params) to the synced device instead of touching the local React
1375
+ * internals — the resulting state comes back via replaceRemoteState(). Pass
1376
+ * null to restore local behavior.
1377
+ */
1378
+ function setRemoteHandler(handler) {
1379
+ remoteHandler = handler;
1380
+ }
1381
+
1382
+ /**
1383
+ * Mirror the synced device's enabled/frozen flags into the local listeners
1384
+ * (so the modal's toggle buttons reflect the device). Never patches React
1385
+ * internals — it only updates the flags the UI reads.
1386
+ */
1387
+ function replaceRemoteState(state) {
1388
+ if (globalEnabled !== state.enabled) {
1389
+ globalEnabled = state.enabled;
1390
+ notifyStateListeners();
1391
+ }
1392
+ if (isFrozen !== state.frozen) {
1393
+ isFrozen = state.frozen;
1394
+ notifyFreezeListeners();
1395
+ }
1396
+ }
1397
+
1398
+ /**
1399
+ * Get the current spotlight nativeTag.
1400
+ */
1401
+ function getSpotlight() {
1402
+ return currentSpotlightTag;
1403
+ }
1404
+ function notifyStateListeners() {
1405
+ stateListeners.forEach(listener => {
1406
+ try {
1407
+ listener(globalEnabled);
1408
+ } catch (error) {
1409
+ console.error("[HighlightUpdates] Error in state listener:", error);
1410
+ }
1411
+ });
1412
+ }
1413
+ function subscribe(listener) {
1414
+ stateListeners.add(listener);
1415
+ listener(globalEnabled);
1416
+ return () => {
1417
+ stateListeners.delete(listener);
1418
+ };
1419
+ }
1420
+ function initialize() {
1421
+ if (typeof __DEV__ !== "undefined" && !__DEV__) {
1422
+ debugLog("Only available in development builds");
1423
+ return false;
1424
+ }
1425
+
1426
+ // Remote mirror mode: initialization (DevTools hook, fiber walking)
1427
+ // belongs to the device — pretend success so callers proceed to the
1428
+ // forwarded toggle.
1429
+ if (remoteHandler) {
1430
+ return true;
1431
+ }
1432
+ if (initialized) {
1433
+ return true;
1434
+ }
1435
+ hook = window?.__REACT_DEVTOOLS_GLOBAL_HOOK__ || null;
1436
+ if (!hook) {
1437
+ debugLog("React DevTools hook not found");
1438
+ return false;
1439
+ }
1440
+ debugLog("Hook found");
1441
+ debugLog(`Hook has sub: ${typeof hook.sub === "function"}`);
1442
+ debugLog(`Hook has on: ${typeof hook.on === "function"}`);
1443
+ debugLog(`Hook has emit: ${typeof hook.emit === "function"}`);
1444
+
1445
+ // Install profiler interceptor to capture what DevTools detects
1446
+ // This allows us to compare profiler data with our detection
1447
+ (0, _ProfilerInterceptor.installProfilerInterceptor)();
1448
+
1449
+ // Comparison callback available for future use when we re-enable our implementation
1450
+ // setComparisonCallback((profilerNodes: Set<unknown>) => {
1451
+ // debugLog(`[COMPARISON] Profiler detected ${profilerNodes.size} nodes`);
1452
+ // });
1453
+
1454
+ if (hook.rendererInterfaces && hook.rendererInterfaces.size > 0) {
1455
+ initialized = true;
1456
+ debugLog(`Initialized with ${hook.rendererInterfaces.size} renderer(s)`);
1457
+ exposeGlobally();
1458
+ return true;
1459
+ }
1460
+
1461
+ // Wait for renderer to be available
1462
+ const checkInterval = setInterval(() => {
1463
+ if (hook?.rendererInterfaces && hook.rendererInterfaces.size > 0) {
1464
+ clearInterval(checkInterval);
1465
+ initialized = true;
1466
+ debugLog(`Initialized with ${hook.rendererInterfaces.size} renderer(s) (delayed)`);
1467
+ exposeGlobally();
1468
+ }
1469
+ }, 100);
1470
+ setTimeout(() => clearInterval(checkInterval), 10000);
1471
+ return false;
1472
+ }
1473
+ function exposeGlobally() {
1474
+ if (typeof window !== "undefined") {
1475
+ window.__HIGHLIGHT_UPDATES_CONTROLLER__ = {
1476
+ enable,
1477
+ disable,
1478
+ toggle,
1479
+ isEnabled,
1480
+ setEnabled,
1481
+ subscribe,
1482
+ initialize,
1483
+ destroy,
1484
+ isInitialized: () => initialized,
1485
+ setHighlightCallback
1486
+ };
1487
+ }
1488
+ }
1489
+ function enable() {
1490
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1491
+ if (!initialized) {
1492
+ initialize();
1493
+ }
1494
+
1495
+ // Enabling the VISUAL tool always means boxes should show — clear any
1496
+ // suppression left over from a silent (screenshot-tool) session.
1497
+ if (highlightsSuppressed) {
1498
+ highlightsSuppressed = false;
1499
+ }
1500
+ if (globalEnabled) {
1501
+ return;
1502
+ }
1503
+ debugLog("Enabling highlights");
1504
+
1505
+ // Only subscribe if not already subscribed via background tracking
1506
+ if (!backgroundTrackingEnabled) {
1507
+ subscribeToTraceUpdates();
1508
+ }
1509
+
1510
+ // Start tracking renders
1511
+ _RenderTracker.RenderTracker.start();
1512
+
1513
+ // Note: profiler logging disabled for normal operation
1514
+ // enableProfilerLogging();
1515
+
1516
+ globalEnabled = true;
1517
+ notifyStateListeners();
1518
+ (0, _sharedUi.notifySubscriberCountChange)('render');
1519
+ }
1520
+ function disable() {
1521
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1522
+ if (!globalEnabled) {
1523
+ return;
1524
+ }
1525
+ debugLog("Disabling highlights");
1526
+
1527
+ // Clear any pending locks/state
1528
+ renderingLock = false;
1529
+ isProcessing = false;
1530
+ if (renderingLockTimeout) {
1531
+ clearTimeout(renderingLockTimeout);
1532
+ renderingLockTimeout = null;
1533
+ }
1534
+ renderedOverlayTags.clear();
1535
+ devToolsNodeCache.clear(); // Clear detection cache
1536
+ (0, _RenderCauseDetector.clearRenderCauseState)(); // Clear render cause state to prevent memory leaks
1537
+
1538
+ // Only unsubscribe if background tracking doesn't need it
1539
+ if (!backgroundTrackingEnabled) {
1540
+ unsubscribeFromTraceUpdates();
1541
+ }
1542
+
1543
+ // Stop tracking renders
1544
+ _RenderTracker.RenderTracker.stop();
1545
+
1546
+ // Note: profiler logging disabled for normal operation
1547
+ // disableProfilerLogging();
1548
+
1549
+ globalEnabled = false;
1550
+ notifyStateListeners();
1551
+ (0, _sharedUi.notifySubscriberCountChange)('render');
1552
+ }
1553
+
1554
+ /**
1555
+ * Enable background render tracking (for Events tool).
1556
+ * This enables render interception WITHOUT affecting the visual toggle state.
1557
+ * The visual highlight toggle remains independent.
1558
+ */
1559
+ function enableBackgroundTracking() {
1560
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1561
+ if (backgroundTrackingEnabled) {
1562
+ return;
1563
+ }
1564
+ if (!initialized) {
1565
+ initialize();
1566
+ }
1567
+ debugLog("Enabling background tracking");
1568
+
1569
+ // Only subscribe if not already subscribed via main toggle
1570
+ if (!globalEnabled) {
1571
+ subscribeToTraceUpdates();
1572
+ }
1573
+ backgroundTrackingEnabled = true;
1574
+ }
1575
+
1576
+ /**
1577
+ * Disable background render tracking (for Events tool).
1578
+ * Only actually unsubscribes if the main toggle is also off.
1579
+ */
1580
+ function disableBackgroundTracking() {
1581
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1582
+ if (!backgroundTrackingEnabled) {
1583
+ return;
1584
+ }
1585
+ debugLog("Disabling background tracking");
1586
+ backgroundTrackingEnabled = false;
1587
+
1588
+ // Only unsubscribe if main toggle is also off
1589
+ if (!globalEnabled) {
1590
+ unsubscribeFromTraceUpdates();
1591
+ }
1592
+ }
1593
+
1594
+ /**
1595
+ * Check if background tracking is enabled (for debugging)
1596
+ */
1597
+ function isBackgroundTrackingEnabled() {
1598
+ return backgroundTrackingEnabled;
1599
+ }
1600
+ function toggle() {
1601
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1602
+ if (remoteHandler) {
1603
+ remoteHandler("toggle");
1604
+ return;
1605
+ }
1606
+ if (globalEnabled) {
1607
+ disable();
1608
+ } else {
1609
+ enable();
1610
+ }
1611
+ }
1612
+
1613
+ /**
1614
+ * Clear all render counts and tracked data
1615
+ */
1616
+ function clearRenderCounts() {
1617
+ if (remoteHandler) {
1618
+ remoteHandler("clearRenderCounts");
1619
+ return;
1620
+ }
1621
+ nodeRenderCounts.clear();
1622
+ _RenderTracker.RenderTracker.clear();
1623
+ debugLog("Cleared render counts");
1624
+ }
1625
+ function isEnabled() {
1626
+ return globalEnabled;
1627
+ }
1628
+ function setEnabled(enabled) {
1629
+ if (remoteHandler) {
1630
+ remoteHandler("setEnabled", {
1631
+ enabled
1632
+ });
1633
+ return;
1634
+ }
1635
+ if (enabled) enable();else disable();
1636
+ }
1637
+
1638
+ /**
1639
+ * Suppress (or restore) the visual highlight boxes without affecting tracking.
1640
+ * When suppressing, any boxes currently on screen are cleared immediately.
1641
+ */
1642
+ function setHighlightsSuppressed(suppressed) {
1643
+ if (highlightsSuppressed === suppressed) return;
1644
+ highlightsSuppressed = suppressed;
1645
+ if (suppressed && highlightCallback) {
1646
+ // Wipe whatever is currently drawn so nothing lingers.
1647
+ highlightCallback([]);
1648
+ }
1649
+ }
1650
+ function getHighlightsSuppressed() {
1651
+ return highlightsSuppressed;
1652
+ }
1653
+
1654
+ /**
1655
+ * Silent tracking — used by the desktop "screenshot this component" flow.
1656
+ * Turns the render tracker on (so the render list + measurements populate and
1657
+ * sync) while keeping the visual highlight boxes hidden. Disabling restores
1658
+ * normal state. On the desktop mirror this forwards to the device.
1659
+ */
1660
+ function setSilentTracking(enabled) {
1661
+ if (remoteHandler) {
1662
+ remoteHandler("setSilentTracking", {
1663
+ enabled
1664
+ });
1665
+ return;
1666
+ }
1667
+ if (enabled) {
1668
+ enable(); // clears suppression as part of a visual enable...
1669
+ setHighlightsSuppressed(true); // ...so re-suppress right after.
1670
+ } else {
1671
+ setHighlightsSuppressed(false);
1672
+ disable();
1673
+ }
1674
+ }
1675
+ function isInitialized() {
1676
+ return initialized;
1677
+ }
1678
+
1679
+ // ============================================================================
1680
+ // FREEZE FRAME MODE
1681
+ // ============================================================================
1682
+
1683
+ /**
1684
+ * Notify all freeze state listeners of a change
1685
+ */
1686
+ function notifyFreezeListeners() {
1687
+ freezeListeners.forEach(listener => {
1688
+ try {
1689
+ listener(isFrozen);
1690
+ } catch (error) {
1691
+ console.error("[HighlightUpdates] Error in freeze listener:", error);
1692
+ }
1693
+ });
1694
+ }
1695
+
1696
+ /**
1697
+ * Subscribe to freeze state changes
1698
+ */
1699
+ function subscribeToFreeze(listener) {
1700
+ freezeListeners.add(listener);
1701
+ listener(isFrozen);
1702
+ return () => {
1703
+ freezeListeners.delete(listener);
1704
+ };
1705
+ }
1706
+
1707
+ /**
1708
+ * Freeze highlights - prevents highlights from fading away.
1709
+ * New renders are still captured but old highlights don't clear.
1710
+ */
1711
+ function freeze() {
1712
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1713
+ if (isFrozen) return;
1714
+ isFrozen = true;
1715
+ debugLog("Freeze mode enabled");
1716
+ notifyFreezeListeners();
1717
+ }
1718
+
1719
+ /**
1720
+ * Unfreeze highlights - resumes normal cleanup behavior.
1721
+ * Clears all current highlights when unfreezing.
1722
+ */
1723
+ function unfreeze() {
1724
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return;
1725
+ if (!isFrozen) return;
1726
+ isFrozen = false;
1727
+ debugLog("Freeze mode disabled");
1728
+
1729
+ // Clear all current highlights when unfreezing
1730
+ if (highlightCallback) {
1731
+ highlightCallback([]);
1732
+ }
1733
+ notifyFreezeListeners();
1734
+ }
1735
+
1736
+ /**
1737
+ * Toggle freeze state
1738
+ */
1739
+ function toggleFreeze() {
1740
+ if (remoteHandler) {
1741
+ remoteHandler("toggleFreeze");
1742
+ return;
1743
+ }
1744
+ if (isFrozen) {
1745
+ unfreeze();
1746
+ } else {
1747
+ freeze();
1748
+ }
1749
+ }
1750
+
1751
+ /**
1752
+ * Check if freeze mode is active
1753
+ */
1754
+ function getFrozen() {
1755
+ return isFrozen;
1756
+ }
1757
+ function destroy() {
1758
+ if (!initialized) return;
1759
+ unsubscribeFromTraceUpdates();
1760
+
1761
+ // Uninstall profiler interceptor
1762
+ (0, _ProfilerInterceptor.uninstallProfilerInterceptor)();
1763
+ (0, _ProfilerInterceptor.setComparisonCallback)(null);
1764
+
1765
+ // Reset freeze state
1766
+ isFrozen = false;
1767
+ freezeListeners.clear();
1768
+ globalEnabled = false;
1769
+ hook = null;
1770
+ highlightCallback = null;
1771
+ initialized = false;
1772
+ if (typeof window !== "undefined") {
1773
+ delete window.__HIGHLIGHT_UPDATES_CONTROLLER__;
1774
+ }
1775
+ debugLog("Destroyed");
1776
+ }
1777
+ const HighlightUpdatesController = {
1778
+ subscribe,
1779
+ enable,
1780
+ disable,
1781
+ toggle,
1782
+ isEnabled,
1783
+ setEnabled,
1784
+ initialize,
1785
+ destroy,
1786
+ isInitialized,
1787
+ setHighlightCallback,
1788
+ clearRenderCounts,
1789
+ // Freeze frame mode
1790
+ freeze,
1791
+ unfreeze,
1792
+ toggleFreeze,
1793
+ getFrozen,
1794
+ subscribeToFreeze,
1795
+ // Badge press callback for "Click Overlay Badge → Jump to Detail"
1796
+ setBadgePressCallback,
1797
+ getBadgePressCallback,
1798
+ handleBadgePress,
1799
+ // Spotlight highlight for detail view
1800
+ setSpotlightCallback,
1801
+ setSpotlight,
1802
+ getSpotlight,
1803
+ // Cache management for excludeDevTools toggle
1804
+ clearDevToolsCache,
1805
+ // Background tracking for Events tool (separate from visual toggle)
1806
+ enableBackgroundTracking,
1807
+ disableBackgroundTracking,
1808
+ isBackgroundTrackingEnabled,
1809
+ // Remote mirror mode (desktop dashboard)
1810
+ setRemoteHandler,
1811
+ replaceRemoteState,
1812
+ // Component locator (desktop "screenshot this component" flow)
1813
+ locateComponent,
1814
+ // Silent tracking (track + measure without drawing boxes)
1815
+ setHighlightsSuppressed,
1816
+ getHighlightsSuppressed,
1817
+ setSilentTracking
1818
+ };
1819
+ var _default = exports.default = HighlightUpdatesController;