@buoy-gg/js-top 7.0.43 → 7.0.45
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.JsTopController=void 0;var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.JsTopController=void 0;var _types=require("../types");var _now=require("./now");var _state=require("./state");var _timers=require("./patches/timers");var _microtasks=require("./patches/microtasks");var _aggregator=require("./aggregator");var _originRegistry=require("./originRegistry");var _busyProbe=require("./busyProbe");var _preferences=require("../utils/preferences");var _sharedUi=require("@buoy-gg/shared-ui");const NOTIFY_INTERVAL_MS=_types.BUCKET_MS;class JsTopControllerImpl{enabled=false;enabledLoaded=false;paused=false;remoteSampling=false;engineRunning=false;tiers={timers:false,promises:false,bridge:false,longtask:false};notifyHandle=null;appStateSub=null;snapshot=this.buildSnapshot();subscribers=new Set;enabledSubscribers=new Set;tierInstallers=[];longtaskProvider=null;freezeStatsProvider=null;clearHooks=[];constructor(){void(0,_preferences.loadJsTopPrefs)().then(e=>{this.enabledLoaded=true;if(e.enabled&&!this.enabled)this.setEnabled(true)})}subscribe(e){this.subscribers.add(e);this.syncEngineState();e(this.snapshot);return()=>{this.subscribers.delete(e);this.syncEngineState()}}subscribeEnabled(e){this.enabledSubscribers.add(e);e(this.enabled);return()=>{this.enabledSubscribers.delete(e)}}setEnabled(e){if(this.enabled===e)return;this.enabled=e;if(this.enabledLoaded)void(0,_preferences.saveJsTopPrefs)({enabled:e});this.enabledSubscribers.forEach(t=>{try{t(e)}catch(i){if(__DEV__){console.error("[js-top] enabled subscriber threw",i)}}});this.syncEngineState()}isEnabled(){return this.enabled}setRemoteSampling(e){if(this.remoteSampling===e)return;this.remoteSampling=e;this.syncEngineState()}isRemoteSampling(){return this.remoteSampling}getStatus(){if(!this.engineRunning)return"disabled";return this.paused?"paused":"running"}pause(){if(this.paused)return;this.paused=true;(0,_state.setActive)(false);(0,_busyProbe.stopBusyProbe)();this.emitSnapshot()}resume(){if(!this.paused)return;this.paused=false;if(this.engineRunning){(0,_state.setActive)(true);(0,_busyProbe.startBusyProbe)()}this.emitSnapshot()}clear(){(0,_originRegistry.resetOrigins)();(0,_aggregator.resetAggregator)();for(const e of this.clearHooks){try{e()}catch{}}this.emitSnapshot()}registerClearHook(e){this.clearHooks.push(e)}getSnapshot(){return this.snapshot}getOriginDetail(e){const t=(0,_now.now)();const i=(0,_aggregator.windowBusyMs)(t);const a=this.freezeStatsProvider?.(Date.now());const s=a?.byOrigin[e];if(e==="unattributed"){const u=(0,_aggregator.windowResidualBuckets)(t);const r=Math.round(u.reduce((n,l)=>n+l,0)*10)/10;return{key:e,label:"unattributed (events / React / native call-ins)",api:"unattributed",promoted:false,scheduleCount:0,calls:0,totalMs:0,avgMs:0,maxMs:0,windowMs:r,pctOfBusy:i>0?Math.min(100,Math.round(r/i*1e3)/10):0,lastSeenAgoMs:0,buckets:u,freezes:s?.count??0,worstFreezeMs:Math.round(s?.maxMs??0)}}const o=(0,_originRegistry.getOriginDetailBase)(e,t,i);if(!o)return null;return{...o,freezes:s?.count??0,worstFreezeMs:Math.round(s?.maxMs??0)}}registerTierInstaller(e){this.tierInstallers.push(e);if(this.engineRunning){Object.assign(this.tiers,this.runInstaller(e))}}registerLongtaskProvider(e){this.longtaskProvider=e}registerFreezeStatsProvider(e){this.freezeStatsProvider=e}shouldRun(){return this.subscribers.size>0||this.remoteSampling}syncEngineState(){const e=this.shouldRun();if(e&&!this.engineRunning)this.startEngine();else if(!e&&this.engineRunning)this.stopEngine()}runInstaller(e){try{return e()}catch(t){if(__DEV__){console.error("[js-top] tier installer threw",t)}return{}}}startEngine(){this.engineRunning=true;(0,_timers.installTimerPatches)();(0,_microtasks.installMicrotaskPatches)();this.tiers={timers:true,promises:false,bridge:false,longtask:false};for(const e of this.tierInstallers){Object.assign(this.tiers,this.runInstaller(e))}(0,_state.setActive)(!this.paused);if(!this.paused)(0,_busyProbe.startBusyProbe)();try{this.appStateSub=(0,_sharedUi.subscribeRealAppState)(()=>{(0,_busyProbe.suppressNextGap)()})}catch{this.appStateSub=null}this.notifyHandle=(0,_state.getOriginals)().setInterval(()=>this.emitSnapshot(),NOTIFY_INTERVAL_MS);this.emitSnapshot()}stopEngine(){this.engineRunning=false;(0,_state.setActive)(false);(0,_busyProbe.stopBusyProbe)();if(this.notifyHandle!=null){(0,_state.getOriginals)().clearInterval(this.notifyHandle);this.notifyHandle=null}if(this.appStateSub){try{this.appStateSub.remove()}catch{}this.appStateSub=null}}buildSnapshot(){const e=(0,_now.now)();const t=(0,_aggregator.windowBusyMs)(e);const i=(0,_aggregator.windowAttributedMs)(e);const a=Math.max(0,t-i);const s=(0,_originRegistry.buildRows)(e,t,_types.SNAPSHOT_ROWS);if(a>=1){s.push({key:"unattributed",label:"unattributed (events / React / native call-ins)",api:"unattributed",windowMs:Math.round(a*10)/10,pctOfBusy:t>0?Math.min(100,Math.round(a/t*1e3)/10):0,totalMs:0,calls:0,avgMs:0,maxMs:0,lastSeenAgoMs:0,freezes:0,worstFreezeMs:0});s.sort((r,n)=>n.windowMs-r.windowMs||n.totalMs-r.totalMs)}const o=this.freezeStatsProvider?.(Date.now())??{count:0,worstMs:0,byOrigin:{}};for(const r of s){const n=o.byOrigin[r.key];if(n){r.freezes=n.count;r.worstFreezeMs=Math.round(n.maxMs)}}const u=_types.WINDOW_BUCKETS*_types.BUCKET_MS;return{ts:Date.now(),paused:this.paused,busyPct:Math.min(100,Math.round(t/u*1e3)/10),busyHistory:(0,_aggregator.busyHistory)(e),tiers:{...this.tiers},rows:s,totals:{attributedWindowMs:Math.round(i*10)/10,unattributedWindowMs:Math.round(a*10)/10,windowMs:u},freezeSummary:{count:o.count,worstMs:Math.round(o.worstMs)},longtasks:this.longtaskProvider?this.longtaskProvider():[]}}emitSnapshot(){this.snapshot=this.buildSnapshot();this.subscribers.forEach(e=>{try{e(this.snapshot)}catch(t){if(__DEV__){console.error("[js-top] snapshot subscriber threw",t)}}})}isEngineActive(){return(0,_state.isActive)()}}const JsTopController=exports.JsTopController=new JsTopControllerImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{BUCKET_MS as h,WINDOW_BUCKETS as m,SNAPSHOT_ROWS as S}from"../types";import{now as d}from"./now";import{setActive as u,isActive as M}from"./state";import{installTimerPatches as w}from"./patches/timers";import{installMicrotaskPatches as y}from"./patches/microtasks";import{busyHistory as v,resetAggregator as E,windowAttributedMs as R,windowBusyMs as c,windowResidualBuckets as z}from"./aggregator";import{buildRows as P,getOriginDetailBase as _,resetOrigins as k}from"./originRegistry";import{startBusyProbe as b,stopBusyProbe as p,suppressNextGap as O}from"./busyProbe";import{getOriginals as f}from"./state";import{loadJsTopPrefs as I,saveJsTopPrefs as H}from"../utils/preferences";import{subscribeRealAppState as T}from"@buoy-gg/shared-ui";const A=h;class B{enabled=false;enabledLoaded=false;paused=false;remoteSampling=false;engineRunning=false;tiers={timers:false,promises:false,bridge:false,longtask:false};notifyHandle=null;appStateSub=null;snapshot=this.buildSnapshot();subscribers=new Set;enabledSubscribers=new Set;tierInstallers=[];longtaskProvider=null;freezeStatsProvider=null;clearHooks=[];constructor(){void I().then(t=>{this.enabledLoaded=true;if(t.enabled&&!this.enabled)this.setEnabled(true)})}subscribe(t){this.subscribers.add(t);this.syncEngineState();t(this.snapshot);return()=>{this.subscribers.delete(t);this.syncEngineState()}}subscribeEnabled(t){this.enabledSubscribers.add(t);t(this.enabled);return()=>{this.enabledSubscribers.delete(t)}}setEnabled(t){if(this.enabled===t)return;this.enabled=t;if(this.enabledLoaded)void H({enabled:t});this.enabledSubscribers.forEach(e=>{try{e(t)}catch(i){if(__DEV__){console.error("[js-top] enabled subscriber threw",i)}}});this.syncEngineState()}isEnabled(){return this.enabled}setRemoteSampling(t){if(this.remoteSampling===t)return;this.remoteSampling=t;this.syncEngineState()}isRemoteSampling(){return this.remoteSampling}getStatus(){if(!this.engineRunning)return"disabled";return this.paused?"paused":"running"}pause(){if(this.paused)return;this.paused=true;u(false);p();this.emitSnapshot()}resume(){if(!this.paused)return;this.paused=false;if(this.engineRunning){u(true);b()}this.emitSnapshot()}clear(){k();E();for(const t of this.clearHooks){try{t()}catch{}}this.emitSnapshot()}registerClearHook(t){this.clearHooks.push(t)}getSnapshot(){return this.snapshot}getOriginDetail(t){const e=d();const i=c(e);const a=this.freezeStatsProvider?.(Date.now());const s=a?.byOrigin[t];if(t==="unattributed"){const l=z(e);const r=Math.round(l.reduce((n,g)=>n+g,0)*10)/10;return{key:t,label:"unattributed (events / React / native call-ins)",api:"unattributed",promoted:false,scheduleCount:0,calls:0,totalMs:0,avgMs:0,maxMs:0,windowMs:r,pctOfBusy:i>0?Math.min(100,Math.round(r/i*1e3)/10):0,lastSeenAgoMs:0,buckets:l,freezes:s?.count??0,worstFreezeMs:Math.round(s?.maxMs??0)}}const o=_(t,e,i);if(!o)return null;return{...o,freezes:s?.count??0,worstFreezeMs:Math.round(s?.maxMs??0)}}registerTierInstaller(t){this.tierInstallers.push(t);if(this.engineRunning){Object.assign(this.tiers,this.runInstaller(t))}}registerLongtaskProvider(t){this.longtaskProvider=t}registerFreezeStatsProvider(t){this.freezeStatsProvider=t}shouldRun(){return this.subscribers.size>0||this.remoteSampling}syncEngineState(){const t=this.shouldRun();if(t&&!this.engineRunning)this.startEngine();else if(!t&&this.engineRunning)this.stopEngine()}runInstaller(t){try{return t()}catch(e){if(__DEV__){console.error("[js-top] tier installer threw",e)}return{}}}startEngine(){this.engineRunning=true;w();y();this.tiers={timers:true,promises:false,bridge:false,longtask:false};for(const t of this.tierInstallers){Object.assign(this.tiers,this.runInstaller(t))}u(!this.paused);if(!this.paused)b();try{this.appStateSub=T(()=>{O()})}catch{this.appStateSub=null}this.notifyHandle=f().setInterval(()=>this.emitSnapshot(),A);this.emitSnapshot()}stopEngine(){this.engineRunning=false;u(false);p();if(this.notifyHandle!=null){f().clearInterval(this.notifyHandle);this.notifyHandle=null}if(this.appStateSub){try{this.appStateSub.remove()}catch{}this.appStateSub=null}}buildSnapshot(){const t=d();const e=c(t);const i=R(t);const a=Math.max(0,e-i);const s=P(t,e,S);if(a>=1){s.push({key:"unattributed",label:"unattributed (events / React / native call-ins)",api:"unattributed",windowMs:Math.round(a*10)/10,pctOfBusy:e>0?Math.min(100,Math.round(a/e*1e3)/10):0,totalMs:0,calls:0,avgMs:0,maxMs:0,lastSeenAgoMs:0,freezes:0,worstFreezeMs:0});s.sort((r,n)=>n.windowMs-r.windowMs||n.totalMs-r.totalMs)}const o=this.freezeStatsProvider?.(Date.now())??{count:0,worstMs:0,byOrigin:{}};for(const r of s){const n=o.byOrigin[r.key];if(n){r.freezes=n.count;r.worstFreezeMs=Math.round(n.maxMs)}}const l=m*h;return{ts:Date.now(),paused:this.paused,busyPct:Math.min(100,Math.round(e/l*1e3)/10),busyHistory:v(t),tiers:{...this.tiers},rows:s,totals:{attributedWindowMs:Math.round(i*10)/10,unattributedWindowMs:Math.round(a*10)/10,windowMs:l},freezeSummary:{count:o.count,worstMs:Math.round(o.worstMs)},longtasks:this.longtaskProvider?this.longtaskProvider():[]}}emitSnapshot(){this.snapshot=this.buildSnapshot();this.subscribers.forEach(t=>{try{t(this.snapshot)}catch(e){if(__DEV__){console.error("[js-top] snapshot subscriber threw",e)}}})}isEngineActive(){return M()}}export const JsTopController=new B;
|
package/lib/web/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";var Ve=Object.defineProperty;var
|
|
2
|
-
`);for(let o of n){let i=/at\s+(.*?)\s+\((?:address at\s+)?(.*?):(\d+):(\d+)\)/.exec(o)??/at\s+()(.*?):(\d+):(\d+)$/.exec(o.trim());if(!i)continue;let a=i[1]??"";if(a.includes("buoyJsTop")||a==="Error"||i[2]?.includes("/js-top/"))continue;t.push({file:i[2]??"",line:Number(i[3]),col:Number(i[4])});let s=/^(react_stack_bottom_frame|runWithFiberInDEV|commitHookEffectList|flushPassive|performWork|renderWithHooks|safelyCall)/.test(a)||/^(then|catch|finally|resolve|reject|fulfilled|rejected|step|tryCallOne|tryCallTwo|tryCatch|invokeCallback|notify)$/.test(a);if(!r&&a&&a!=="anonymous"&&!s&&(r=a),t.length>=3)break}return{caller:r,frames:t}}function Qr(e,t){return t-e.lastCaptureAt<Jr||(t-Ge>1e3&&(Ge=t,we=0),we>=Kr)?false:(we++,e.lastCaptureAt=t,true)}function ve(e){if(!e)return;let t=(e.split("?")[0]??e).replace(/\/\/&.*$/,""),r=/^[a-z]+:\/\/[^/]+\/(.*)$/.exec(t);return(r?r[1]:t).split("/").slice(-2).join("/")}function Gr(e){return k.has(e)}function ke(e,t,r,n=true){let o=t,i=typeof o.displayName=="string"&&o.displayName||typeof o.name=="string"&&o.name||"anonymous",a=`${e}|${i}`,s=k.get(a);if(s||(k.size>=500&&Ze(r),s=Se(a,e,i==="anonymous"?ee(e):`${ee(e)} ${i}`),k.set(a,s)),s.scheduleCount++,!s.promoted&&(s.scheduleCount>=25||s.totalMs>=50)&&(s.promoted=true),(s.promoted||e==="interval")&&n&&Qr(s,r)){let{caller:l,frames:u}=_r(new Error().stack??""),M=u[0];if(M||l){let F=M?`${ve(M.file)??"?"}:${M.line}`:"?",p=`${a}@${l??"?"}:${F}`,g=k.get(p);if(!g){k.size>=500&&Ze(r);let C=i==="anonymous"?ee(e):`${ee(e)} ${i}`;g=Se(p,e,l?`${C} \u2190 ${l}`:i==="anonymous"?`${C} @ ${ve(M?.file??"")??"?"}`:C),g.caller=l,g.file=M?ve(M.file):void 0,g.line=M?.line,g.frames=u,g.promoted=true,g.calls=s.calls,g.totalMs=s.totalMs,g.maxMs=s.maxMs,g.scheduleCount=s.scheduleCount,g.lastSeenAt=s.lastSeenAt,g.ring.set(s.ring),g.ringStamps.set(s.ringStamps),s.calls=0,s.totalMs=0,s.maxMs=0,s.ring.fill(0),s.ringStamps.fill(-1),k.set(p,g),qr(g,ee(e))}s.activeRefinedKey=p}}return s.activeRefinedKey??a}function ee(e){switch(e){case"timeout":return"setTimeout";case"interval":return"setInterval";case"immediate":return"setImmediate";case"raf":return"requestAnimationFrame";case"microtask":return"queueMicrotask";case"then":return"Promise.then";case"bridge":return"bridge";default:return e}}function Yr(e,t,r,n){let o=k.get(e);if(!o)return;o.calls++,o.totalMs+=t,t>o.maxMs&&(o.maxMs=t),o.lastSeenAt=n,!o.promoted&&o.totalMs>=50&&(o.promoted=true);let i=n-r,a=i>0?Math.min(1,t/i):1,s=Math.max(r,n-5e3),l=P(s),u=P(n),M=s;for(;l<=u;){let F=(l+1)*250,p=Math.min(n,F),g=p-M;if(g>0){let C=l%20;C>=0&&(o.ringStamps[C]!==l&&(o.ringStamps[C]=l,o.ring[C]=0),o.ring[C]+=i>0?g*a:t)}M=p,l++}Pr(r,n,t)}function Zr(e){return k.get(e)?.label??null}function Xr(e,t,r){let n=[];for(let a of k.values()){let s=Ye(a,e);s<=0&&a.totalMs<1||n.push({key:a.key,label:a.label,api:a.api,file:a.file,line:a.line,windowMs:Math.round(s*10)/10,pctOfBusy:t>0?Math.min(100,Math.round(s/t*1e3)/10):0,totalMs:Math.round(a.totalMs*10)/10,calls:a.calls,avgMs:a.calls>0?Math.round(a.totalMs/a.calls*100)/100:0,maxMs:Math.round(a.maxMs*100)/100,lastSeenAgoMs:a.lastSeenAt>0?Math.max(0,e-a.lastSeenAt):0,freezes:0,worstFreezeMs:0})}n.sort((a,s)=>s.windowMs-a.windowMs||s.totalMs-a.totalMs);let o=[],i=[];for(let a of n)(a.windowMs>=1||a.pctOfBusy>=.5||a.freezes>0?o:i).push(a);return i.length>=2?(o.push({key:"minor",label:`${i.length} minor origins (\u22641ms each)`,api:"other",windowMs:Math.round(i.reduce((a,s)=>a+s.windowMs,0)*10)/10,pctOfBusy:Math.round(i.reduce((a,s)=>a+s.pctOfBusy,0)*10)/10,totalMs:Math.round(i.reduce((a,s)=>a+s.totalMs,0)*10)/10,calls:i.reduce((a,s)=>a+s.calls,0),avgMs:0,maxMs:Math.max(0,...i.map(a=>a.maxMs)),lastSeenAgoMs:Math.min(...i.map(a=>a.lastSeenAgoMs)),freezes:0,worstFreezeMs:0}),o.slice(0,r)):n.slice(0,r)}function en(e,t,r){let n=k.get(e);if(!n)return null;let o=P(t),i=[],a=0;for(let s=o-20+1;s<=o;s++){let l=s%20,u=l>=0&&n.ringStamps[l]===s?Math.round(n.ring[l]*10)/10:0;i.push(u),a+=u}return{key:n.key,label:n.label,api:n.api,caller:n.caller,file:n.file,line:n.line,frames:n.frames,promoted:n.promoted,scheduleCount:n.scheduleCount,calls:n.calls,totalMs:Math.round(n.totalMs*10)/10,avgMs:n.calls>0?Math.round(n.totalMs/n.calls*100)/100:0,maxMs:Math.round(n.maxMs*100)/100,windowMs:Math.round(a*10)/10,pctOfBusy:r>0?Math.min(100,Math.round(a/r*1e3)/10):0,lastSeenAgoMs:n.lastSeenAt>0?Math.max(0,t-n.lastSeenAt):0,buckets:i}}function tn(){k.clear()}var rn=32,K=[],nn=20,Xe=64,et=new Array(Xe).fill(null),Te=0;function on(){return et}function tt(e,t){let r=I(),n=K.length>0?K[K.length-1]:null,o=null;K.length<rn&&(o={originKey:e,start:r,childrenMs:0},K.push(o));try{return t()}finally{try{if(o){K.pop();let i=I(),a=i-r,s=Math.max(0,a-o.childrenMs);n&&(n.childrenMs+=a),Yr(e,s,r,i),!n&&a>=nn&&(et[Te]={originKey:e,start:r,end:i},Te=(Te+1)%Xe)}}catch{}}}function U(e,t){if(typeof e!="function"||e[Ke])return e;let r=V()?ke(t,e,I()):null,n=function(...o){return V()?((r===null||!Gr(r))&&(r=ke(t,e,I(),false)),tt(r,()=>e.apply(this,o))):e.apply(this,o)};return n[Ke]=true,n}function rt(e,t,r){if(!V())return r();let n=ke(e,{name:t},I());return tt(n,r)}function nt(){let e=ge();if(typeof h.setTimeout=="function"&&!h.setTimeout[S]){let t=function(r,n,...o){let i=U(r,"timeout");return e.setTimeout(i,n,...o)};t[S]=true,h.setTimeout=t}if(typeof h.setInterval=="function"&&!h.setInterval[S]){let t=function(r,n,...o){let i=U(r,"interval");return e.setInterval(i,n,...o)};t[S]=true,h.setInterval=t}if(typeof h.setImmediate=="function"&&!h.setImmediate[S]&&e.setImmediate){let t=function(r,...n){let o=U(r,"immediate");return e.setImmediate(o,...n)};t[S]=true,h.setImmediate=t}if(typeof h.requestAnimationFrame=="function"&&!h.requestAnimationFrame[S]&&e.requestAnimationFrame){let t=function(r){let n=U(r,"raf");return e.requestAnimationFrame(n)};t[S]=true,h.requestAnimationFrame=t}}function ot(){let e=ge();if(typeof h.queueMicrotask=="function"&&!h.queueMicrotask[S]&&e.queueMicrotask){let t=function(r){let n=U(r,"microtask");return e.queueMicrotask(n)};t[S]=true,h.queueMicrotask=t}}var Ce=16,an=100,sn=3,ln=8,te=null,re=0,ce=false,ne=[],_=1/0,Q=0,ze=Ce;function cn(){let e=I(),t=re>0?e-re:0;if(re=e,ce){ce=false,_=1/0,Q=e;return}if(t<=0)return;t<an&&(t<_&&(_=t),Q===0&&(Q=e),e-Q>=1e3&&(ne.push(_),ne.length>sn&&ne.shift(),ze=Math.max(ln,Math.min(...ne)),_=1/0,Q=e));let r=t-ze;r>1&&Ir(e-r,e)}function it(){if(te!=null)return;let e=le();re=I(),ce=false,ne=[],_=1/0,Q=0,ze=Ce,te=e.setInterval(cn,Ce)}function at(){te!=null&&(le().clearInterval(te),te=null),re=0}function un(){ce=true}import{definePersistedSetting as dn}from"@buoy-gg/shared-ui/web";var hn="@react_buoy/js-top/prefs",fn={enabled:false},st=dn(hn,fn,{sanitize:e=>({enabled:e.enabled===true})});async function mn(){return st.load()}async function pn(e){await st.save(e)}var bn=250,gn=class{constructor(){this.enabled=false;this.enabledLoaded=false;this.paused=false;this.remoteSampling=false;this.engineRunning=false;this.tiers={timers:false,promises:false,bridge:false,longtask:false};this.notifyHandle=null;this.appStateSub=null;this.snapshot=this.buildSnapshot();this.subscribers=new Set;this.enabledSubscribers=new Set;this.tierInstallers=[];this.longtaskProvider=null;this.freezeStatsProvider=null;this.clearHooks=[];mn().then(e=>{this.enabledLoaded=true,e.enabled&&!this.enabled&&this.setEnabled(true)})}subscribe(e){return this.subscribers.add(e),this.syncEngineState(),e(this.snapshot),()=>{this.subscribers.delete(e),this.syncEngineState()}}subscribeEnabled(e){return this.enabledSubscribers.add(e),e(this.enabled),()=>{this.enabledSubscribers.delete(e)}}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.enabledLoaded&&pn({enabled:e}),this.enabledSubscribers.forEach(t=>{try{t(e)}catch(r){Y&&console.error("[js-top] enabled subscriber threw",r)}}),this.syncEngineState())}isEnabled(){return this.enabled}setRemoteSampling(e){this.remoteSampling!==e&&(this.remoteSampling=e,this.syncEngineState())}isRemoteSampling(){return this.remoteSampling}getStatus(){return this.engineRunning?this.paused?"paused":"running":"disabled"}pause(){this.paused||(this.paused=true,se(false),at(),this.emitSnapshot())}resume(){this.paused&&(this.paused=false,this.engineRunning&&(se(true),it()),this.emitSnapshot())}clear(){tn(),Hr();for(let e of this.clearHooks)try{e()}catch{}this.emitSnapshot()}registerClearHook(e){this.clearHooks.push(e)}getSnapshot(){return this.snapshot}getOriginDetail(e){let t=I(),r=_e(t),n=this.freezeStatsProvider?.(Date.now())?.byOrigin[e];if(e==="unattributed"){let i=Wr(t),a=Math.round(i.reduce((s,l)=>s+l,0)*10)/10;return{key:e,label:"unattributed (events / React / native call-ins)",api:"unattributed",promoted:false,scheduleCount:0,calls:0,totalMs:0,avgMs:0,maxMs:0,windowMs:a,pctOfBusy:r>0?Math.min(100,Math.round(a/r*1e3)/10):0,lastSeenAgoMs:0,buckets:i,freezes:n?.count??0,worstFreezeMs:Math.round(n?.maxMs??0)}}let o=en(e,t,r);return o?{...o,freezes:n?.count??0,worstFreezeMs:Math.round(n?.maxMs??0)}:null}registerTierInstaller(e){this.tierInstallers.push(e),this.engineRunning&&Object.assign(this.tiers,this.runInstaller(e))}registerLongtaskProvider(e){this.longtaskProvider=e}registerFreezeStatsProvider(e){this.freezeStatsProvider=e}shouldRun(){return this.subscribers.size>0||this.remoteSampling}syncEngineState(){let e=this.shouldRun();e&&!this.engineRunning?this.startEngine():!e&&this.engineRunning&&this.stopEngine()}runInstaller(e){try{return e()}catch(t){return Y&&console.error("[js-top] tier installer threw",t),{}}}startEngine(){this.engineRunning=true,nt(),ot(),this.tiers={timers:true,promises:false,bridge:false,longtask:false};for(let e of this.tierInstallers)Object.assign(this.tiers,this.runInstaller(e));se(!this.paused),this.paused||it();try{this.appStateSub=qe.addEventListener("change",()=>{un()})}catch{this.appStateSub=null}this.notifyHandle=le().setInterval(()=>this.emitSnapshot(),bn),this.emitSnapshot()}stopEngine(){if(this.engineRunning=false,se(false),at(),this.notifyHandle!=null&&(le().clearInterval(this.notifyHandle),this.notifyHandle=null),this.appStateSub){try{this.appStateSub.remove()}catch{}this.appStateSub=null}}buildSnapshot(){let e=I(),t=_e(e),r=Lr(e),n=Math.max(0,t-r),o=Xr(e,t,30);n>=1&&(o.push({key:"unattributed",label:"unattributed (events / React / native call-ins)",api:"unattributed",windowMs:Math.round(n*10)/10,pctOfBusy:t>0?Math.min(100,Math.round(n/t*1e3)/10):0,totalMs:0,calls:0,avgMs:0,maxMs:0,lastSeenAgoMs:0,freezes:0,worstFreezeMs:0}),o.sort((s,l)=>l.windowMs-s.windowMs||l.totalMs-s.totalMs));let i=this.freezeStatsProvider?.(Date.now())??{count:0,worstMs:0,byOrigin:{}};for(let s of o){let l=i.byOrigin[s.key];l&&(s.freezes=l.count,s.worstFreezeMs=Math.round(l.maxMs))}let a=5e3;return{ts:Date.now(),paused:this.paused,busyPct:Math.min(100,Math.round(t/a*1e3)/10),busyHistory:Dr(e),tiers:{...this.tiers},rows:o,totals:{attributedWindowMs:Math.round(r*10)/10,unattributedWindowMs:Math.round(n*10)/10,windowMs:a},freezeSummary:{count:i.count,worstMs:Math.round(i.worstMs)},longtasks:this.longtaskProvider?this.longtaskProvider():[]}}emitSnapshot(){this.snapshot=this.buildSnapshot(),this.subscribers.forEach(e=>{try{e(this.snapshot)}catch(t){Y&&console.error("[js-top] snapshot subscriber threw",t)}})}isEngineActive(){return V()}},d=new gn;function Ae(e,t){let r=e[t];if(typeof r!="function")return false;if(r[S])return true;let n=function(...o){for(let i=0;i<o.length;i++)typeof o[i]=="function"&&(o[i]=U(o[i],"then"));return r.apply(this,o)};return n[S]=true,Object.defineProperty(n,"name",{value:t,configurable:true}),e[t]=n,true}function yn(){let e=h.Promise?.prototype;if(!e)return{promises:false};let t=Ae(e,"then");return Ae(e,"catch"),Ae(e,"finally"),{promises:t}}function Mn(){let e=h.__fbBatchedBridge;if(!e)return{bridge:false};let t=false;if(typeof e.callFunctionReturnFlushedQueue=="function"&&!e.callFunctionReturnFlushedQueue[S]){let n=e.callFunctionReturnFlushedQueue.bind(e),o=function(i,a,s){return V()?rt("bridge",`${i}.${a}`,()=>n(i,a,s)):n(i,a,s)};o[S]=true,e.callFunctionReturnFlushedQueue=o,t=true}if(typeof e.invokeCallbackAndReturnFlushedQueue=="function"&&!e.invokeCallbackAndReturnFlushedQueue[S]){let n=e.invokeCallbackAndReturnFlushedQueue.bind(e),o=function(i,a){return V()?rt("bridge","nativeModuleCallback",()=>n(i,a)):n(i,a)};o[S]=true,e.invokeCallbackAndReturnFlushedQueue=o,t=true}let r=e.callFunctionReturnFlushedQueue?.[S]===true;return{bridge:t||r}}var xn=40,wn=6e4,Sn="unattributed",lt=false,ue=false,G=[];function vn(e,t){let r=e+t,n=null,o=0;for(let i of on()){if(!i)continue;let a=Math.min(r,i.end)-Math.max(e,i.start);a>o&&(o=a,n=i.originKey)}return n}function kn(){if(lt)return{longtask:ue};lt=true;let e=h.PerformanceObserver;if(typeof e!="function")return{longtask:false};try{new e(t=>{if(V())try{for(let r of t.getEntries()){if(r.entryType!=="longtask")continue;let n=r.startTime,o=r.duration;$r(n,n+o),G.push({start:n,duration:o,at:Date.now(),originKey:vn(n,o)}),G.length>xn&&G.shift()}}catch{}}).observe({entryTypes:["longtask"]}),ue=true}catch{ue=false}return{longtask:ue}}function Tn(){return G.map(e=>({start:e.start,duration:e.duration,at:e.at,originLabel:e.originKey?Zr(e.originKey):null}))}function Cn(e){let t={},r=0,n=0;for(let o of G){if(o.at>0&&e-o.at>wn)continue;r++,o.duration>n&&(n=o.duration);let i=o.originKey??Sn,a=t[i];a?(a.count++,o.duration>a.maxMs&&(a.maxMs=o.duration)):t[i]={count:1,maxMs:o.duration}}return{count:r,worstMs:n,byOrigin:t}}function zn(){G.length=0}var An={version:1,getSnapshot:()=>({live:d.getSnapshot(),enabled:d.isEnabled()||d.isRemoteSampling()}),subscribe:e=>{let t=d.subscribe(()=>e()),r=d.subscribeEnabled(()=>e());return()=>{t(),r()}},actions:{setEnabled:e=>{let t=e.enabled;d.setRemoteSampling(t)},pause:()=>d.pause(),resume:()=>d.resume(),clear:()=>d.clear(),getOriginDetail:e=>d.getOriginDetail(e.key),sample:async e=>{let t=e,r=Math.min(Math.max(t?.durationMs??3e3,250),3e4),n=d.isRemoteSampling()||d.isEnabled();n||d.setRemoteSampling(true),t?.clearFirst&&d.clear();try{return await new Promise(o=>setTimeout(o,r)),d.getSnapshot()}finally{n||d.setRemoteSampling(false)}}}};import{useCallback as Bn,useEffect as Rn,useMemo as En,useState as ct}from"react";import{Activity as Fn,JsModal as On,macOSColors as O,night as z,ModalHeader as oe,Pause as In,Play as Pn,Trash2 as $n}from"@buoy-gg/shared-ui/web";import{memo as Ln}from"react";import{macOSColors as Be}from"@buoy-gg/shared-ui/web";import{jsx as ut}from"react/jsx-runtime";var Wn=60;function Dn(e){return e>=80?Be.semantic.error:e>=40?Be.semantic.warning:Be.semantic.success}var Hn=Ln(function({history:e}){let t=e.slice(-Wn);return ut(f,{style:dt.row,pointerEvents:"none",children:t.map((r,n)=>ut(f,{style:[dt.bar,{height:Math.max(2,r/100*28),backgroundColor:Dn(r)}]},`b${n}`))})}),dt=D.create({row:{flexDirection:"row",alignItems:"flex-end",gap:1,height:28,alignSelf:"stretch"},bar:{flex:1,maxWidth:6,borderRadius:1,opacity:.9}});import{memo as Vn,useState as Nn}from"react";import{macOSColors as de,night as w}from"@buoy-gg/shared-ui/web";import{jsx as B,jsxs as $}from"react/jsx-runtime";var jn=[{key:"windowMs",title:"RECENT"},{key:"calls",title:"CALLS"},{key:"avgMs",title:"AVG"},{key:"maxMs",title:"MAX"},{key:"totalMs",title:"TOTAL"}],ht={timeout:{text:"TIMEOUT",color:"#38BDF8",prefix:"setTimeout"},interval:{text:"INTERVAL",color:"#22D3EE",prefix:"setInterval"},immediate:{text:"IMMED",color:"#60A5FA",prefix:"setImmediate"},raf:{text:"RAF",color:"#34D399",prefix:"requestAnimationFrame"},microtask:{text:"MICRO",color:"#A78BFA",prefix:"queueMicrotask"},then:{text:"PROMISE",color:"#BF5AF2",prefix:"Promise.then"},bridge:{text:"BRIDGE",color:"#FBBF24",prefix:"bridge"},unattributed:{text:"SYSTEM",color:"#8E8E93"},other:{text:"OTHER",color:"#8E8E93",prefix:"other"}};function Re(e){return ht[e]??ht.other}function ft(e){if(e.api==="unattributed")return"events \xB7 React \xB7 native call-ins";if(e.api==="other")return"evicted cold origins";let t=Re(e.api).prefix,r=e.label;return t&&r.startsWith(t)&&(r=r.slice(t.length)),r=r.replace(/^[\s←@]+/,"").trim(),r.length>0?r:"anonymous"}function ie(e){return e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e>=100?`${Math.round(e)}`:`${Math.round(e*10)/10}`}function qn(e){return e.calls<=0?"measured by probe \xB7 not reachable from JS":`${ie(e.calls)} calls \xB7 avg ${ie(e.avgMs)} \xB7 max ${ie(e.maxMs)} \xB7 total ${ie(e.totalMs)} ms`}var Jn=Vn(function({row:e,rank:t,onPress:r}){let n=Re(e.api);return $(r?Z:f,{style:T.row,...r?{onPress:()=>r(e),activeOpacity:.6}:{},children:[$(f,{style:T.topLine,children:[B(c,{style:T.rank,children:t}),B(f,{style:[T.badge,{borderColor:n.color,backgroundColor:`${n.color}1A`}],children:B(c,{style:[T.badgeText,{color:n.color}],children:n.text})}),B(c,{style:T.name,numberOfLines:1,children:ft(e)}),e.freezes>0&&$(c,{style:[T.freezeBadge,e.worstFreezeMs>=100&&T.freezeBadgeSevere],children:["\u26A0 \xD7",e.freezes]}),$(c,{style:[T.windowMs,e.api!=="unattributed"&&e.pctOfBusy>=25&&{color:e.pctOfBusy>=50?de.semantic.error:de.semantic.warning}],children:[ie(e.windowMs),B(c,{style:T.unit,children:" ms"})]}),$(c,{style:[T.pct,e.api==="unattributed"&&T.pctMuted],children:[Math.round(e.pctOfBusy),"%"]})]}),$(f,{style:T.subLine,children:[B(f,{style:T.barTrack,children:B(f,{style:[T.barFill,{width:`${Math.min(100,e.pctOfBusy)}%`,backgroundColor:n.color}]})}),B(c,{style:T.stats,numberOfLines:1,children:qn(e)})]})]})},(e,t)=>e.rank===t.rank&&e.onPress===t.onPress&&e.row.key===t.row.key&&e.row.windowMs===t.row.windowMs&&e.row.calls===t.row.calls&&e.row.maxMs===t.row.maxMs&&e.row.totalMs===t.row.totalMs&&e.row.pctOfBusy===t.row.pctOfBusy&&e.row.freezes===t.row.freezes&&e.row.worstFreezeMs===t.row.worstFreezeMs);function Kn({rows:e,onSelectRow:t}){let[r,n]=Nn("windowMs"),o=r==="windowMs"?e:[...e].sort((i,a)=>a[r]-i[r]);return $(f,{style:L.root,children:[$(f,{style:L.sortRow,children:[B(c,{style:L.sortLabel,children:"SORT"}),jn.map(i=>B(Z,{onPress:()=>n(i.key),style:[L.sortChip,r===i.key&&L.sortChipOn],children:B(c,{style:[L.sortChipText,r===i.key&&L.sortChipTextOn],children:i.title})},i.key))]}),$(pe,{style:L.body,children:[o.map((i,a)=>B(Jn,{row:i,rank:a+1,onPress:t},i.key)),o.length===0&&B(c,{style:L.empty,children:"No tasks observed yet \u2014 interact with the app."})]})]})}var L=D.create({root:{flex:1,minHeight:0},sortRow:{flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:10,paddingVertical:6,borderBottomWidth:1,borderBottomColor:w.color.border,backgroundColor:w.color.surface},sortLabel:{color:w.color.textTertiary,fontSize:9,fontWeight:"700",letterSpacing:.5,marginRight:2},sortChip:{borderWidth:1,borderColor:w.color.border,borderRadius:4,paddingHorizontal:7,paddingVertical:3},sortChipOn:{borderColor:w.color.accentBorderStrong,backgroundColor:w.color.accentSoft},sortChipText:{color:w.color.textTertiary,fontSize:9,fontWeight:"600",fontVariant:["tabular-nums"]},sortChipTextOn:{color:w.color.accent},body:{flex:1},empty:{color:w.color.textTertiary,fontSize:12,textAlign:"center",paddingVertical:24}}),T=D.create({row:{paddingHorizontal:10,paddingVertical:8,borderBottomWidth:D.hairlineWidth,borderBottomColor:w.color.border,gap:5},topLine:{flexDirection:"row",alignItems:"center",gap:6},rank:{width:16,color:w.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},badge:{borderWidth:1,borderRadius:3,paddingHorizontal:4,paddingVertical:1},badgeText:{fontSize:8,fontWeight:"700",letterSpacing:.4},name:{flex:1,color:w.color.text,fontSize:13,fontWeight:"500"},freezeBadge:{color:de.semantic.warning,fontSize:10,fontWeight:"700",fontVariant:["tabular-nums"]},freezeBadgeSevere:{color:de.semantic.error},windowMs:{color:w.color.text,fontSize:13,fontWeight:"700",fontVariant:["tabular-nums"]},unit:{color:w.color.textTertiary,fontSize:10,fontWeight:"400"},pct:{width:38,textAlign:"right",color:w.color.textSecondary,fontSize:12,fontWeight:"600",fontVariant:["tabular-nums"]},pctMuted:{color:w.color.textTertiary},subLine:{flexDirection:"row",alignItems:"center",gap:8,paddingLeft:22},barTrack:{width:72,height:4,borderRadius:2,backgroundColor:w.color.fillSecondary,overflow:"hidden"},barFill:{height:4,borderRadius:2,opacity:.85},stats:{flex:1,color:w.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]}});import{memo as Un}from"react";import{macOSColors as he,night as v,useSafeAreaInsets as _n}from"@buoy-gg/shared-ui/web";import{Fragment as mt,jsx as y,jsxs as R}from"react/jsx-runtime";var pt={timeout:"Work scheduled with setTimeout. Time shown is the callback's exclusive run time on the JS thread.",interval:"A repeating setInterval. One scheduling site, many runs \u2014 a hot interval is the classic silent JS-FPS killer.",immediate:"Work scheduled with setImmediate \u2014 runs at the end of the current event-loop turn.",raf:"requestAnimationFrame work \u2014 runs once per frame while scheduled. Cost here directly trades against 60fps.",microtask:"queueMicrotask work \u2014 runs after the current task, before the thread yields.",then:"Promise reaction (.then/.catch/.finally). Named by the function that attached the reaction. Note: async/await bodies bypass .then and land in the System row instead.",bridge:"A native\u2192JS call-in over the legacy bridge (events, module callbacks), measured as its un-nested remainder.",unattributed:"Thread time the probe measured but no JS wrapper could claim: touch handlers, React commits, native call-ins, and async/await bodies. High here on New Architecture is normal \u2014 it's where UI work lives.",other:"Origins evicted from the table when the registry hit its cap \u2014 their totals are preserved here."};function Qn(e){return pt[e]??pt.other}function N(e){return e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e>=100?`${Math.round(e)}`:`${Math.round(e*100)/100}`}function Gn(e){if(e<=0)return"\u2014";let t=e/1e3;return t<1?"just now":t<60?`${Math.round(t)}s ago`:`${Math.floor(t/60)}m ago`}function H({label:e,value:t,accent:r}){return R(f,{style:m.stat,children:[y(c,{style:m.statLabel,children:e}),y(c,{style:[m.statValue,r?{color:r}:null],children:t})]})}var Yn=Un(function({detail:e}){let t=Re(e.api),r=_n({minBottom:12}),n=Math.max(1,...e.buckets);return R(pe,{style:m.root,contentContainerStyle:{paddingBottom:r.bottom},children:[R(f,{style:m.identityRow,children:[y(f,{style:[m.badge,{borderColor:t.color,backgroundColor:`${t.color}1A`}],children:y(c,{style:[m.badgeText,{color:t.color}],children:t.text})}),y(c,{style:m.name,numberOfLines:2,children:ft(e)})]}),y(c,{style:m.explainer,children:Qn(e.api)}),y(c,{style:m.sectionTitle,children:"ACTIVITY \xB7 LAST 5S"}),y(f,{style:m.chartRow,children:e.buckets.map((o,i)=>y(f,{style:m.chartBarSlot,children:y(f,{style:[m.chartBar,{height:Math.max(2,o/n*44),backgroundColor:t.color}]})},`bk${i}`))}),R(f,{style:m.chartLegend,children:[R(c,{style:m.chartLegendText,children:[N(e.windowMs)," ms in window \xB7 ",e.pctOfBusy.toFixed(1),"% of busy time"]}),R(c,{style:m.chartLegendText,children:["peak ",N(n)," ms/250ms"]})]}),y(c,{style:m.sectionTitle,children:"STATS \xB7 SINCE START"}),R(f,{style:m.statGrid,children:[y(H,{label:"RUNS",value:e.calls>0?N(e.calls):"\u2014"}),y(H,{label:"SCHEDULED",value:e.scheduleCount>0?N(e.scheduleCount):"\u2014"}),y(H,{label:"AVG / RUN",value:e.calls>0?`${N(e.avgMs)} ms`:"\u2014"}),y(H,{label:"MAX / RUN",value:e.maxMs>0?`${N(e.maxMs)} ms`:"\u2014",accent:e.maxMs>=50?he.semantic.warning:void 0}),y(H,{label:"TOTAL",value:e.totalMs>0?`${N(e.totalMs)} ms`:"\u2014"}),y(H,{label:"LAST RUN",value:Gn(e.lastSeenAgoMs)}),y(H,{label:"FREEZES \xB7 60S",value:e.freezes>0?`${e.freezes}`:"0",accent:e.freezes>0?he.semantic.error:void 0}),y(H,{label:"WORST FREEZE",value:e.worstFreezeMs>0?`${e.worstFreezeMs} ms`:"\u2014",accent:e.worstFreezeMs>=100?he.semantic.error:e.worstFreezeMs>0?he.semantic.warning:void 0})]}),(e.caller||(e.frames?.length??0)>0)&&R(mt,{children:[y(c,{style:m.sectionTitle,children:"SCHEDULED FROM"}),R(f,{style:m.siteCard,children:[e.caller&&R(c,{style:m.siteCaller,children:[e.caller,"()"]}),e.file&&R(c,{style:m.siteFile,children:[e.file,e.line!=null?`:${e.line}`:""]}),e.frames?.map((o,i)=>R(c,{style:m.siteFrame,numberOfLines:1,children:[o.file,":",o.line,":",o.col]},`fr${i}`)),y(c,{style:m.siteNote,children:"Frames are bundle offsets (Hermes) \u2014 the caller name above is the readable part. Captured once when this origin got hot."})]})]}),!e.caller&&(e.frames?.length??0)===0&&e.api!=="unattributed"&&e.api!=="other"&&R(mt,{children:[y(c,{style:m.sectionTitle,children:"SCHEDULED FROM"}),y(c,{style:m.sitePending,children:e.promoted?"Stack capture pending \u2014 next schedule from this site will record it.":"Not hot enough yet \u2014 the scheduling stack is captured once an origin passes 25 schedules or 50ms total."})]})]})}),m=D.create({root:{flex:1,backgroundColor:"transparent",paddingHorizontal:12},identityRow:{flexDirection:"row",alignItems:"center",gap:8,paddingTop:12},badge:{borderWidth:1,borderRadius:3,paddingHorizontal:5,paddingVertical:2},badgeText:{fontSize:9,fontWeight:"700",letterSpacing:.4},name:{flex:1,color:v.color.text,fontSize:15,fontWeight:"600"},explainer:{color:v.color.textTertiary,fontSize:11,lineHeight:15,marginTop:6,marginBottom:4},sectionTitle:{color:v.color.textTertiary,fontSize:9,fontWeight:"700",letterSpacing:.5,marginTop:14,marginBottom:6},chartRow:{flexDirection:"row",alignItems:"flex-end",height:48,gap:2,backgroundColor:v.color.surface,borderRadius:6,borderWidth:1,borderColor:v.color.border,paddingHorizontal:6,paddingTop:2},chartBarSlot:{flex:1,alignItems:"center",justifyContent:"flex-end"},chartBar:{width:"70%",borderTopLeftRadius:2,borderTopRightRadius:2,opacity:.9},chartLegend:{flexDirection:"row",justifyContent:"space-between",marginTop:4},chartLegendText:{color:v.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},statGrid:{flexDirection:"row",flexWrap:"wrap",gap:8},stat:{width:"23%",minWidth:76,flexGrow:1,backgroundColor:v.color.surface,borderWidth:1,borderColor:v.color.border,borderRadius:6,paddingHorizontal:8,paddingVertical:6},statLabel:{color:v.color.textTertiary,fontSize:8,fontWeight:"700",letterSpacing:.4,marginBottom:3},statValue:{color:v.color.text,fontSize:13,fontWeight:"600",fontVariant:["tabular-nums"]},siteCard:{backgroundColor:v.color.surface,borderWidth:1,borderColor:v.color.border,borderRadius:6,padding:10,gap:3},siteCaller:{color:v.color.text,fontSize:13,fontWeight:"600"},siteFile:{color:v.color.info,fontSize:11},siteFrame:{color:v.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},siteNote:{color:v.color.textTertiary,fontSize:9,opacity:.8,marginTop:4},sitePending:{color:v.color.textTertiary,fontSize:11}});import{Fragment as Zn,jsx as b,jsxs as W}from"react/jsx-runtime";function bt(e){return e>=80?O.semantic.error:e>=40?O.semantic.warning:O.semantic.success}function Ee(e){return e>=100?O.semantic.error:O.semantic.warning}function Xn(e){let t=e.rows.find(r=>r.api!=="unattributed"&&r.api!=="other");return t&&t.pctOfBusy>=25&&e.busyPct>=15?{color:t.pctOfBusy>=50?O.semantic.error:O.semantic.warning,icon:"\u25B2",text:`${t.label} is eating ${Math.round(t.pctOfBusy)}% of thread time \u2014 start there.`}:e.freezeSummary.count>0?{color:Ee(e.freezeSummary.worstMs),icon:"\u25B2",text:`${e.freezeSummary.count} freeze${e.freezeSummary.count===1?"":"s"} in the last 60s (worst ${e.freezeSummary.worstMs}ms) \u2014 check rows marked \u26A0.`}:e.busyPct>=80?{color:O.semantic.warning,icon:"\u25B2",text:"Thread saturated by UI/React work \u2014 open Highlight Updates to find re-renders."}:{color:O.semantic.success,icon:"\u25CF",text:`Thread healthy at ${Math.round(e.busyPct)}% load \u2014 nothing worth chasing.`}}function gt({visible:e,onClose:t,onBack:r,onMinimize:n,initialModalState:o,minimizeTargetPosition:i,remoteSnapshot:a,remoteActions:s,embedded:l=false}){let u=a!==void 0,[M,F]=ct(null);Rn(()=>{if(!(u||!e))return d.subscribe(F)},[u,e]);let p=u?a:M,g=En(()=>s??{pause:()=>d.pause(),resume:()=>d.resume(),clear:()=>d.clear()},[s]),C=p?.paused??false,fe=(p?.rows.length??0)>0,[me,$e]=ct(null),kt=Bn(j=>$e(j.key),[]),Le=!u&&me?d.getOriginDetail(me):null,We=me!==null,De=W(oe,{children:[We?b(oe.Navigation,{onBack:()=>$e(null)}):r?b(oe.Navigation,{onBack:r}):null,b(oe.Content,{title:"",noMargin:true,children:W(f,{style:x.titleRow,children:[b(Fn,{size:14,color:"#34D399"}),b(c,{style:x.title,children:"JS Top"}),p&&b(f,{style:[x.busyPill,{borderColor:bt(p.busyPct)}],children:W(c,{style:[x.busyText,{color:bt(p.busyPct)}],children:[p.busyPct.toFixed(0),"% BUSY"]})}),p&&p.freezeSummary.count>0&&b(f,{style:[x.busyPill,{borderColor:Ee(p.freezeSummary.worstMs)}],children:W(c,{style:[x.busyText,{color:Ee(p.freezeSummary.worstMs)}],children:["\u26A0 ",p.freezeSummary.count," \xB7"," ",p.freezeSummary.worstMs,"ms"]})})]})}),W(oe.Actions,{children:[b(Z,{onPress:C?g.resume:g.pause,style:[x.actionBtn,C&&x.actionBtnActive],accessibilityLabel:C?"Resume sampling":"Pause sampling",children:C?b(Pn,{size:14,color:z.color.accent}):b(In,{size:14,color:z.color.textSecondary})}),b(Z,{onPress:g.clear,disabled:!fe,style:[x.actionBtn,!fe&&x.actionBtnDisabled],accessibilityLabel:"Clear stats",children:b($n,{size:14,color:fe?z.color.textTertiary:z.color.textTertiary})})]})]}),He=b(f,{style:x.body,children:We?Le?b(Yn,{detail:Le}):b(c,{style:x.waiting,children:"This origin is no longer tracked (cleared or evicted)."}):p?W(Zn,{children:[(()=>{let j=Xn(p);return W(f,{style:[x.diagnosis,{borderLeftColor:j.color}],children:[b(c,{style:[x.diagnosisIcon,{color:j.color}],children:j.icon}),b(c,{style:x.diagnosisText,children:j.text})]})})(),W(f,{style:x.sparklineRow,children:[b(c,{style:x.sparklineCaption,children:"JS THREAD LOAD \xB7 LAST 30s"}),b(Hn,{history:p.busyHistory})]}),!p.tiers.bridge&&b(c,{style:x.tierBanner,children:"\u201CSystem\u201D rows are UI/React/native work pure JS can\u2019t name \u2014 timers, rAF and Promise chains are fully attributed."}),b(Kn,{rows:p.rows,onSelectRow:u?void 0:kt})]}):b(c,{style:x.waiting,children:u?"Waiting for device\u2026":"Starting engine\u2026"})});return l?W(f,{style:x.embeddedRoot,children:[b(f,{style:x.embeddedHeader,children:De}),He]}):b(On,{visible:e,onClose:t,onMinimize:n,minimizeTargetPosition:i,initialModalState:o,header:{showToggleButton:true,customContent:De},persistenceKey:"buoy-js-top-modal",enablePersistence:true,initialMode:"bottomSheet",disableScrollWrapper:true,children:He})}var x=D.create({titleRow:{flexDirection:"row",alignItems:"center",gap:8},title:{color:z.color.text,fontSize:14,fontWeight:"500"},busyPill:{borderWidth:1,borderRadius:4,paddingHorizontal:6,paddingVertical:2},busyText:{fontSize:10,fontWeight:"700",fontVariant:["tabular-nums"]},actionBtn:{width:32,height:32,borderRadius:8,backgroundColor:z.color.buttonSurface,borderWidth:1,borderColor:z.color.border,alignItems:"center",justifyContent:"center"},actionBtnActive:{backgroundColor:z.color.accentSoft,borderColor:z.color.accentBorderStrong},actionBtnDisabled:{opacity:.55},body:{flex:1,minHeight:0,backgroundColor:"transparent"},diagnosis:{flexDirection:"row",alignItems:"center",gap:8,marginHorizontal:10,marginTop:8,paddingHorizontal:10,paddingVertical:8,backgroundColor:z.color.surface,borderRadius:6,borderLeftWidth:3},diagnosisIcon:{fontSize:11,fontWeight:"700"},diagnosisText:{flex:1,color:z.color.text,fontSize:12,lineHeight:16},sparklineRow:{paddingHorizontal:10,paddingVertical:8,gap:4},sparklineCaption:{color:z.color.textTertiary,fontSize:8,fontWeight:"700",letterSpacing:.5},tierBanner:{color:z.color.textTertiary,fontSize:10,paddingHorizontal:10,paddingBottom:6},waiting:{color:z.color.textTertiary,fontSize:12,textAlign:"center",paddingVertical:32},embeddedRoot:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:O.background.base},embeddedHeader:{borderBottomWidth:1,borderBottomColor:O.border.default}});import{useEffect as yt,useState as Mt}from"react";import{macOSColors as Fe,night as Oe}from"@buoy-gg/shared-ui/web";import{jsx as eo,jsxs as xt}from"react/jsx-runtime";function to(e){return e>=80?Fe.semantic.error:e>=40?Fe.semantic.warning:Fe.semantic.success}function ro(){let[e,t]=Mt(()=>d.isEnabled()),[r,n]=Mt(null);if(yt(()=>d.subscribeEnabled(t),[]),yt(()=>{if(!e){n(null);return}return d.subscribe(n)},[e]),!e||!r)return null;let o=r.rows.find(i=>i.api!=="unattributed");return xt(f,{style:Ie.pill,pointerEvents:"none",children:[xt(c,{style:[Ie.busy,{color:to(r.busyPct)}],children:[r.busyPct.toFixed(0),"%"]}),o&&eo(c,{style:Ie.label,numberOfLines:1,children:o.label})]})}var Ie=D.create({pill:{position:"absolute",top:60,left:8,flexDirection:"row",alignItems:"center",gap:6,backgroundColor:Oe.color.buttonSurface,borderWidth:1,borderColor:Oe.color.border,borderRadius:6,paddingHorizontal:8,paddingVertical:4,maxWidth:220},busy:{fontSize:11,fontWeight:"700",fontVariant:["tabular-nums"]},label:{color:Oe.color.textSecondary,fontSize:10,flexShrink:1}});import{useEffect as no,useState as oo}from"react";import{Activity as wt}from"@buoy-gg/shared-ui/web";import{jsx as St}from"react/jsx-runtime";var Pe="#34D399",vt="#6B7280";function io({size:e}){let[t,r]=oo(()=>d.isEnabled());return no(()=>d.subscribeEnabled(r),[]),St(wt,{size:e,color:t?Pe:vt})}function ao(){return null}var so={id:"js-top",name:"JS TOP",description:"Toggle the floating JS-thread busy pill",slot:"row",icon:io,component:ao,props:{},launchMode:"toggle-only",onPress:()=>{d.setEnabled(!d.isEnabled())}},lo={id:"js-top-modal",name:"TASKS",description:"Live Task Manager for the JS thread",slot:"both",icon:({size:e})=>St(wt,{size:e,color:Pe}),component:gt,props:{enableSharedModalDimensions:false}};d.registerTierInstaller(yn);d.registerTierInstaller(Mn);d.registerTierInstaller(kn);d.registerLongtaskProvider(Tn);d.registerFreezeStatsProvider(Cn);d.registerClearHook(zn);try{typeof window<"u"&&(nt(),ot())}catch{}export{vt as JS_TOP_DISABLED_COLOR,Pe as JS_TOP_ENABLED_COLOR,d as JsTopController,ro as JsTopHudOverlay,gt as JsTopModal,lo as jsTopModalPreset,so as jsTopPreset,An as jsTopSyncAdapter};
|
|
1
|
+
"use client";var Ve=Object.defineProperty;var kt=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var zt=(e,t)=>{for(var r in t)Ve(e,r,{get:t[r],enumerable:true})},Ne=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Tt(t))!Ct.call(e,o)&&o!==r&&Ve(e,o,{get:()=>t[o],enumerable:!(n=kt(t,o))||n.enumerable});return e},At=(e,t,r)=>(Ne(e,t,"default"),r&&Ne(r,t,"default"));var Y=process.env.NODE_ENV!=="production";typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);var ae=typeof globalThis<"u"?globalThis:void 0,Rt=(()=>{if(typeof ae?.nativePerformanceNow=="function"){let e=ae.nativePerformanceNow;return()=>e()}if(typeof ae?.performance?.now=="function"){let e=ae.performance;return()=>e.now()}return()=>Date.now()})(),Bt=Rt;function I(){return Bt()}var h=typeof globalThis<"u"?globalThis:{},je=false;function V(){return je}function se(e){je=e}var pe=null;function be(){return pe||(pe={setTimeout:h.setTimeout?.bind(h),setInterval:h.setInterval?.bind(h),clearInterval:h.clearInterval?.bind(h),clearTimeout:h.clearTimeout?.bind(h),setImmediate:h.setImmediate?.bind(h),requestAnimationFrame:h.requestAnimationFrame?.bind(h),queueMicrotask:h.queueMicrotask?.bind(h)}),pe}function le(){return be()}var S=Symbol.for("buoy.jsTop.patched"),qe=Symbol.for("buoy.jsTop.wrapped");var q=new Float64Array(120),Z=new Float64Array(120),ge=new Float64Array(120),J=new Float64Array(120).fill(-1);function P(e){return Math.floor(e/250)}function Et(e){let t=e%120;return J[t]!==e&&(J[t]=e,q[t]=0,Z[t]=0,ge[t]=0),t}function ye(e,t,r){if(!(t>e))return;let n=Math.max(e,t-3e4),o=P(n),i=P(t),a=n;for(;o<=i;){let s=(o+1)*250,l=Math.min(t,s),u=l-a;u>0&&r(Et(o),u),a=l,o++}}function Ft(e,t){ye(e,t,(r,n)=>{q[r]=Math.min(250,q[r]+n)})}function Ot(e,t,r){let n=t-e;if(!(n>0)||!(r>0))return;let o=Math.min(1,r/n);ye(e,t,(i,a)=>{Z[i]=Math.min(250,Z[i]+a*o)})}function It(e,t){ye(e,t,(r,n)=>{ge[r]=Math.min(250,ge[r]+n)})}function Je(e,t,r){let n=P(t),o=0;for(let i=n-r+1;i<=n;i++){let a=i%120;a>=0&&J[a]===i&&(o+=e[a])}return o}function Ke(e){return Je(q,e,20)}function Pt(e){return Je(Z,e,20)}function $t(e){let t=P(e),r=[];for(let n=t-20+1;n<=t;n++){let o=n%120;o>=0&&J[o]===n?r.push(Math.max(0,Math.round((q[o]-Z[o])*10)/10)):r.push(0)}return r}function Lt(e){let t=P(e),r=[];for(let o=t-120+1;o<=t;o++){let i=o%120;i>=0&&J[i]===o?r.push(Math.round(q[i]/250*100)):r.push(0)}let n=0;for(;n<r.length&&r[n]===0;)n++;return r.slice(Math.max(0,Math.min(n,r.length-1)))}function Wt(){J.fill(-1)}var Me=0;function Dt(){return typeof Y<"u"&&Y}function Ht(e){return(e.split("?")[0]??e).split("/").filter(Boolean).slice(-2).join("/")}function Vt(e){return/^[A-Z][A-Za-z0-9]*$/.test(e)}function Nt(e,t){if(!Dt()||e.symbolicated||!e.frames||e.frames.length===0||Me>=3)return;e.symbolicated=true;let r=e.frames[0];if(!r||!/^https?:\/\//.test(r.file))return;let n;try{n=`${new URL(r.file).origin}/symbolicate`}catch{return}Me++;let o=JSON.stringify({stack:e.frames.map(i=>({file:i.file,lineNumber:i.line,column:i.col,methodName:""}))});fetch(n,{method:"POST",body:o}).then(i=>i.ok?i.json():null).then(i=>{let a=i?.stack?.find(F=>F.file&&!F.file.includes("node_modules"))??i?.stack?.[0];if(!a?.file&&i?.error){let F=/found: (\/.+)$/.exec(i.error);F&&(a={file:F[1]})}if(!a?.file)return;let s=Ht(a.file),l=a.lineNumber,u=a.methodName&&a.methodName!=="<unknown>"?a.methodName:void 0;e.file=s,e.line=l??e.line;let M=`${s.split("/").pop()}${l!=null?`:${l}`:""}`;u&&Vt(u)&&!e.caller?(e.caller=u,e.label=`${e.label} \u2190 <${u}> \xB7 ${M}`):e.label=`${e.label} \xB7 ${M}`}).catch(()=>{}).finally(()=>{Me--})}var jt=500,qt=20,k=new Map,Ue="other",_e=0,xe=0;function we(e,t,r){return{key:e,api:t,label:r,calls:0,totalMs:0,maxMs:0,scheduleCount:0,lastSeenAt:0,promoted:false,lastCaptureAt:0,ring:new Float64Array(20),ringStamps:new Float64Array(20).fill(-1)}}function Qe(e,t){let r=P(t),n=0;for(let o=r-20+1;o<=r;o++){let i=o%20;i>=0&&e.ringStamps[i]===o&&(n+=e.ring[i])}return n}function Ge(e){let t=null,r=1/0;for(let o of k.values()){if(o.key===Ue)continue;let i=Qe(o,e)*1e6+o.lastSeenAt;i<r&&(r=i,t=o)}if(!t)return;let n=Jt(Ue,"other","other (evicted origins)");n.calls+=t.calls,n.totalMs+=t.totalMs,n.maxMs=Math.max(n.maxMs,t.maxMs),n.lastSeenAt=Math.max(n.lastSeenAt,t.lastSeenAt),k.delete(t.key)}function Jt(e,t,r){let n=k.get(e);return n||(n=we(e,t,r),k.set(e,n)),n}function Kt(e){let t=[],r,n=e.split(`
|
|
2
|
+
`);for(let o of n){let i=/at\s+(.*?)\s+\((?:address at\s+)?(.*?):(\d+):(\d+)\)/.exec(o)??/at\s+()(.*?):(\d+):(\d+)$/.exec(o.trim());if(!i)continue;let a=i[1]??"";if(a.includes("buoyJsTop")||a==="Error"||i[2]?.includes("/js-top/"))continue;t.push({file:i[2]??"",line:Number(i[3]),col:Number(i[4])});let s=/^(react_stack_bottom_frame|runWithFiberInDEV|commitHookEffectList|flushPassive|performWork|renderWithHooks|safelyCall)/.test(a)||/^(then|catch|finally|resolve|reject|fulfilled|rejected|step|tryCallOne|tryCallTwo|tryCatch|invokeCallback|notify)$/.test(a);if(!r&&a&&a!=="anonymous"&&!s&&(r=a),t.length>=3)break}return{caller:r,frames:t}}function Ut(e,t){return t-e.lastCaptureAt<jt||(t-_e>1e3&&(_e=t,xe=0),xe>=qt)?false:(xe++,e.lastCaptureAt=t,true)}function Se(e){if(!e)return;let t=(e.split("?")[0]??e).replace(/\/\/&.*$/,""),r=/^[a-z]+:\/\/[^/]+\/(.*)$/.exec(t);return(r?r[1]:t).split("/").slice(-2).join("/")}function _t(e){return k.has(e)}function ve(e,t,r,n=true){let o=t,i=typeof o.displayName=="string"&&o.displayName||typeof o.name=="string"&&o.name||"anonymous",a=`${e}|${i}`,s=k.get(a);if(s||(k.size>=500&&Ge(r),s=we(a,e,i==="anonymous"?X(e):`${X(e)} ${i}`),k.set(a,s)),s.scheduleCount++,!s.promoted&&(s.scheduleCount>=25||s.totalMs>=50)&&(s.promoted=true),(s.promoted||e==="interval")&&n&&Ut(s,r)){let{caller:l,frames:u}=Kt(new Error().stack??""),M=u[0];if(M||l){let F=M?`${Se(M.file)??"?"}:${M.line}`:"?",p=`${a}@${l??"?"}:${F}`,g=k.get(p);if(!g){k.size>=500&&Ge(r);let C=i==="anonymous"?X(e):`${X(e)} ${i}`;g=we(p,e,l?`${C} \u2190 ${l}`:i==="anonymous"?`${C} @ ${Se(M?.file??"")??"?"}`:C),g.caller=l,g.file=M?Se(M.file):void 0,g.line=M?.line,g.frames=u,g.promoted=true,g.calls=s.calls,g.totalMs=s.totalMs,g.maxMs=s.maxMs,g.scheduleCount=s.scheduleCount,g.lastSeenAt=s.lastSeenAt,g.ring.set(s.ring),g.ringStamps.set(s.ringStamps),s.calls=0,s.totalMs=0,s.maxMs=0,s.ring.fill(0),s.ringStamps.fill(-1),k.set(p,g),Nt(g,X(e))}s.activeRefinedKey=p}}return s.activeRefinedKey??a}function X(e){switch(e){case"timeout":return"setTimeout";case"interval":return"setInterval";case"immediate":return"setImmediate";case"raf":return"requestAnimationFrame";case"microtask":return"queueMicrotask";case"then":return"Promise.then";case"bridge":return"bridge";default:return e}}function Qt(e,t,r,n){let o=k.get(e);if(!o)return;o.calls++,o.totalMs+=t,t>o.maxMs&&(o.maxMs=t),o.lastSeenAt=n,!o.promoted&&o.totalMs>=50&&(o.promoted=true);let i=n-r,a=i>0?Math.min(1,t/i):1,s=Math.max(r,n-5e3),l=P(s),u=P(n),M=s;for(;l<=u;){let F=(l+1)*250,p=Math.min(n,F),g=p-M;if(g>0){let C=l%20;C>=0&&(o.ringStamps[C]!==l&&(o.ringStamps[C]=l,o.ring[C]=0),o.ring[C]+=i>0?g*a:t)}M=p,l++}Ot(r,n,t)}function Gt(e){return k.get(e)?.label??null}function Yt(e,t,r){let n=[];for(let a of k.values()){let s=Qe(a,e);s<=0&&a.totalMs<1||n.push({key:a.key,label:a.label,api:a.api,file:a.file,line:a.line,windowMs:Math.round(s*10)/10,pctOfBusy:t>0?Math.min(100,Math.round(s/t*1e3)/10):0,totalMs:Math.round(a.totalMs*10)/10,calls:a.calls,avgMs:a.calls>0?Math.round(a.totalMs/a.calls*100)/100:0,maxMs:Math.round(a.maxMs*100)/100,lastSeenAgoMs:a.lastSeenAt>0?Math.max(0,e-a.lastSeenAt):0,freezes:0,worstFreezeMs:0})}n.sort((a,s)=>s.windowMs-a.windowMs||s.totalMs-a.totalMs);let o=[],i=[];for(let a of n)(a.windowMs>=1||a.pctOfBusy>=.5||a.freezes>0?o:i).push(a);return i.length>=2?(o.push({key:"minor",label:`${i.length} minor origins (\u22641ms each)`,api:"other",windowMs:Math.round(i.reduce((a,s)=>a+s.windowMs,0)*10)/10,pctOfBusy:Math.round(i.reduce((a,s)=>a+s.pctOfBusy,0)*10)/10,totalMs:Math.round(i.reduce((a,s)=>a+s.totalMs,0)*10)/10,calls:i.reduce((a,s)=>a+s.calls,0),avgMs:0,maxMs:Math.max(0,...i.map(a=>a.maxMs)),lastSeenAgoMs:Math.min(...i.map(a=>a.lastSeenAgoMs)),freezes:0,worstFreezeMs:0}),o.slice(0,r)):n.slice(0,r)}function Zt(e,t,r){let n=k.get(e);if(!n)return null;let o=P(t),i=[],a=0;for(let s=o-20+1;s<=o;s++){let l=s%20,u=l>=0&&n.ringStamps[l]===s?Math.round(n.ring[l]*10)/10:0;i.push(u),a+=u}return{key:n.key,label:n.label,api:n.api,caller:n.caller,file:n.file,line:n.line,frames:n.frames,promoted:n.promoted,scheduleCount:n.scheduleCount,calls:n.calls,totalMs:Math.round(n.totalMs*10)/10,avgMs:n.calls>0?Math.round(n.totalMs/n.calls*100)/100:0,maxMs:Math.round(n.maxMs*100)/100,windowMs:Math.round(a*10)/10,pctOfBusy:r>0?Math.min(100,Math.round(a/r*1e3)/10):0,lastSeenAgoMs:n.lastSeenAt>0?Math.max(0,t-n.lastSeenAt):0,buckets:i}}function Xt(){k.clear()}var er=32,K=[],tr=20,Ye=64,Ze=new Array(Ye).fill(null),ke=0;function rr(){return Ze}function Xe(e,t){let r=I(),n=K.length>0?K[K.length-1]:null,o=null;K.length<er&&(o={originKey:e,start:r,childrenMs:0},K.push(o));try{return t()}finally{try{if(o){K.pop();let i=I(),a=i-r,s=Math.max(0,a-o.childrenMs);n&&(n.childrenMs+=a),Qt(e,s,r,i),!n&&a>=tr&&(Ze[ke]={originKey:e,start:r,end:i},ke=(ke+1)%Ye)}}catch{}}}function U(e,t){if(typeof e!="function"||e[qe])return e;let r=V()?ve(t,e,I()):null,n=function(...o){return V()?((r===null||!_t(r))&&(r=ve(t,e,I(),false)),Xe(r,()=>e.apply(this,o))):e.apply(this,o)};return n[qe]=true,n}function et(e,t,r){if(!V())return r();let n=ve(e,{name:t},I());return Xe(n,r)}function tt(){let e=be();if(typeof h.setTimeout=="function"&&!h.setTimeout[S]){let t=function(r,n,...o){let i=U(r,"timeout");return e.setTimeout(i,n,...o)};t[S]=true,h.setTimeout=t}if(typeof h.setInterval=="function"&&!h.setInterval[S]){let t=function(r,n,...o){let i=U(r,"interval");return e.setInterval(i,n,...o)};t[S]=true,h.setInterval=t}if(typeof h.setImmediate=="function"&&!h.setImmediate[S]&&e.setImmediate){let t=function(r,...n){let o=U(r,"immediate");return e.setImmediate(o,...n)};t[S]=true,h.setImmediate=t}if(typeof h.requestAnimationFrame=="function"&&!h.requestAnimationFrame[S]&&e.requestAnimationFrame){let t=function(r){let n=U(r,"raf");return e.requestAnimationFrame(n)};t[S]=true,h.requestAnimationFrame=t}}function rt(){let e=be();if(typeof h.queueMicrotask=="function"&&!h.queueMicrotask[S]&&e.queueMicrotask){let t=function(r){let n=U(r,"microtask");return e.queueMicrotask(n)};t[S]=true,h.queueMicrotask=t}}var Te=16,nr=100,or=3,ir=8,ee=null,te=0,ce=false,re=[],_=1/0,Q=0,Ce=Te;function ar(){let e=I(),t=te>0?e-te:0;if(te=e,ce){ce=false,_=1/0,Q=e;return}if(t<=0)return;t<nr&&(t<_&&(_=t),Q===0&&(Q=e),e-Q>=1e3&&(re.push(_),re.length>or&&re.shift(),Ce=Math.max(ir,Math.min(...re)),_=1/0,Q=e));let r=t-Ce;r>1&&Ft(e-r,e)}function nt(){if(ee!=null)return;let e=le();te=I(),ce=false,re=[],_=1/0,Q=0,Ce=Te,ee=e.setInterval(ar,Te)}function ot(){ee!=null&&(le().clearInterval(ee),ee=null),te=0}function sr(){ce=true}import{definePersistedSetting as lr}from"@buoy-gg/shared-ui/web";var cr="@react_buoy/js-top/prefs",ur={enabled:false},it=lr(cr,ur,{sanitize:e=>({enabled:e.enabled===true})});async function dr(){return it.load()}async function hr(e){await it.save(e)}import{subscribeRealAppState as fr}from"@buoy-gg/shared-ui/web";var mr=250,pr=class{constructor(){this.enabled=false;this.enabledLoaded=false;this.paused=false;this.remoteSampling=false;this.engineRunning=false;this.tiers={timers:false,promises:false,bridge:false,longtask:false};this.notifyHandle=null;this.appStateSub=null;this.snapshot=this.buildSnapshot();this.subscribers=new Set;this.enabledSubscribers=new Set;this.tierInstallers=[];this.longtaskProvider=null;this.freezeStatsProvider=null;this.clearHooks=[];dr().then(e=>{this.enabledLoaded=true,e.enabled&&!this.enabled&&this.setEnabled(true)})}subscribe(e){return this.subscribers.add(e),this.syncEngineState(),e(this.snapshot),()=>{this.subscribers.delete(e),this.syncEngineState()}}subscribeEnabled(e){return this.enabledSubscribers.add(e),e(this.enabled),()=>{this.enabledSubscribers.delete(e)}}setEnabled(e){this.enabled!==e&&(this.enabled=e,this.enabledLoaded&&hr({enabled:e}),this.enabledSubscribers.forEach(t=>{try{t(e)}catch(r){Y&&console.error("[js-top] enabled subscriber threw",r)}}),this.syncEngineState())}isEnabled(){return this.enabled}setRemoteSampling(e){this.remoteSampling!==e&&(this.remoteSampling=e,this.syncEngineState())}isRemoteSampling(){return this.remoteSampling}getStatus(){return this.engineRunning?this.paused?"paused":"running":"disabled"}pause(){this.paused||(this.paused=true,se(false),ot(),this.emitSnapshot())}resume(){this.paused&&(this.paused=false,this.engineRunning&&(se(true),nt()),this.emitSnapshot())}clear(){Xt(),Wt();for(let e of this.clearHooks)try{e()}catch{}this.emitSnapshot()}registerClearHook(e){this.clearHooks.push(e)}getSnapshot(){return this.snapshot}getOriginDetail(e){let t=I(),r=Ke(t),n=this.freezeStatsProvider?.(Date.now())?.byOrigin[e];if(e==="unattributed"){let i=$t(t),a=Math.round(i.reduce((s,l)=>s+l,0)*10)/10;return{key:e,label:"unattributed (events / React / native call-ins)",api:"unattributed",promoted:false,scheduleCount:0,calls:0,totalMs:0,avgMs:0,maxMs:0,windowMs:a,pctOfBusy:r>0?Math.min(100,Math.round(a/r*1e3)/10):0,lastSeenAgoMs:0,buckets:i,freezes:n?.count??0,worstFreezeMs:Math.round(n?.maxMs??0)}}let o=Zt(e,t,r);return o?{...o,freezes:n?.count??0,worstFreezeMs:Math.round(n?.maxMs??0)}:null}registerTierInstaller(e){this.tierInstallers.push(e),this.engineRunning&&Object.assign(this.tiers,this.runInstaller(e))}registerLongtaskProvider(e){this.longtaskProvider=e}registerFreezeStatsProvider(e){this.freezeStatsProvider=e}shouldRun(){return this.subscribers.size>0||this.remoteSampling}syncEngineState(){let e=this.shouldRun();e&&!this.engineRunning?this.startEngine():!e&&this.engineRunning&&this.stopEngine()}runInstaller(e){try{return e()}catch(t){return Y&&console.error("[js-top] tier installer threw",t),{}}}startEngine(){this.engineRunning=true,tt(),rt(),this.tiers={timers:true,promises:false,bridge:false,longtask:false};for(let e of this.tierInstallers)Object.assign(this.tiers,this.runInstaller(e));se(!this.paused),this.paused||nt();try{this.appStateSub=fr(()=>{sr()})}catch{this.appStateSub=null}this.notifyHandle=le().setInterval(()=>this.emitSnapshot(),mr),this.emitSnapshot()}stopEngine(){if(this.engineRunning=false,se(false),ot(),this.notifyHandle!=null&&(le().clearInterval(this.notifyHandle),this.notifyHandle=null),this.appStateSub){try{this.appStateSub.remove()}catch{}this.appStateSub=null}}buildSnapshot(){let e=I(),t=Ke(e),r=Pt(e),n=Math.max(0,t-r),o=Yt(e,t,30);n>=1&&(o.push({key:"unattributed",label:"unattributed (events / React / native call-ins)",api:"unattributed",windowMs:Math.round(n*10)/10,pctOfBusy:t>0?Math.min(100,Math.round(n/t*1e3)/10):0,totalMs:0,calls:0,avgMs:0,maxMs:0,lastSeenAgoMs:0,freezes:0,worstFreezeMs:0}),o.sort((s,l)=>l.windowMs-s.windowMs||l.totalMs-s.totalMs));let i=this.freezeStatsProvider?.(Date.now())??{count:0,worstMs:0,byOrigin:{}};for(let s of o){let l=i.byOrigin[s.key];l&&(s.freezes=l.count,s.worstFreezeMs=Math.round(l.maxMs))}let a=5e3;return{ts:Date.now(),paused:this.paused,busyPct:Math.min(100,Math.round(t/a*1e3)/10),busyHistory:Lt(e),tiers:{...this.tiers},rows:o,totals:{attributedWindowMs:Math.round(r*10)/10,unattributedWindowMs:Math.round(n*10)/10,windowMs:a},freezeSummary:{count:i.count,worstMs:Math.round(i.worstMs)},longtasks:this.longtaskProvider?this.longtaskProvider():[]}}emitSnapshot(){this.snapshot=this.buildSnapshot(),this.subscribers.forEach(e=>{try{e(this.snapshot)}catch(t){Y&&console.error("[js-top] snapshot subscriber threw",t)}})}isEngineActive(){return V()}},d=new pr;function ze(e,t){let r=e[t];if(typeof r!="function")return false;if(r[S])return true;let n=function(...o){for(let i=0;i<o.length;i++)typeof o[i]=="function"&&(o[i]=U(o[i],"then"));return r.apply(this,o)};return n[S]=true,Object.defineProperty(n,"name",{value:t,configurable:true}),e[t]=n,true}function br(){let e=h.Promise?.prototype;if(!e)return{promises:false};let t=ze(e,"then");return ze(e,"catch"),ze(e,"finally"),{promises:t}}function gr(){let e=h.__fbBatchedBridge;if(!e)return{bridge:false};let t=false;if(typeof e.callFunctionReturnFlushedQueue=="function"&&!e.callFunctionReturnFlushedQueue[S]){let n=e.callFunctionReturnFlushedQueue.bind(e),o=function(i,a,s){return V()?et("bridge",`${i}.${a}`,()=>n(i,a,s)):n(i,a,s)};o[S]=true,e.callFunctionReturnFlushedQueue=o,t=true}if(typeof e.invokeCallbackAndReturnFlushedQueue=="function"&&!e.invokeCallbackAndReturnFlushedQueue[S]){let n=e.invokeCallbackAndReturnFlushedQueue.bind(e),o=function(i,a){return V()?et("bridge","nativeModuleCallback",()=>n(i,a)):n(i,a)};o[S]=true,e.invokeCallbackAndReturnFlushedQueue=o,t=true}let r=e.callFunctionReturnFlushedQueue?.[S]===true;return{bridge:t||r}}var yr=40,Mr=6e4,xr="unattributed",at=false,ue=false,G=[];function wr(e,t){let r=e+t,n=null,o=0;for(let i of rr()){if(!i)continue;let a=Math.min(r,i.end)-Math.max(e,i.start);a>o&&(o=a,n=i.originKey)}return n}function Sr(){if(at)return{longtask:ue};at=true;let e=h.PerformanceObserver;if(typeof e!="function")return{longtask:false};try{new e(t=>{if(V())try{for(let r of t.getEntries()){if(r.entryType!=="longtask")continue;let n=r.startTime,o=r.duration;It(n,n+o),G.push({start:n,duration:o,at:Date.now(),originKey:wr(n,o)}),G.length>yr&&G.shift()}}catch{}}).observe({entryTypes:["longtask"]}),ue=true}catch{ue=false}return{longtask:ue}}function vr(){return G.map(e=>({start:e.start,duration:e.duration,at:e.at,originLabel:e.originKey?Gt(e.originKey):null}))}function kr(e){let t={},r=0,n=0;for(let o of G){if(o.at>0&&e-o.at>Mr)continue;r++,o.duration>n&&(n=o.duration);let i=o.originKey??xr,a=t[i];a?(a.count++,o.duration>a.maxMs&&(a.maxMs=o.duration)):t[i]={count:1,maxMs:o.duration}}return{count:r,worstMs:n,byOrigin:t}}function Tr(){G.length=0}var Cr={version:1,getSnapshot:()=>({live:d.getSnapshot(),enabled:d.isEnabled()||d.isRemoteSampling()}),subscribe:e=>{let t=d.subscribe(()=>e()),r=d.subscribeEnabled(()=>e());return()=>{t(),r()}},actions:{setEnabled:e=>{let t=e.enabled;d.setRemoteSampling(t)},pause:()=>d.pause(),resume:()=>d.resume(),clear:()=>d.clear(),getOriginDetail:e=>d.getOriginDetail(e.key),sample:async e=>{let t=e,r=Math.min(Math.max(t?.durationMs??3e3,250),3e4),n=d.isRemoteSampling()||d.isEnabled();n||d.setRemoteSampling(true),t?.clearFirst&&d.clear();try{return await new Promise(o=>setTimeout(o,r)),d.getSnapshot()}finally{n||d.setRemoteSampling(false)}}}};import{useCallback as zr,useEffect as Ar,useMemo as Rr,useState as st}from"react";var lt={};zt(lt,{AccessibilityInfo:()=>Or,ActivityIndicator:()=>Rn,Alert:()=>Fn,Animated:()=>Ir,AppRegistry:()=>$r,AppState:()=>Lr,Appearance:()=>Pr,BackHandler:()=>Wr,Button:()=>Bn,CheckBox:()=>en,Clipboard:()=>Dr,DeviceEventEmitter:()=>gn,Dimensions:()=>Hr,Easing:()=>Vr,FlatList:()=>tn,I18nManager:()=>Nr,Image:()=>rn,ImageBackground:()=>nn,InteractionManager:()=>qr,Keyboard:()=>jr,KeyboardAvoidingView:()=>on,LayoutAnimation:()=>Jr,Linking:()=>Kr,LogBox:()=>bn,Modal:()=>zn,NativeEventEmitter:()=>Ur,NativeModules:()=>Fr,PanResponder:()=>_r,Picker:()=>an,PixelRatio:()=>Qr,Platform:()=>Gr,Pressable:()=>Cn,ProgressBar:()=>sn,RefreshControl:()=>ln,SafeAreaView:()=>cn,ScrollView:()=>Ae,SectionList:()=>un,Share:()=>Yr,StatusBar:()=>dn,StyleSheet:()=>D,Switch:()=>An,Text:()=>c,TextInput:()=>vn,Touchable:()=>hn,TouchableHighlight:()=>kn,TouchableNativeFeedback:()=>fn,TouchableOpacity:()=>ne,TouchableWithoutFeedback:()=>Tn,UIManager:()=>Zr,Vibration:()=>Xr,View:()=>f,VirtualizedList:()=>mn,YellowBox:()=>pn,findNodeHandle:()=>En,unstable_createElement:()=>Er,useColorScheme:()=>yn,useLocaleContext:()=>Mn,useWindowDimensions:()=>xn});At(lt,Br);import*as Br from"react-native-web";import{unstable_createElement as Er,NativeModules as Fr,AccessibilityInfo as Or,Animated as Ir,Appearance as Pr,AppRegistry as $r,AppState as Lr,BackHandler as Wr,Clipboard as Dr,Dimensions as Hr,Easing as Vr,I18nManager as Nr,Keyboard as jr,InteractionManager as qr,LayoutAnimation as Jr,Linking as Kr,NativeEventEmitter as Ur,PanResponder as _r,PixelRatio as Qr,Platform as Gr,Share as Yr,StyleSheet as D,UIManager as Zr,Vibration as Xr,CheckBox as en,FlatList as tn,Image as rn,ImageBackground as nn,KeyboardAvoidingView as on,Picker as an,ProgressBar as sn,RefreshControl as ln,SafeAreaView as cn,SectionList as un,StatusBar as dn,Touchable as hn,TouchableNativeFeedback as fn,VirtualizedList as mn,YellowBox as pn,LogBox as bn,DeviceEventEmitter as gn,useColorScheme as yn,useLocaleContext as Mn,useWindowDimensions as xn}from"react-native-web";import*as A from"react-native-web";import{createElement as wn,forwardRef as Sn}from"react";function E(e){let t=Sn((n,o)=>{let{accessibilityState:i,accessibilityValue:a,...s}=n;for(let l of["busy","checked","disabled","expanded","selected"])i?.[l]!==void 0&&s[`aria-${l}`]===void 0&&(s[`aria-${l}`]=i[l]);for(let[l,u]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))a?.[l]!==void 0&&s[`aria-${u}`]===void 0&&(s[`aria-${u}`]=a[l]);return wn(e,{...s,ref:o})}),r=e.State;return r&&Object.assign(t,{State:r}),t.displayName=e.displayName??e.name??"NativeWebView",t}var f=E(A.View),c=E(A.Text),vn=E(A.TextInput),ne=E(A.TouchableOpacity),kn=E(A.TouchableHighlight),Tn=E(A.TouchableWithoutFeedback),Cn=E(A.Pressable),Ae=E(A.ScrollView),zn=E(A.Modal),An=E(A.Switch),Rn=E(A.ActivityIndicator),Bn=E(A.Button),En=A.findNodeHandle,Fn={alert(e,t,r,n){if(typeof document>"u")return;let o=document.createElement("dialog");o.dataset.buoyRoot="",o.setAttribute("aria-label",e),o.style.cssText="position:fixed;inset:0;margin:auto;width:min(440px,90vw);padding:24px;border:1px solid #475569;border-radius:14px;background:#17212e;color:#f1f5f9;font:14px system-ui;box-shadow:0 20px 80px #0008;z-index:2147483647";let i=document.createElement("h2");if(i.textContent=e,i.style.cssText="font-size:18px;margin:0 0 12px",o.appendChild(i),t){let u=document.createElement("p");u.textContent=t,u.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",o.appendChild(u)}let a=document.createElement("div");a.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let s=r?.length?r:[{text:"OK"}],l=()=>{o.close?.(),o.remove()};for(let u of s){let M=document.createElement("button");M.type="button",M.textContent=u.text??"OK",M.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${u.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,M.onclick=()=>{l(),u.onPress?.()},a.appendChild(M)}o.addEventListener("cancel",u=>{u.preventDefault(),n?.cancelable!==false&&(l(),n?.onDismiss?.())}),o.appendChild(a),document.body.appendChild(o),o.showModal?o.showModal():o.setAttribute("open","")}};import{Activity as On,JsModal as In,macOSColors as O,night as z,ModalHeader as oe,Pause as Pn,Play as $n,Trash2 as Ln}from"@buoy-gg/shared-ui/web";import{memo as Wn}from"react";import{macOSColors as Re}from"@buoy-gg/shared-ui/web";import{jsx as ct}from"react/jsx-runtime";var Dn=60;function Hn(e){return e>=80?Re.semantic.error:e>=40?Re.semantic.warning:Re.semantic.success}var Vn=Wn(function({history:e}){let t=e.slice(-Dn);return ct(f,{style:ut.row,pointerEvents:"none",children:t.map((r,n)=>ct(f,{style:[ut.bar,{height:Math.max(2,r/100*28),backgroundColor:Hn(r)}]},`b${n}`))})}),ut=D.create({row:{flexDirection:"row",alignItems:"flex-end",gap:1,height:28,alignSelf:"stretch"},bar:{flex:1,maxWidth:6,borderRadius:1,opacity:.9}});import{memo as Nn,useState as jn}from"react";import{macOSColors as de,night as w}from"@buoy-gg/shared-ui/web";import{jsx as R,jsxs as $}from"react/jsx-runtime";var qn=[{key:"windowMs",title:"RECENT"},{key:"calls",title:"CALLS"},{key:"avgMs",title:"AVG"},{key:"maxMs",title:"MAX"},{key:"totalMs",title:"TOTAL"}],dt={timeout:{text:"TIMEOUT",color:"#38BDF8",prefix:"setTimeout"},interval:{text:"INTERVAL",color:"#22D3EE",prefix:"setInterval"},immediate:{text:"IMMED",color:"#60A5FA",prefix:"setImmediate"},raf:{text:"RAF",color:"#34D399",prefix:"requestAnimationFrame"},microtask:{text:"MICRO",color:"#A78BFA",prefix:"queueMicrotask"},then:{text:"PROMISE",color:"#BF5AF2",prefix:"Promise.then"},bridge:{text:"BRIDGE",color:"#FBBF24",prefix:"bridge"},unattributed:{text:"SYSTEM",color:"#8E8E93"},other:{text:"OTHER",color:"#8E8E93",prefix:"other"}};function Be(e){return dt[e]??dt.other}function ht(e){if(e.api==="unattributed")return"events \xB7 React \xB7 native call-ins";if(e.api==="other")return"evicted cold origins";let t=Be(e.api).prefix,r=e.label;return t&&r.startsWith(t)&&(r=r.slice(t.length)),r=r.replace(/^[\s←@]+/,"").trim(),r.length>0?r:"anonymous"}function ie(e){return e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e>=100?`${Math.round(e)}`:`${Math.round(e*10)/10}`}function Jn(e){return e.calls<=0?"measured by probe \xB7 not reachable from JS":`${ie(e.calls)} calls \xB7 avg ${ie(e.avgMs)} \xB7 max ${ie(e.maxMs)} \xB7 total ${ie(e.totalMs)} ms`}var Kn=Nn(function({row:e,rank:t,onPress:r}){let n=Be(e.api);return $(r?ne:f,{style:T.row,...r?{onPress:()=>r(e),activeOpacity:.6}:{},children:[$(f,{style:T.topLine,children:[R(c,{style:T.rank,children:t}),R(f,{style:[T.badge,{borderColor:n.color,backgroundColor:`${n.color}1A`}],children:R(c,{style:[T.badgeText,{color:n.color}],children:n.text})}),R(c,{style:T.name,numberOfLines:1,children:ht(e)}),e.freezes>0&&$(c,{style:[T.freezeBadge,e.worstFreezeMs>=100&&T.freezeBadgeSevere],children:["\u26A0 \xD7",e.freezes]}),$(c,{style:[T.windowMs,e.api!=="unattributed"&&e.pctOfBusy>=25&&{color:e.pctOfBusy>=50?de.semantic.error:de.semantic.warning}],children:[ie(e.windowMs),R(c,{style:T.unit,children:" ms"})]}),$(c,{style:[T.pct,e.api==="unattributed"&&T.pctMuted],children:[Math.round(e.pctOfBusy),"%"]})]}),$(f,{style:T.subLine,children:[R(f,{style:T.barTrack,children:R(f,{style:[T.barFill,{width:`${Math.min(100,e.pctOfBusy)}%`,backgroundColor:n.color}]})}),R(c,{style:T.stats,numberOfLines:1,children:Jn(e)})]})]})},(e,t)=>e.rank===t.rank&&e.onPress===t.onPress&&e.row.key===t.row.key&&e.row.windowMs===t.row.windowMs&&e.row.calls===t.row.calls&&e.row.maxMs===t.row.maxMs&&e.row.totalMs===t.row.totalMs&&e.row.pctOfBusy===t.row.pctOfBusy&&e.row.freezes===t.row.freezes&&e.row.worstFreezeMs===t.row.worstFreezeMs);function Un({rows:e,onSelectRow:t}){let[r,n]=jn("windowMs"),o=r==="windowMs"?e:[...e].sort((i,a)=>a[r]-i[r]);return $(f,{style:L.root,children:[$(f,{style:L.sortRow,children:[R(c,{style:L.sortLabel,children:"SORT"}),qn.map(i=>R(ne,{onPress:()=>n(i.key),style:[L.sortChip,r===i.key&&L.sortChipOn],children:R(c,{style:[L.sortChipText,r===i.key&&L.sortChipTextOn],children:i.title})},i.key))]}),$(Ae,{style:L.body,children:[o.map((i,a)=>R(Kn,{row:i,rank:a+1,onPress:t},i.key)),o.length===0&&R(c,{style:L.empty,children:"No tasks observed yet \u2014 interact with the app."})]})]})}var L=D.create({root:{flex:1,minHeight:0},sortRow:{flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:10,paddingVertical:6,borderBottomWidth:1,borderBottomColor:w.color.border,backgroundColor:w.color.surface},sortLabel:{color:w.color.textTertiary,fontSize:9,fontWeight:"700",letterSpacing:.5,marginRight:2},sortChip:{borderWidth:1,borderColor:w.color.border,borderRadius:4,paddingHorizontal:7,paddingVertical:3},sortChipOn:{borderColor:w.color.accentBorderStrong,backgroundColor:w.color.accentSoft},sortChipText:{color:w.color.textTertiary,fontSize:9,fontWeight:"600",fontVariant:["tabular-nums"]},sortChipTextOn:{color:w.color.accent},body:{flex:1},empty:{color:w.color.textTertiary,fontSize:12,textAlign:"center",paddingVertical:24}}),T=D.create({row:{paddingHorizontal:10,paddingVertical:8,borderBottomWidth:D.hairlineWidth,borderBottomColor:w.color.border,gap:5},topLine:{flexDirection:"row",alignItems:"center",gap:6},rank:{width:16,color:w.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},badge:{borderWidth:1,borderRadius:3,paddingHorizontal:4,paddingVertical:1},badgeText:{fontSize:8,fontWeight:"700",letterSpacing:.4},name:{flex:1,color:w.color.text,fontSize:13,fontWeight:"500"},freezeBadge:{color:de.semantic.warning,fontSize:10,fontWeight:"700",fontVariant:["tabular-nums"]},freezeBadgeSevere:{color:de.semantic.error},windowMs:{color:w.color.text,fontSize:13,fontWeight:"700",fontVariant:["tabular-nums"]},unit:{color:w.color.textTertiary,fontSize:10,fontWeight:"400"},pct:{width:38,textAlign:"right",color:w.color.textSecondary,fontSize:12,fontWeight:"600",fontVariant:["tabular-nums"]},pctMuted:{color:w.color.textTertiary},subLine:{flexDirection:"row",alignItems:"center",gap:8,paddingLeft:22},barTrack:{width:72,height:4,borderRadius:2,backgroundColor:w.color.fillSecondary,overflow:"hidden"},barFill:{height:4,borderRadius:2,opacity:.85},stats:{flex:1,color:w.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]}});import{memo as _n}from"react";import{macOSColors as he,night as v,useSafeAreaInsets as Qn}from"@buoy-gg/shared-ui/web";import{Fragment as ft,jsx as y,jsxs as B}from"react/jsx-runtime";var mt={timeout:"Work scheduled with setTimeout. Time shown is the callback's exclusive run time on the JS thread.",interval:"A repeating setInterval. One scheduling site, many runs \u2014 a hot interval is the classic silent JS-FPS killer.",immediate:"Work scheduled with setImmediate \u2014 runs at the end of the current event-loop turn.",raf:"requestAnimationFrame work \u2014 runs once per frame while scheduled. Cost here directly trades against 60fps.",microtask:"queueMicrotask work \u2014 runs after the current task, before the thread yields.",then:"Promise reaction (.then/.catch/.finally). Named by the function that attached the reaction. Note: async/await bodies bypass .then and land in the System row instead.",bridge:"A native\u2192JS call-in over the legacy bridge (events, module callbacks), measured as its un-nested remainder.",unattributed:"Thread time the probe measured but no JS wrapper could claim: touch handlers, React commits, native call-ins, and async/await bodies. High here on New Architecture is normal \u2014 it's where UI work lives.",other:"Origins evicted from the table when the registry hit its cap \u2014 their totals are preserved here."};function Gn(e){return mt[e]??mt.other}function N(e){return e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:e>=100?`${Math.round(e)}`:`${Math.round(e*100)/100}`}function Yn(e){if(e<=0)return"\u2014";let t=e/1e3;return t<1?"just now":t<60?`${Math.round(t)}s ago`:`${Math.floor(t/60)}m ago`}function H({label:e,value:t,accent:r}){return B(f,{style:m.stat,children:[y(c,{style:m.statLabel,children:e}),y(c,{style:[m.statValue,r?{color:r}:null],children:t})]})}var Zn=_n(function({detail:e}){let t=Be(e.api),r=Qn({minBottom:12}),n=Math.max(1,...e.buckets);return B(Ae,{style:m.root,contentContainerStyle:{paddingBottom:r.bottom},children:[B(f,{style:m.identityRow,children:[y(f,{style:[m.badge,{borderColor:t.color,backgroundColor:`${t.color}1A`}],children:y(c,{style:[m.badgeText,{color:t.color}],children:t.text})}),y(c,{style:m.name,numberOfLines:2,children:ht(e)})]}),y(c,{style:m.explainer,children:Gn(e.api)}),y(c,{style:m.sectionTitle,children:"ACTIVITY \xB7 LAST 5S"}),y(f,{style:m.chartRow,children:e.buckets.map((o,i)=>y(f,{style:m.chartBarSlot,children:y(f,{style:[m.chartBar,{height:Math.max(2,o/n*44),backgroundColor:t.color}]})},`bk${i}`))}),B(f,{style:m.chartLegend,children:[B(c,{style:m.chartLegendText,children:[N(e.windowMs)," ms in window \xB7 ",e.pctOfBusy.toFixed(1),"% of busy time"]}),B(c,{style:m.chartLegendText,children:["peak ",N(n)," ms/250ms"]})]}),y(c,{style:m.sectionTitle,children:"STATS \xB7 SINCE START"}),B(f,{style:m.statGrid,children:[y(H,{label:"RUNS",value:e.calls>0?N(e.calls):"\u2014"}),y(H,{label:"SCHEDULED",value:e.scheduleCount>0?N(e.scheduleCount):"\u2014"}),y(H,{label:"AVG / RUN",value:e.calls>0?`${N(e.avgMs)} ms`:"\u2014"}),y(H,{label:"MAX / RUN",value:e.maxMs>0?`${N(e.maxMs)} ms`:"\u2014",accent:e.maxMs>=50?he.semantic.warning:void 0}),y(H,{label:"TOTAL",value:e.totalMs>0?`${N(e.totalMs)} ms`:"\u2014"}),y(H,{label:"LAST RUN",value:Yn(e.lastSeenAgoMs)}),y(H,{label:"FREEZES \xB7 60S",value:e.freezes>0?`${e.freezes}`:"0",accent:e.freezes>0?he.semantic.error:void 0}),y(H,{label:"WORST FREEZE",value:e.worstFreezeMs>0?`${e.worstFreezeMs} ms`:"\u2014",accent:e.worstFreezeMs>=100?he.semantic.error:e.worstFreezeMs>0?he.semantic.warning:void 0})]}),(e.caller||(e.frames?.length??0)>0)&&B(ft,{children:[y(c,{style:m.sectionTitle,children:"SCHEDULED FROM"}),B(f,{style:m.siteCard,children:[e.caller&&B(c,{style:m.siteCaller,children:[e.caller,"()"]}),e.file&&B(c,{style:m.siteFile,children:[e.file,e.line!=null?`:${e.line}`:""]}),e.frames?.map((o,i)=>B(c,{style:m.siteFrame,numberOfLines:1,children:[o.file,":",o.line,":",o.col]},`fr${i}`)),y(c,{style:m.siteNote,children:"Frames are bundle offsets (Hermes) \u2014 the caller name above is the readable part. Captured once when this origin got hot."})]})]}),!e.caller&&(e.frames?.length??0)===0&&e.api!=="unattributed"&&e.api!=="other"&&B(ft,{children:[y(c,{style:m.sectionTitle,children:"SCHEDULED FROM"}),y(c,{style:m.sitePending,children:e.promoted?"Stack capture pending \u2014 next schedule from this site will record it.":"Not hot enough yet \u2014 the scheduling stack is captured once an origin passes 25 schedules or 50ms total."})]})]})}),m=D.create({root:{flex:1,backgroundColor:"transparent",paddingHorizontal:12},identityRow:{flexDirection:"row",alignItems:"center",gap:8,paddingTop:12},badge:{borderWidth:1,borderRadius:3,paddingHorizontal:5,paddingVertical:2},badgeText:{fontSize:9,fontWeight:"700",letterSpacing:.4},name:{flex:1,color:v.color.text,fontSize:15,fontWeight:"600"},explainer:{color:v.color.textTertiary,fontSize:11,lineHeight:15,marginTop:6,marginBottom:4},sectionTitle:{color:v.color.textTertiary,fontSize:9,fontWeight:"700",letterSpacing:.5,marginTop:14,marginBottom:6},chartRow:{flexDirection:"row",alignItems:"flex-end",height:48,gap:2,backgroundColor:v.color.surface,borderRadius:6,borderWidth:1,borderColor:v.color.border,paddingHorizontal:6,paddingTop:2},chartBarSlot:{flex:1,alignItems:"center",justifyContent:"flex-end"},chartBar:{width:"70%",borderTopLeftRadius:2,borderTopRightRadius:2,opacity:.9},chartLegend:{flexDirection:"row",justifyContent:"space-between",marginTop:4},chartLegendText:{color:v.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},statGrid:{flexDirection:"row",flexWrap:"wrap",gap:8},stat:{width:"23%",minWidth:76,flexGrow:1,backgroundColor:v.color.surface,borderWidth:1,borderColor:v.color.border,borderRadius:6,paddingHorizontal:8,paddingVertical:6},statLabel:{color:v.color.textTertiary,fontSize:8,fontWeight:"700",letterSpacing:.4,marginBottom:3},statValue:{color:v.color.text,fontSize:13,fontWeight:"600",fontVariant:["tabular-nums"]},siteCard:{backgroundColor:v.color.surface,borderWidth:1,borderColor:v.color.border,borderRadius:6,padding:10,gap:3},siteCaller:{color:v.color.text,fontSize:13,fontWeight:"600"},siteFile:{color:v.color.info,fontSize:11},siteFrame:{color:v.color.textTertiary,fontSize:10,fontVariant:["tabular-nums"]},siteNote:{color:v.color.textTertiary,fontSize:9,opacity:.8,marginTop:4},sitePending:{color:v.color.textTertiary,fontSize:11}});import{Fragment as Xn,jsx as b,jsxs as W}from"react/jsx-runtime";function pt(e){return e>=80?O.semantic.error:e>=40?O.semantic.warning:O.semantic.success}function Ee(e){return e>=100?O.semantic.error:O.semantic.warning}function eo(e){let t=e.rows.find(r=>r.api!=="unattributed"&&r.api!=="other");return t&&t.pctOfBusy>=25&&e.busyPct>=15?{color:t.pctOfBusy>=50?O.semantic.error:O.semantic.warning,icon:"\u25B2",text:`${t.label} is eating ${Math.round(t.pctOfBusy)}% of thread time \u2014 start there.`}:e.freezeSummary.count>0?{color:Ee(e.freezeSummary.worstMs),icon:"\u25B2",text:`${e.freezeSummary.count} freeze${e.freezeSummary.count===1?"":"s"} in the last 60s (worst ${e.freezeSummary.worstMs}ms) \u2014 check rows marked \u26A0.`}:e.busyPct>=80?{color:O.semantic.warning,icon:"\u25B2",text:"Thread saturated by UI/React work \u2014 open Highlight Updates to find re-renders."}:{color:O.semantic.success,icon:"\u25CF",text:`Thread healthy at ${Math.round(e.busyPct)}% load \u2014 nothing worth chasing.`}}function bt({visible:e,onClose:t,onBack:r,onMinimize:n,initialModalState:o,minimizeTargetPosition:i,remoteSnapshot:a,remoteActions:s,embedded:l=false}){let u=a!==void 0,[M,F]=st(null);Ar(()=>{if(!(u||!e))return d.subscribe(F)},[u,e]);let p=u?a:M,g=Rr(()=>s??{pause:()=>d.pause(),resume:()=>d.resume(),clear:()=>d.clear()},[s]),C=p?.paused??false,fe=(p?.rows.length??0)>0,[me,$e]=st(null),vt=zr(j=>$e(j.key),[]),Le=!u&&me?d.getOriginDetail(me):null,We=me!==null,De=W(oe,{children:[We?b(oe.Navigation,{onBack:()=>$e(null)}):r?b(oe.Navigation,{onBack:r}):null,b(oe.Content,{title:"",noMargin:true,children:W(f,{style:x.titleRow,children:[b(On,{size:14,color:"#34D399"}),b(c,{style:x.title,children:"JS Top"}),p&&b(f,{style:[x.busyPill,{borderColor:pt(p.busyPct)}],children:W(c,{style:[x.busyText,{color:pt(p.busyPct)}],children:[p.busyPct.toFixed(0),"% BUSY"]})}),p&&p.freezeSummary.count>0&&b(f,{style:[x.busyPill,{borderColor:Ee(p.freezeSummary.worstMs)}],children:W(c,{style:[x.busyText,{color:Ee(p.freezeSummary.worstMs)}],children:["\u26A0 ",p.freezeSummary.count," \xB7"," ",p.freezeSummary.worstMs,"ms"]})})]})}),W(oe.Actions,{children:[b(ne,{onPress:C?g.resume:g.pause,style:[x.actionBtn,C&&x.actionBtnActive],accessibilityLabel:C?"Resume sampling":"Pause sampling",children:C?b($n,{size:14,color:z.color.accent}):b(Pn,{size:14,color:z.color.textSecondary})}),b(ne,{onPress:g.clear,disabled:!fe,style:[x.actionBtn,!fe&&x.actionBtnDisabled],accessibilityLabel:"Clear stats",children:b(Ln,{size:14,color:fe?z.color.textTertiary:z.color.textTertiary})})]})]}),He=b(f,{style:x.body,children:We?Le?b(Zn,{detail:Le}):b(c,{style:x.waiting,children:"This origin is no longer tracked (cleared or evicted)."}):p?W(Xn,{children:[(()=>{let j=eo(p);return W(f,{style:[x.diagnosis,{borderLeftColor:j.color}],children:[b(c,{style:[x.diagnosisIcon,{color:j.color}],children:j.icon}),b(c,{style:x.diagnosisText,children:j.text})]})})(),W(f,{style:x.sparklineRow,children:[b(c,{style:x.sparklineCaption,children:"JS THREAD LOAD \xB7 LAST 30s"}),b(Vn,{history:p.busyHistory})]}),!p.tiers.bridge&&b(c,{style:x.tierBanner,children:"\u201CSystem\u201D rows are UI/React/native work pure JS can\u2019t name \u2014 timers, rAF and Promise chains are fully attributed."}),b(Un,{rows:p.rows,onSelectRow:u?void 0:vt})]}):b(c,{style:x.waiting,children:u?"Waiting for device\u2026":"Starting engine\u2026"})});return l?W(f,{style:x.embeddedRoot,children:[b(f,{style:x.embeddedHeader,children:De}),He]}):b(In,{visible:e,onClose:t,onMinimize:n,minimizeTargetPosition:i,initialModalState:o,header:{showToggleButton:true,customContent:De},persistenceKey:"buoy-js-top-modal",enablePersistence:true,initialMode:"bottomSheet",disableScrollWrapper:true,children:He})}var x=D.create({titleRow:{flexDirection:"row",alignItems:"center",gap:8},title:{color:z.color.text,fontSize:14,fontWeight:"500"},busyPill:{borderWidth:1,borderRadius:4,paddingHorizontal:6,paddingVertical:2},busyText:{fontSize:10,fontWeight:"700",fontVariant:["tabular-nums"]},actionBtn:{width:32,height:32,borderRadius:8,backgroundColor:z.color.buttonSurface,borderWidth:1,borderColor:z.color.border,alignItems:"center",justifyContent:"center"},actionBtnActive:{backgroundColor:z.color.accentSoft,borderColor:z.color.accentBorderStrong},actionBtnDisabled:{opacity:.55},body:{flex:1,minHeight:0,backgroundColor:"transparent"},diagnosis:{flexDirection:"row",alignItems:"center",gap:8,marginHorizontal:10,marginTop:8,paddingHorizontal:10,paddingVertical:8,backgroundColor:z.color.surface,borderRadius:6,borderLeftWidth:3},diagnosisIcon:{fontSize:11,fontWeight:"700"},diagnosisText:{flex:1,color:z.color.text,fontSize:12,lineHeight:16},sparklineRow:{paddingHorizontal:10,paddingVertical:8,gap:4},sparklineCaption:{color:z.color.textTertiary,fontSize:8,fontWeight:"700",letterSpacing:.5},tierBanner:{color:z.color.textTertiary,fontSize:10,paddingHorizontal:10,paddingBottom:6},waiting:{color:z.color.textTertiary,fontSize:12,textAlign:"center",paddingVertical:32},embeddedRoot:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:O.background.base},embeddedHeader:{borderBottomWidth:1,borderBottomColor:O.border.default}});import{useEffect as gt,useState as yt}from"react";import{macOSColors as Fe,night as Oe}from"@buoy-gg/shared-ui/web";import{jsx as to,jsxs as Mt}from"react/jsx-runtime";function ro(e){return e>=80?Fe.semantic.error:e>=40?Fe.semantic.warning:Fe.semantic.success}function no(){let[e,t]=yt(()=>d.isEnabled()),[r,n]=yt(null);if(gt(()=>d.subscribeEnabled(t),[]),gt(()=>{if(!e){n(null);return}return d.subscribe(n)},[e]),!e||!r)return null;let o=r.rows.find(i=>i.api!=="unattributed");return Mt(f,{style:Ie.pill,pointerEvents:"none",children:[Mt(c,{style:[Ie.busy,{color:ro(r.busyPct)}],children:[r.busyPct.toFixed(0),"%"]}),o&&to(c,{style:Ie.label,numberOfLines:1,children:o.label})]})}var Ie=D.create({pill:{position:"absolute",top:60,left:8,flexDirection:"row",alignItems:"center",gap:6,backgroundColor:Oe.color.buttonSurface,borderWidth:1,borderColor:Oe.color.border,borderRadius:6,paddingHorizontal:8,paddingVertical:4,maxWidth:220},busy:{fontSize:11,fontWeight:"700",fontVariant:["tabular-nums"]},label:{color:Oe.color.textSecondary,fontSize:10,flexShrink:1}});import{useEffect as oo,useState as io}from"react";import{Activity as xt}from"@buoy-gg/shared-ui/web";import{jsx as wt}from"react/jsx-runtime";var Pe="#34D399",St="#6B7280";function ao({size:e}){let[t,r]=io(()=>d.isEnabled());return oo(()=>d.subscribeEnabled(r),[]),wt(xt,{size:e,color:t?Pe:St})}function so(){return null}var lo={id:"js-top",name:"JS TOP",description:"Toggle the floating JS-thread busy pill",slot:"row",icon:ao,component:so,props:{},launchMode:"toggle-only",onPress:()=>{d.setEnabled(!d.isEnabled())}},co={id:"js-top-modal",name:"TASKS",description:"Live Task Manager for the JS thread",slot:"both",icon:({size:e})=>wt(xt,{size:e,color:Pe}),component:bt,props:{enableSharedModalDimensions:false}};d.registerTierInstaller(br);d.registerTierInstaller(gr);d.registerTierInstaller(Sr);d.registerLongtaskProvider(vr);d.registerFreezeStatsProvider(kr);d.registerClearHook(Tr);try{typeof window<"u"&&(tt(),rt())}catch{}export{St as JS_TOP_DISABLED_COLOR,Pe as JS_TOP_ENABLED_COLOR,d as JsTopController,no as JsTopHudOverlay,bt as JsTopModal,co as jsTopModalPreset,lo as jsTopPreset,Cr as jsTopSyncAdapter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/js-top",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.45",
|
|
4
4
|
"description": "Inspect instrumented JavaScript timers, promises and callbacks to investigate work on the React Native JS thread.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@buoy-gg/shared-ui": "^7.0.
|
|
15
|
+
"@buoy-gg/shared-ui": "^7.0.45"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": "*"
|