@buoy-gg/focus-inspector 7.0.62 → 7.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/web/index.mjs CHANGED
@@ -1 +1 @@
1
- "use client";var Z=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var ze=(e,n)=>{for(var t in n)Z(e,t,{get:n[t],enumerable:true})},X=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Be(n))!He.call(e,i)&&i!==t&&Z(e,i,{get:()=>n[i],enumerable:!(a=Re(n,i))||a.enumerable});return e},Ue=(e,n,t)=>(X(e,n,"default"),t&&X(t,n,"default"));var Ln=(()=>{try{let e=globalThis.Capacitor;if(e&&typeof e.isNativePlatform=="function"&&e.isNativePlatform())return e.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{approxJsonSize as ee}from"@buoy-gg/shared-ui/web";var b=null,E=null,w=[],T=[],O=new Set,_=0,F=0,P=0,k=true,S=null,C=null,R=new Set,W=new Set;function x(){W.forEach(e=>{e()})}function We(e){w=w.length>=300?[...w.slice(1),e]:[...w,e]}function te(e){T=T.length>=400?[...T.slice(1),e]:[...T,e]}function je(e,n,t){for(let a=T.length-1;a>=0;a--){let i=T[a];if(t-i.at>250)break;if(!i.resolved&&i.tag===e)return i.resolved=true,i.movedTo=n,i.direction}return null}function ne(e,n,t){F+=1;let a=e!==null&&E!==null?Math.max(0,t-E):void 0,i={seq:F,fromTag:e,toTag:n,direction:je(e,n,t),at:t,dwellMs:a};We(i),n===null&&(_+=1)}function B(){C!==null&&(clearTimeout(C),C=null)}function re(e,n=Date.now()){if(!k||!Number.isFinite(e))return;B();let t=S?.tag??b;S=null,!(t===e&&b===e)&&(ne(t,e,n),b=e,E=n,O.add(e),x())}function ae(e,n=Date.now()){!k||!Number.isFinite(e)||b!==null&&e!==b||(S={tag:e,at:n},B(),C=setTimeout(()=>{if(C=null,!S)return;let t=S.tag;S=null,ne(t,null,Date.now()),b=null,E=null,x()},400))}function ie(e,n=Date.now()){if(!k)return;let t=w[w.length-1];if(t&&t.direction===null&&t.fromTag!==null&&n-t.at<=60){t.direction=e,P+=1,te({seq:P,tag:t.fromTag,direction:e,at:n,resolved:true,movedTo:t.toTag}),x();return}P+=1;let a={seq:P,tag:b,direction:e,at:n,resolved:false,movedTo:null};te(a);let i=setTimeout(()=>{R.delete(i),!a.resolved&&(a.resolved=true,a.movedTo=null,x())},250);R.add(i),x()}function H(){return{currentTag:b,presence:b!==null?"focused":F===0?"never-observed":"lost",currentSince:E,transitions:w,probes:T,visited:Array.from(O),lostCount:_,transitionCount:F,tracking:k}}function oe(){w=[],T=[],O=b!==null?new Set([b]):new Set,_=0,F=0,P=0,x()}function le(e){k!==e&&(k=e,e||(B(),S=null),x())}function Ke(){B(),R.forEach(e=>{clearTimeout(e)}),R.clear(),S=null,b=null,E=null,w=[],T=[],O=new Set,_=0,F=0,P=0,k=true,x()}function se(e){return W.add(e),()=>{W.delete(e)}}function qe(){x()}import{resolveDOMEventEmitter as $e}from"@buoy-gg/shared-ui/web/utils";var j=null,ue=false,D=[],A="idle",K=null;function Ge(){if(ue)return j;ue=true;let e=$e();return j=e.emitter,K=e.reason,j}function ce(e){let n=e?.nativeEvent;if(!n)return null;let t=n.target??n.tag;return typeof t=="number"&&Number.isFinite(t)?t:null}function de(){if(D.length>0)return;let e=Ge();if(!e){A="unavailable";return}try{D=[e.addListener("topFocus",n=>{let t=ce(n);t!==null&&re(t)}),e.addListener("topBlur",n=>{let t=ce(n);t!==null&&ae(t)})],A="listening"}catch(n){D=[],A="unavailable",K=n?.message??"addListener failed"}}function Ye(){D.forEach(e=>{try{e.remove()}catch{}}),D=[],A==="listening"&&(A="idle")}function Je(){return{status:A,reason:A==="unavailable"?K:null}}var q=false,N="web",I=false,Qe={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"};function fe(e){let n=Qe[e.key];n&&ie(n)}function ge(){I||typeof document>"u"||(I=true,document.addEventListener("keydown",fe,true))}function Ze(){I&&(I=false,document.removeEventListener("keydown",fe,true))}function Xe(){return I}import{getDOMNodeHandle as et,getDOMPublicInstance as tt,isDOMElement as nt}from"@buoy-gg/shared-ui/web/utils";var he={};ze(he,{AccessibilityInfo:()=>ot,ActivityIndicator:()=>on,Alert:()=>un,Animated:()=>lt,AppRegistry:()=>ut,AppState:()=>ct,Appearance:()=>st,BackHandler:()=>dt,Button:()=>ln,CheckBox:()=>Ft,Clipboard:()=>ft,DeviceEventEmitter:()=>Wt,Dimensions:()=>pe,Easing:()=>gt,FlatList:()=>Pt,I18nManager:()=>ht,Image:()=>Mt,ImageBackground:()=>Vt,InteractionManager:()=>mt,Keyboard:()=>pt,KeyboardAvoidingView:()=>Ct,LayoutAnimation:()=>bt,Linking:()=>vt,LogBox:()=>Ut,Modal:()=>rn,NativeEventEmitter:()=>yt,NativeModules:()=>it,PanResponder:()=>wt,Picker:()=>Dt,PixelRatio:()=>Tt,Platform:()=>xt,Pressable:()=>tn,ProgressBar:()=>Nt,RefreshControl:()=>It,SafeAreaView:()=>Lt,ScrollView:()=>nn,SectionList:()=>Ot,Share:()=>St,StatusBar:()=>_t,StyleSheet:()=>kt,Switch:()=>an,Text:()=>Jt,TextInput:()=>Qt,Touchable:()=>Rt,TouchableHighlight:()=>Xt,TouchableNativeFeedback:()=>Bt,TouchableOpacity:()=>Zt,TouchableWithoutFeedback:()=>en,UIManager:()=>At,Vibration:()=>Et,View:()=>Yt,VirtualizedList:()=>Ht,YellowBox:()=>zt,findNodeHandle:()=>sn,unstable_createElement:()=>at,useColorScheme:()=>jt,useLocaleContext:()=>Kt,useWindowDimensions:()=>qt});Ue(he,rt);import*as rt from"react-native-web";import{unstable_createElement as at,NativeModules as it,AccessibilityInfo as ot,Animated as lt,Appearance as st,AppRegistry as ut,AppState as ct,BackHandler as dt,Clipboard as ft,Dimensions as pe,Easing as gt,I18nManager as ht,Keyboard as pt,InteractionManager as mt,LayoutAnimation as bt,Linking as vt,NativeEventEmitter as yt,PanResponder as wt,PixelRatio as Tt,Platform as xt,Share as St,StyleSheet as kt,UIManager as At,Vibration as Et,CheckBox as Ft,FlatList as Pt,Image as Mt,ImageBackground as Vt,KeyboardAvoidingView as Ct,Picker as Dt,ProgressBar as Nt,RefreshControl as It,SafeAreaView as Lt,SectionList as Ot,StatusBar as _t,Touchable as Rt,TouchableNativeFeedback as Bt,VirtualizedList as Ht,YellowBox as zt,LogBox as Ut,DeviceEventEmitter as Wt,useColorScheme as jt,useLocaleContext as Kt,useWindowDimensions as qt}from"react-native-web";import*as h from"react-native-web";import{createElement as $t,forwardRef as Gt}from"react";function v(e){let n=Gt((a,i)=>{let{accessibilityState:r,accessibilityValue:o,...l}=a;for(let s of["busy","checked","disabled","expanded","selected"])r?.[s]!==void 0&&l[`aria-${s}`]===void 0&&(l[`aria-${s}`]=r[s]);for(let[s,u]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))o?.[s]!==void 0&&l[`aria-${u}`]===void 0&&(l[`aria-${u}`]=o[s]);return $t(e,{...l,ref:i})}),t=e.State;return t&&Object.assign(n,{State:t}),n.displayName=e.displayName??e.name??"NativeWebView",n}var Yt=v(h.View),Jt=v(h.Text),Qt=v(h.TextInput),Zt=v(h.TouchableOpacity),Xt=v(h.TouchableHighlight),en=v(h.TouchableWithoutFeedback),tn=v(h.Pressable),nn=v(h.ScrollView),rn=v(h.Modal),an=v(h.Switch),on=v(h.ActivityIndicator),ln=v(h.Button),sn=h.findNodeHandle,un={alert(e,n,t,a){if(typeof document>"u")return;let i=document.createElement("dialog");i.dataset.buoyRoot="",i.setAttribute("aria-label",e),i.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 r=document.createElement("h2");if(r.textContent=e,r.style.cssText="font-size:18px;margin:0 0 12px",i.appendChild(r),n){let u=document.createElement("p");u.textContent=n,u.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",i.appendChild(u)}let o=document.createElement("div");o.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let l=t?.length?t:[{text:"OK"}],s=()=>{i.close?.(),i.remove()};for(let u of l){let f=document.createElement("button");f.type="button",f.textContent=u.text??"OK",f.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${u.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,f.onclick=()=>{s(),u.onPress?.()},o.appendChild(f)}i.addEventListener("cancel",u=>{u.preventDefault(),a?.cancelable!==false&&(s(),a?.onDismiss?.())}),i.appendChild(o),document.body.appendChild(i),i.showModal?i.showModal():i.setAttribute("open","")}};var cn=22,me=new Set(["View","RCTView","ScrollView","RCTScrollView","RCTScrollContentView","SafeAreaView","RCTSafeAreaView","AndroidHorizontalScrollContentView","KeyboardAvoidingView","Pressable","PlatformPressable","TouchableOpacity","TouchableHighlight","TouchableWithoutFeedback","TouchableNativeFeedback","AnimatedComponent","Wrapper"]),$="TVFocusGuideView";function dn(){return typeof globalThis>"u"?null:globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__??null}function fn(){let e=dn();if(!e)return[];let n=[];try{if(e.renderers&&typeof e.renderers.forEach=="function"&&e.renderers.forEach((t,a)=>{try{let i=e.getFiberRoots?.(a);i&&i.forEach(r=>n.push(r))}catch{}}),n.length===0&&e.getFiberRoots){let t=e.getFiberRoots(1);t&&t.forEach(a=>n.push(a))}}catch{}return n}function gn(e){return e.tag===cn&&e.memoizedState!==null}function hn(e){let n=e.memoizedProps?.activityState;return n===0||n===1||e.memoizedProps?.isPageFocused===false}function G(e){return e?.memoizedProps??e?.pendingProps??null}function be(e){let n=e?.type;return n?typeof n=="string"?n:n.displayName||n.name||null:null}function ve(e){let n=e?._debugOwner||e?.return,t=0;for(;n&&t<30;){t++;let a=be(n);if(a&&!me.has(a)&&typeof n.type!="string")return a;n=n.return}return null}function ye(e){let n=tt(e);if(n)return n;if(!e)return null;let t=e;return t.canonical?.publicInstance?t.canonical.publicInstance:t.canonical&&typeof t.canonical.measure=="function"?t.canonical:typeof t.measure=="function"||typeof t.measureInWindow=="function"?t:null}function we(e){let n=et(e);if(n!==null)return n;if(e==null)return null;let t=e;if(typeof t.__nativeTag=="number")return t.__nativeTag;if(typeof t._nativeTag=="number")return t._nativeTag;if(typeof t.nativeTag=="number")return t.nativeTag;if(t.canonical){if(typeof t.canonical.__nativeTag=="number")return t.canonical.__nativeTag;if(typeof t.canonical._nativeTag=="number")return t.canonical._nativeTag;if(typeof t.canonical.nativeTag=="number")return t.canonical.nativeTag}return null}function pn(e){let n=ye(e.stateNode);if(n)return{instance:n,nativeTag:we(e.stateNode)};let t=[];e.child&&t.push(e.child);let a=0;for(;t.length>0&&a<4e3;){a++;let i=t.pop();if(!i)continue;let r=ye(i.stateNode);if(r)return{instance:r,nativeTag:we(i.stateNode)};i.child&&t.push(i.child),i.sibling&&t.push(i.sibling)}return null}function mn(e){if(typeof e.isTVSelectable=="boolean")return e.isTVSelectable;if(typeof e.focusable=="boolean")return e.focusable;if(typeof e.tvFocusable=="boolean")return e.tvFocusable}function bn(e){let n=typeof e.nextFocusUp=="number",t=typeof e.nextFocusDown=="number",a=typeof e.nextFocusLeft=="number",i=typeof e.nextFocusRight=="number";if(!(!n&&!t&&!a&&!i))return{up:n||void 0,down:t||void 0,left:a||void 0,right:i||void 0}}function Te(e){if(!e)return;let n=t=>{if(typeof t=="string")return t.trim()?t.trim().slice(0,60):void 0;if(typeof t=="number"&&Number.isFinite(t))return String(t)};return n(e.children)??n(e.title)??n(e.label)??void 0}function vn(e,n){let t=[],a=(r,o)=>{if(!r||o>n||t.length>=3)return;if(r!==e){let s=G(r);if(s&&typeof s.onPress=="function")return}let l=Te(G(r));l&&!t.includes(l)&&t.push(l),r.child&&a(r.child,o+1),r!==e&&r.sibling&&a(r.sibling,o)};e.child&&a(e.child,1);let i=t.join(" ").trim();return i?i.slice(0,60):void 0}function yn(e){return new Promise(n=>{let t=false,a=i=>{t||(t=true,n(i))};setTimeout(()=>a(null),1e3);try{typeof e.measureInWindow=="function"?e.measureInWindow((i,r,o,l)=>{a(o>0&&l>0?{x:i,y:r,width:o,height:l}:null)}):typeof e.measure=="function"?e.measure((i,r,o,l,s,u)=>{a(o>0&&l>0&&s!=null&&u!=null?{x:s,y:u,width:o,height:l}:null)}):a(null)}catch{a(null)}})}var Y=new Map;function wn(e,n,t){let a=[{fiber:e,context:n,depth:0}],i=new Set;for(;a.length>0;){let r=a.pop();if(!r)continue;let{fiber:o,depth:l}=r;if(!o||i.has(o)||l>500)continue;if(i.add(o),gn(o)||hn(o)){o.sibling&&a.push({fiber:o.sibling,context:r.context,depth:l});continue}let s=t(o,r.context);o.sibling&&a.push({fiber:o.sibling,context:r.context,depth:l}),o.child&&a.push({fiber:o.child,context:s,depth:l+1})}}function Tn(){let e=fn();if(e.length===0)return[];let n=[],t=new Set;for(let a of e)wn(a.current,{guideTag:null},(i,r)=>{let o=G(i);if(!o)return r;let l=be(i),s=l===$,u=mn(o),f=typeof o.onPress=="function"||typeof o.onLongPress=="function",c=o.hasTVPreferredFocus===true,p=bn(o);if(!(s||u===true||c||!!p||f&&u!==false||nt(i.stateNode)&&i.stateNode.matches('a[href],button,input,select,textarea,[tabindex],[contenteditable="true"]')&&!i.stateNode.matches(':disabled,[inert], [tabindex="-1"]')))return r;let d=pn(i),g=d?.nativeTag??null;if(g===null)return r;let L=s?{guideTag:g}:r;if(t.has(g)){let m=n.find(_e=>_e.node.nativeTag===g);return m&&(u!==void 0&&m.node.focusProps.focusable===void 0&&(m.node.focusProps.focusable=u),c&&(m.node.focusProps.hasTVPreferredFocus=true),p&&!m.node.focusProps.nextFocus&&(m.node.focusProps.nextFocus=p),f&&(m.node.pressable=true),!m.node.testID&&o.testID&&(m.node.testID=o.testID),s&&!m.node.guide&&(m.node.guide=xe(o),m.node.name=$)),L}t.add(g);let Q=l??"Unknown";(!l||me.has(l)||typeof i.type=="string")&&(Q=ve(i)??l??"Unknown");let Ie=o.accessibilityLabel||o["aria-label"]||void 0,Le=Te(o)??(f?vn(i,6):void 0),Oe={nativeTag:g,name:s?$:Q,owner:ve(i)??void 0,testID:o.testID||o["data-testid"]||void 0,label:Ie,text:Le,focusProps:{focusable:u,hasTVPreferredFocus:c||void 0,nextFocus:p},guide:s?xe(o):void 0,guideAncestorTag:r.guideTag??void 0,pressable:f||void 0};return d?.instance&&Y.set(g,d.instance),n.push({node:Oe,instance:d?.instance??null}),L});return n}function xe(e){return{autoFocus:e.autoFocus===true,hasDestinations:Array.isArray(e.destinations)&&e.destinations.length>0,enabled:e.enabled!==false,trap:{up:e.trapFocusUp===true,down:e.trapFocusDown===true,left:e.trapFocusLeft===true,right:e.trapFocusRight===true}}}function z(e){return Math.round(e*1e3)/1e3}var xn=400;async function Se(){Y.clear();let e=Tn();await Promise.all(e.map(async r=>{if(!r.instance)return;let o=await yn(r.instance);o&&(r.node.frame=o)}));let n=pe.get("window"),t=Math.round(n.width)||1,a=Math.round(n.height)||1,i=[];for(let r of e){let o=r.node.frame;if(o){let l=o.x+o.width/2,s=o.y+o.height/2;r.node.onScreen=s>=0&&s<=a&&l>=0&&l<=t,r.node.frame={x:z(o.x/t),y:z(o.y/a),width:z(o.width/t),height:z(o.height/a)}}if(i.push(r.node),i.length>=xn)break}return i.sort((r,o)=>{let l=r.frame?.y??2,s=o.frame?.y??2;return Math.abs(l-s)>.01?l-s:(r.frame?.x??2)-(o.frame?.x??2)}),{screen:{width:t,height:a},nodes:i,scannedAt:Date.now()}}function Sn(e){let n=Y.get(e);if(!n)return{ok:false,reason:"Unknown tag \u2014 rescan and try again."};if(typeof n.requestTVFocus!="function")return{ok:false,reason:"This element exposes no requestTVFocus()."};try{return n.requestTVFocus(),{ok:true}}catch(t){return{ok:false,reason:t?.message??"requestTVFocus() threw."}}}var ke=["up","down","left","right"];function kn(e,n){return`${e}:${n}`}function Ae(e,n,t=3,a=0){let i=new Map;for(let l of e){if(!l.resolved||l.tag===null||l.at<a)continue;let s=kn(l.tag,l.direction);l.movedTo===null?i.set(s,(i.get(s)??0)+1):i.set(s,0)}let r=new Map;for(let l of n)r.set(l.nativeTag,l);let o=[];return i.forEach((l,s)=>{if(l<t)return;let[u,f]=s.split(":"),c=Number(u),p=f;o.push({tag:c,direction:p,attempts:l,atEdge:An(r.get(c),p,n)})}),o.sort((l,s)=>s.attempts-l.attempts)}function An(e,n,t){let a=e?.frame;if(!a)return false;let i=a.x+a.width/2,r=a.y+a.height/2;for(let o of t){if(o.nativeTag===e.nativeTag||o.guide)continue;let l=o.frame;if(!l)continue;let s=l.x+l.width/2,u=l.y+l.height/2;switch(n){case"up":if(u<a.y)return false;break;case"down":if(u>a.y+a.height)return false;break;case"left":if(s<a.x)return false;break;case"right":if(s>a.x+a.width)return false;break}}return true}function En(e){if(e.length===0)return null;let n=1/0,t=1/0,a=-1/0,i=-1/0;for(let r of e)n=Math.min(n,r.x),t=Math.min(t,r.y),a=Math.max(a,r.x+r.width),i=Math.max(i,r.y+r.height);return{x:n,y:t,width:a-n,height:i-t}}function Fn(e,n,t){switch(t){case"up":return n.y<e.y;case"down":return n.y>e.y+e.height;case"left":return n.x<e.x;case"right":return n.x>e.x+e.width;default:return false}}var Pn=2;function Ee(e,n){let t=new Map;for(let r of n)t.set(r.nativeTag,r);let a=new Map;for(let r of e){let o=t.get(r.tag)?.guideAncestorTag??r.tag,l=a.get(o)??{containerTag:o,tags:new Set,directions:new Set};l.tags.add(r.tag),l.directions.add(r.direction),a.set(o,l)}let i=[];return a.forEach(r=>{if(r.directions.size<Pn)return;let o=new Set(r.tags);for(let d of n)d.guideAncestorTag===r.containerTag&&o.add(d.nativeTag);o.add(r.containerTag);let l=t.get(r.containerTag),s=l?.guide&&l.frame?l.frame:En(Array.from(o).map(d=>t.get(d)?.frame).filter(d=>!!d));if(!s)return;let u=0,f=0;for(let d of ke)n.some(g=>{if(g.guide||o.has(g.nativeTag)||!g.frame)return false;let L={x:g.frame.x+g.frame.width/2,y:g.frame.y+g.frame.height/2};return Fn(s,L,d)})&&(f+=1,r.directions.has(d)||(u+=1));if(f===0||u>0)return;let c=l?.guide,p=c!==void 0&&(c.trap.up||c.trap.down||c.trap.left||c.trap.right);i.push({tags:Array.from(r.tags).sort((d,g)=>d-g),containerTag:r.containerTag,directions:ke.filter(d=>r.directions.has(d)),guideTrapTag:p?r.containerTag:void 0})}),i}function Fe(e,n,t=0){let a=new Map;for(let r of n)a.set(r.nativeTag,r);let i=new Map;for(let r of e){let o=r.toTag;if(o===null||r.at<t)continue;let l=a.get(o),s=l?l.guide?"guide":null:n.length>0?"unknown":null;if(!s)continue;let u=i.get(o);u?(u.count+=1,u.at=r.at):i.set(o,{tag:o,reason:s,at:r.at,count:1})}return Array.from(i.values()).sort((r,o)=>o.at-r.at)}function Pe(e,n,t,a,i=0){let r=Ae(n,t,3,i);return{deadEnds:r,traps:Ee(r,t),invisibleStops:Fe(e,t,i),lostCount:a}}function Me(e,n,t,a){let i=new Set(n),r=e.filter(c=>!c.guide),o=r.filter(c=>!i.has(c.nativeTag)).map(c=>c.nativeTag),l=a.length>=12,s=new Set;for(let c of t)c.toTag!==null&&s.add(c.toTag);let u=new Map;for(let c of e)u.set(c.nativeTag,c);let f=l?o.filter(c=>{if(s.has(c))return false;let p=u.get(c);return p?.frame?r.some(d=>d.nativeTag!==c&&i.has(d.nativeTag)&&Mn(p,d)):false}):[];return{focusables:r.length,visited:r.filter(c=>i.has(c.nativeTag)).length,unvisited:o,suspectedUnreachable:f,meaningful:l}}var Ve=.12;function Mn(e,n){let t=e.frame,a=n.frame;if(!t||!a)return false;let i=t.x<a.x+a.width&&a.x<t.x+t.width,r=t.y<a.y+a.height&&a.y<t.y+t.height;return!!(i&&Math.max(t.y-(a.y+a.height),a.y-(t.y+t.height))<=Ve||r&&Math.max(t.x-(a.x+a.width),a.x-(t.x+t.width))<=Ve)}function Ce(e,n,t=[]){let a=[];for(let r of n)r.fromTag!==e||r.direction===null||a.push({at:r.at,direction:r.direction,to:r.toTag});for(let r of t)r.tag!==e||!r.resolved||r.movedTo!==null||a.push({at:r.at,direction:r.direction,to:null});a.sort((r,o)=>r.at-o.at);let i={};for(let r of a)i[r.direction]=r.to;return i}var De=1.5*1024*1024,Vn=500;q&&(de(),ge());var y=null,J=false,M=null,V=0;function Ne(){let e=new Map;for(let n of y?.nodes??[])e.set(n.nativeTag,n);return e}async function U(){if(J)return y;J=true;try{return y=await Se(),y}catch{return y}finally{J=false,qe()}}function Cn(){if(V===0)return;let{currentTag:e}=H();e!==null&&(Ne().has(e)||M===null&&(M=setTimeout(()=>{M=null,U()},Vn)))}function Dn(e,n){let t=[],a=0;for(let i=e.length-1;i>=0;i--){let r=ee(e[i],n).bytes;if(a+r>n&&t.length>0)break;t.push(e[i]),a+=r}return t.reverse(),t}function Nn(){let e=H(),n=y?.nodes??[],t=Je(),a=Pe(e.transitions,e.probes,n,e.lostCount,y?.scannedAt??0),i=Me(n,e.visited,e.transitions,e.probes),r=Ne(),o=ee(n,De).bytes,l=Dn(e.transitions,Math.max(64*1024,De-o)),s=a.deadEnds.filter(u=>!u.atEdge).length+a.traps.length+a.invisibleStops.length+(a.lostCount>0?1:0);return{supported:q||N==="web",platform:N,observer:t.status,observerReason:t.reason,keysListening:Xe(),tracking:e.tracking,presence:e.presence,current:e.currentTag===null?null:{tag:e.currentTag,node:r.get(e.currentTag)??null,since:e.currentSince??Date.now(),edges:Ce(e.currentTag,e.transitions,e.probes)},transitions:l,focusables:n,screen:y?.screen??null,scannedAt:y?.scannedAt??null,flags:a,coverage:i,stats:{focusables:i.focusables,visited:i.visited,transitions:e.transitionCount,flagged:s},capturedAt:Date.now()}}var In={version:1,getSnapshot(){return Nn()},subscribe(e){V+=1,V===1&&(N==="web"&&(de(),ge()),U());let n=se(()=>{Cn(),e()}),t=0,a=null,i=()=>{if(t+=1,(y?.nodes.length??0)>0||t>=100){a=null;return}U(),a=setTimeout(i,100)};return a=setTimeout(i,100),()=>{n(),a!==null&&clearTimeout(a),V=Math.max(0,V-1),V===0&&(M!==null&&(clearTimeout(M),M=null),N==="web"&&(Ye(),Ze()))}},actions:{async rescan(){return{ok:true,focusables:(await U())?.nodes.length??0}},clearHistory(){return oe(),{ok:true}},setTracking(e){return le(e?.enabled!==false),{tracking:H().tracking}},focusElement(e){let n=e?.nativeTag;return typeof n!="number"?{ok:false,reason:"nativeTag is required."}:!q&&N!=="web"?{ok:false,reason:"Not a TV build \u2014 there is no focus engine."}:Sn(n)}}};export{oe as clearHistory,Me as computeCoverage,Ae as detectDeadEnds,Pe as detectFlags,Fe as detectInvisibleStops,Ee as detectTraps,In as focusInspectorSyncAdapter,H as getState,Ce as observedEdges,ae as recordBlur,re as recordFocus,ie as recordKey,Ke as resetStore,Se as scanFocusables,le as setTracking,se as subscribe};
1
+ "use client";var ee=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var n in t)ee(e,n,{get:t[n],enumerable:true})},te=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of We(t))!qe.call(e,i)&&i!==n&&ee(e,i,{get:()=>t[i],enumerable:!(a=Ue(t,i))||a.enumerable});return e},Ge=(e,t,n)=>(te(e,t,"default"),n&&te(n,t,"default"));var $n=(()=>{try{let e=globalThis.Capacitor;if(e&&typeof e.isNativePlatform=="function"&&e.isNativePlatform())return e.DEBUG===true}catch{}return process.env.NODE_ENV!=="production"})();typeof window<"u"&&typeof globalThis.global>"u"&&(globalThis.global=globalThis);import{approxJsonSize as ne}from"@buoy-gg/shared-ui/web";var b=null,A=null,w=[],T=[],R=new Set,_=0,P=0,F=0,k=true,E=null,M=null,B=new Set,U=new Set;function x(){U.forEach(e=>{e()})}function Ye(e){w=w.length>=300?[...w.slice(1),e]:[...w,e]}function re(e){T=T.length>=400?[...T.slice(1),e]:[...T,e]}function Je(e,t,n){for(let a=T.length-1;a>=0;a--){let i=T[a];if(n-i.at>250)break;if(!i.resolved&&i.tag===e)return i.resolved=true,i.movedTo=t,i.direction}return null}function ae(e,t,n){P+=1;let a=e!==null&&A!==null?Math.max(0,n-A):void 0,i={seq:P,fromTag:e,toTag:t,direction:Je(e,t,n),at:n,dwellMs:a};Ye(i),t===null&&(_+=1)}function K(){M!==null&&(clearTimeout(M),M=null)}function ie(e,t=Date.now()){if(!k||!Number.isFinite(e))return;K();let n=E?.tag??b;E=null,!(n===e&&b===e)&&(ae(n,e,t),b=e,A=t,R.add(e),x())}function oe(e,t=Date.now()){!k||!Number.isFinite(e)||b!==null&&e!==b||(E={tag:e,at:t},K(),M=setTimeout(()=>{if(M=null,!E)return;let n=E.tag;E=null,ae(n,null,Date.now()),b=null,A=null,x()},400))}function le(e,t=Date.now()){if(!k)return;let n=w[w.length-1];if(n&&n.direction===null&&n.fromTag!==null&&t-n.at<=60){n.direction=e,F+=1,re({seq:F,tag:n.fromTag,direction:e,at:t,resolved:true,movedTo:n.toTag}),x();return}F+=1;let a={seq:F,tag:b,direction:e,at:t,resolved:false,movedTo:null};re(a);let i=setTimeout(()=>{B.delete(i),!a.resolved&&(a.resolved=true,a.movedTo=null,x())},250);B.add(i),x()}function H(){return{currentTag:b,presence:b!==null?"focused":P===0?"never-observed":"lost",currentSince:A,transitions:w,probes:T,visited:Array.from(R),lostCount:_,transitionCount:P,tracking:k}}function se(){w=[],T=[],R=b!==null?new Set([b]):new Set,_=0,P=0,F=0,x()}function ue(e){k!==e&&(k=e,e||(K(),E=null),x())}function Xe(){K(),B.forEach(e=>{clearTimeout(e)}),B.clear(),E=null,b=null,A=null,w=[],T=[],R=new Set,_=0,P=0,F=0,k=true,x()}function ce(e){return U.add(e),()=>{U.delete(e)}}function Qe(){x()}import{resolveDOMEventEmitter as Ze}from"@buoy-gg/shared-ui/web/utils";var W=null,de=false,V=[],S="idle",q=null;function et(){if(de)return W;de=true;let e=Ze();return W=e.emitter,q=e.reason,W}function fe(e){let t=e?.nativeEvent;if(!t)return null;let n=t.target??t.tag;return typeof n=="number"&&Number.isFinite(n)?n:null}function ge(){if(V.length>0)return;let e=et();if(!e){S="unavailable";return}try{V=[e.addListener("topFocus",t=>{let n=fe(t);n!==null&&ie(n)}),e.addListener("topBlur",t=>{let n=fe(t);n!==null&&oe(n)})],S="listening"}catch(t){V=[],S="unavailable",q=t?.message??"addListener failed"}}function tt(){V.forEach(e=>{try{e.remove()}catch{}}),V=[],S==="listening"&&(S="idle")}function nt(){return{status:S,reason:S==="unavailable"?q:null}}var $=false,N="web",D=false,rt={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"};function pe(e){let t=rt[e.key];t&&le(t)}function he(){D||typeof document>"u"||(D=true,document.addEventListener("keydown",pe,true))}function at(){D&&(D=false,document.removeEventListener("keydown",pe,true))}function it(){return D}import{getDOMNodeHandle as ot,getDOMPublicInstance as lt,isDOMElement as st}from"@buoy-gg/shared-ui/web/utils";var me={};$e(me,{AccessibilityInfo:()=>ft,ActivityIndicator:()=>vn,Alert:()=>Tn,Animated:()=>gt,AppRegistry:()=>ht,AppState:()=>mt,Appearance:()=>pt,BackHandler:()=>bt,Button:()=>yn,CheckBox:()=>Nt,Clipboard:()=>vt,DeviceEventEmitter:()=>Yt,Dimensions:()=>be,Easing:()=>yt,FlatList:()=>Dt,I18nManager:()=>wt,Image:()=>It,ImageBackground:()=>Ot,InteractionManager:()=>xt,Keyboard:()=>Tt,KeyboardAvoidingView:()=>Rt,LayoutAnimation:()=>Et,Linking:()=>kt,LogBox:()=>Gt,Modal:()=>mn,NativeEventEmitter:()=>St,NativeModules:()=>dt,PanResponder:()=>At,Picker:()=>_t,PixelRatio:()=>Pt,Platform:()=>Ft,Pressable:()=>pn,ProgressBar:()=>Bt,RefreshControl:()=>Kt,SafeAreaView:()=>Ht,ScrollView:()=>hn,SectionList:()=>zt,Share:()=>Lt,StatusBar:()=>jt,StyleSheet:()=>Ct,Switch:()=>bn,Text:()=>un,TextInput:()=>cn,Touchable:()=>Ut,TouchableHighlight:()=>fn,TouchableNativeFeedback:()=>Wt,TouchableOpacity:()=>dn,TouchableWithoutFeedback:()=>gn,UIManager:()=>Mt,Vibration:()=>Vt,View:()=>sn,VirtualizedList:()=>qt,YellowBox:()=>$t,findNodeHandle:()=>wn,unstable_createElement:()=>ct,useColorScheme:()=>Jt,useLocaleContext:()=>Xt,useWindowDimensions:()=>Qt});Ge(me,ut);import*as ut from"react-native-web";import{unstable_createElement as ct,NativeModules as dt,AccessibilityInfo as ft,Animated as gt,Appearance as pt,AppRegistry as ht,AppState as mt,BackHandler as bt,Clipboard as vt,Dimensions as be,Easing as yt,I18nManager as wt,Keyboard as Tt,InteractionManager as xt,LayoutAnimation as Et,Linking as kt,NativeEventEmitter as St,PanResponder as At,PixelRatio as Pt,Platform as Ft,Share as Lt,StyleSheet as Ct,UIManager as Mt,Vibration as Vt,CheckBox as Nt,FlatList as Dt,Image as It,ImageBackground as Ot,KeyboardAvoidingView as Rt,Picker as _t,ProgressBar as Bt,RefreshControl as Kt,SafeAreaView as Ht,SectionList as zt,StatusBar as jt,Touchable as Ut,TouchableNativeFeedback as Wt,VirtualizedList as qt,YellowBox as $t,LogBox as Gt,DeviceEventEmitter as Yt,useColorScheme as Jt,useLocaleContext as Xt,useWindowDimensions as Qt}from"react-native-web";import*as p from"react-native-web";import{createElement as G,forwardRef as ve,useCallback as Zt,useRef as en}from"react";import{useEffect as tn,useState as nn}from"react";import{createPortal as rn}from"react-dom";var an='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';import{jsx as on}from"react/jsx-runtime";var I=Symbol.for("@buoy-gg/portal-host"),ye=e=>{if(!(e instanceof Element))return false;if(e.closest("input, textarea, select"))return true;let t=e.closest("[contenteditable]")?.getAttribute("contenteditable")?.toLowerCase();return t===""||t==="true"||t==="plaintext-only"};function we(){let e=document;if(e[I])return e[I].host;let t=document.createElement("div");t.dataset.buoyPortalHost="",Object.assign(t.style,{position:"fixed",inset:"0",zIndex:"2147483647",pointerEvents:"none",fontFamily:an});let n=()=>{let u=document.fullscreenElement,d=u&&u.tagName!=="CANVAS"?u:document.body;t.parentElement!==d&&d.appendChild(t)},a=new Map,i=u=>{(!t.contains(u.target)||!ye(u.target))&&a.set(u.code||u.key,{key:u.key,code:u.code,location:u.location,keyCode:u.keyCode,which:u.which,altKey:u.altKey,ctrlKey:u.ctrlKey,metaKey:u.metaKey,shiftKey:u.shiftKey})},r=u=>{a.delete(u.code||u.key)},o=()=>a.clear(),l=()=>{let u=[...a.values()];a.clear();for(let d of u)document.dispatchEvent(new KeyboardEvent("keyup",{...d,bubbles:true}))},s=u=>{ye(u.target)&&u.stopPropagation()},c=u=>u.stopPropagation();return n(),document.addEventListener("fullscreenchange",n),document.addEventListener("keydown",i,true),document.addEventListener("keyup",r,true),window.addEventListener("blur",o),t.addEventListener("focusin",l),t.addEventListener("keydown",s),t.addEventListener("keyup",s),t.addEventListener("keypress",s),t.addEventListener("wheel",c,{passive:true}),e[I]={host:t,users:0,dispose:()=>{document.removeEventListener("fullscreenchange",n),document.removeEventListener("keydown",i,true),document.removeEventListener("keyup",r,true),window.removeEventListener("blur",o),t.remove(),delete e[I]}},t}function ln({children:e}){let[t,n]=nn(null);return tn(()=>{let a=we(),i=document[I];return i.users++,n(a),()=>{--i.users===0&&i.dispose()}},[]),t?rn(on("div",{"data-buoy-root":"",style:{display:"contents",pointerEvents:"auto"},children:e}),t):null}function v(e){let t=ve((a,i)=>{let{accessibilityState:r,accessibilityValue:o,...l}=a;for(let s of["busy","checked","disabled","expanded","selected"])r?.[s]!==void 0&&l[`aria-${s}`]===void 0&&(l[`aria-${s}`]=r[s]);for(let[s,c]of Object.entries({min:"valuemin",max:"valuemax",now:"valuenow",text:"valuetext"}))o?.[s]!==void 0&&l[`aria-${c}`]===void 0&&(l[`aria-${c}`]=o[s]);return G(e,{...l,ref:i})}),n=e.State;return n&&Object.assign(t,{State:n}),t.displayName=e.displayName??e.name??"NativeWebView",t}var sn=v(p.View),un=v(p.Text),cn=v(p.TextInput),dn=v(p.TouchableOpacity),fn=v(p.TouchableHighlight),gn=v(p.TouchableWithoutFeedback),pn=v(p.Pressable),hn=v(p.ScrollView),Te=ve((e,t)=>{let n=en(null),a=Zt(i=>{if(i){let r=i;for(;r.parentElement&&r.parentElement!==document.body;)r=r.parentElement;r.parentElement===document.body&&(n.current=r,Object.assign(r.style,{position:"relative",zIndex:"2147483647",pointerEvents:"auto"}),we().appendChild(r))}else n.current&&(document.body.appendChild(n.current),n.current=null);typeof t=="function"?t(i):t&&(t.current=i)},[t]);return G(ln,null,G(p.Modal,{...e,ref:a}))});Te.displayName="Modal";var mn=v(Te),bn=v(p.Switch),vn=v(p.ActivityIndicator),yn=v(p.Button),wn=p.findNodeHandle,Tn={alert(e,t,n,a){if(typeof document>"u")return;let i=document.createElement("dialog");i.dataset.buoyRoot="",i.setAttribute("aria-label",e),i.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 r=document.createElement("h2");if(r.textContent=e,r.style.cssText="font-size:18px;margin:0 0 12px",i.appendChild(r),t){let c=document.createElement("p");c.textContent=t,c.style.cssText="line-height:1.5;white-space:pre-wrap;margin:0 0 20px",i.appendChild(c)}let o=document.createElement("div");o.style.cssText="display:flex;justify-content:flex-end;flex-wrap:wrap;gap:8px";let l=n?.length?n:[{text:"OK"}],s=()=>{i.close?.(),i.remove()};for(let c of l){let u=document.createElement("button");u.type="button",u.textContent=c.text??"OK",u.style.cssText=`padding:9px 14px;border:1px solid #64748b;border-radius:7px;color:white;background:${c.style==="destructive"?"#a52b38":"#283a4d"};cursor:pointer;font:inherit`,u.onclick=()=>{s(),c.onPress?.()},o.appendChild(u)}i.addEventListener("cancel",c=>{c.preventDefault(),a?.cancelable!==false&&(s(),a?.onDismiss?.())}),i.appendChild(o),document.body.appendChild(i),i.showModal?i.showModal():i.setAttribute("open","")}};var xn=22,xe=new Set(["View","RCTView","ScrollView","RCTScrollView","RCTScrollContentView","SafeAreaView","RCTSafeAreaView","AndroidHorizontalScrollContentView","KeyboardAvoidingView","Pressable","PlatformPressable","TouchableOpacity","TouchableHighlight","TouchableWithoutFeedback","TouchableNativeFeedback","AnimatedComponent","Wrapper"]),Y="TVFocusGuideView";function En(){return typeof globalThis>"u"?null:globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__??null}function kn(){let e=En();if(!e)return[];let t=[];try{if(e.renderers&&typeof e.renderers.forEach=="function"&&e.renderers.forEach((n,a)=>{try{let i=e.getFiberRoots?.(a);i&&i.forEach(r=>t.push(r))}catch{}}),t.length===0&&e.getFiberRoots){let n=e.getFiberRoots(1);n&&n.forEach(a=>t.push(a))}}catch{}return t}function Sn(e){return e.tag===xn&&e.memoizedState!==null}function An(e){let t=e.memoizedProps?.activityState;return t===0||t===1||e.memoizedProps?.isPageFocused===false}function J(e){return e?.memoizedProps??e?.pendingProps??null}function Ee(e){let t=e?.type;return t?typeof t=="string"?t:t.displayName||t.name||null:null}function ke(e){let t=e?._debugOwner||e?.return,n=0;for(;t&&n<30;){n++;let a=Ee(t);if(a&&!xe.has(a)&&typeof t.type!="string")return a;t=t.return}return null}function Se(e){let t=lt(e);if(t)return t;if(!e)return null;let n=e;return n.canonical?.publicInstance?n.canonical.publicInstance:n.canonical&&typeof n.canonical.measure=="function"?n.canonical:typeof n.measure=="function"||typeof n.measureInWindow=="function"?n:null}function Ae(e){let t=ot(e);if(t!==null)return t;if(e==null)return null;let n=e;if(typeof n.__nativeTag=="number")return n.__nativeTag;if(typeof n._nativeTag=="number")return n._nativeTag;if(typeof n.nativeTag=="number")return n.nativeTag;if(n.canonical){if(typeof n.canonical.__nativeTag=="number")return n.canonical.__nativeTag;if(typeof n.canonical._nativeTag=="number")return n.canonical._nativeTag;if(typeof n.canonical.nativeTag=="number")return n.canonical.nativeTag}return null}function Pn(e){let t=Se(e.stateNode);if(t)return{instance:t,nativeTag:Ae(e.stateNode)};let n=[];e.child&&n.push(e.child);let a=0;for(;n.length>0&&a<4e3;){a++;let i=n.pop();if(!i)continue;let r=Se(i.stateNode);if(r)return{instance:r,nativeTag:Ae(i.stateNode)};i.child&&n.push(i.child),i.sibling&&n.push(i.sibling)}return null}function Fn(e){if(typeof e.isTVSelectable=="boolean")return e.isTVSelectable;if(typeof e.focusable=="boolean")return e.focusable;if(typeof e.tvFocusable=="boolean")return e.tvFocusable}function Ln(e){let t=typeof e.nextFocusUp=="number",n=typeof e.nextFocusDown=="number",a=typeof e.nextFocusLeft=="number",i=typeof e.nextFocusRight=="number";if(!(!t&&!n&&!a&&!i))return{up:t||void 0,down:n||void 0,left:a||void 0,right:i||void 0}}function Pe(e){if(!e)return;let t=n=>{if(typeof n=="string")return n.trim()?n.trim().slice(0,60):void 0;if(typeof n=="number"&&Number.isFinite(n))return String(n)};return t(e.children)??t(e.title)??t(e.label)??void 0}function Cn(e,t){let n=[],a=(r,o)=>{if(!r||o>t||n.length>=3)return;if(r!==e){let s=J(r);if(s&&typeof s.onPress=="function")return}let l=Pe(J(r));l&&!n.includes(l)&&n.push(l),r.child&&a(r.child,o+1),r!==e&&r.sibling&&a(r.sibling,o)};e.child&&a(e.child,1);let i=n.join(" ").trim();return i?i.slice(0,60):void 0}function Mn(e){return new Promise(t=>{let n=false,a=i=>{n||(n=true,t(i))};setTimeout(()=>a(null),1e3);try{typeof e.measureInWindow=="function"?e.measureInWindow((i,r,o,l)=>{a(o>0&&l>0?{x:i,y:r,width:o,height:l}:null)}):typeof e.measure=="function"?e.measure((i,r,o,l,s,c)=>{a(o>0&&l>0&&s!=null&&c!=null?{x:s,y:c,width:o,height:l}:null)}):a(null)}catch{a(null)}})}var X=new Map;function Vn(e,t,n){let a=[{fiber:e,context:t,depth:0}],i=new Set;for(;a.length>0;){let r=a.pop();if(!r)continue;let{fiber:o,depth:l}=r;if(!o||i.has(o)||l>500)continue;if(i.add(o),Sn(o)||An(o)){o.sibling&&a.push({fiber:o.sibling,context:r.context,depth:l});continue}let s=n(o,r.context);o.sibling&&a.push({fiber:o.sibling,context:r.context,depth:l}),o.child&&a.push({fiber:o.child,context:s,depth:l+1})}}function Nn(){let e=kn();if(e.length===0)return[];let t=[],n=new Set;for(let a of e)Vn(a.current,{guideTag:null},(i,r)=>{let o=J(i);if(!o)return r;let l=Ee(i),s=l===Y,c=Fn(o),u=typeof o.onPress=="function"||typeof o.onLongPress=="function",d=o.hasTVPreferredFocus===true,h=Ln(o);if(!(s||c===true||d||!!h||u&&c!==false||st(i.stateNode)&&i.stateNode.matches('a[href],button,input,select,textarea,[tabindex],[contenteditable="true"]')&&!i.stateNode.matches(':disabled,[inert], [tabindex="-1"]')))return r;let f=Pn(i),g=f?.nativeTag??null;if(g===null)return r;let O=s?{guideTag:g}:r;if(n.has(g)){let m=t.find(je=>je.node.nativeTag===g);return m&&(c!==void 0&&m.node.focusProps.focusable===void 0&&(m.node.focusProps.focusable=c),d&&(m.node.focusProps.hasTVPreferredFocus=true),h&&!m.node.focusProps.nextFocus&&(m.node.focusProps.nextFocus=h),u&&(m.node.pressable=true),!m.node.testID&&o.testID&&(m.node.testID=o.testID),s&&!m.node.guide&&(m.node.guide=Fe(o),m.node.name=Y)),O}n.add(g);let Z=l??"Unknown";(!l||xe.has(l)||typeof i.type=="string")&&(Z=ke(i)??l??"Unknown");let Ke=o.accessibilityLabel||o["aria-label"]||void 0,He=Pe(o)??(u?Cn(i,6):void 0),ze={nativeTag:g,name:s?Y:Z,owner:ke(i)??void 0,testID:o.testID||o["data-testid"]||void 0,label:Ke,text:He,focusProps:{focusable:c,hasTVPreferredFocus:d||void 0,nextFocus:h},guide:s?Fe(o):void 0,guideAncestorTag:r.guideTag??void 0,pressable:u||void 0};return f?.instance&&X.set(g,f.instance),t.push({node:ze,instance:f?.instance??null}),O});return t}function Fe(e){return{autoFocus:e.autoFocus===true,hasDestinations:Array.isArray(e.destinations)&&e.destinations.length>0,enabled:e.enabled!==false,trap:{up:e.trapFocusUp===true,down:e.trapFocusDown===true,left:e.trapFocusLeft===true,right:e.trapFocusRight===true}}}function z(e){return Math.round(e*1e3)/1e3}var Dn=400;async function Le(){X.clear();let e=Nn();await Promise.all(e.map(async r=>{if(!r.instance)return;let o=await Mn(r.instance);o&&(r.node.frame=o)}));let t=be.get("window"),n=Math.round(t.width)||1,a=Math.round(t.height)||1,i=[];for(let r of e){let o=r.node.frame;if(o){let l=o.x+o.width/2,s=o.y+o.height/2;r.node.onScreen=s>=0&&s<=a&&l>=0&&l<=n,r.node.frame={x:z(o.x/n),y:z(o.y/a),width:z(o.width/n),height:z(o.height/a)}}if(i.push(r.node),i.length>=Dn)break}return i.sort((r,o)=>{let l=r.frame?.y??2,s=o.frame?.y??2;return Math.abs(l-s)>.01?l-s:(r.frame?.x??2)-(o.frame?.x??2)}),{screen:{width:n,height:a},nodes:i,scannedAt:Date.now()}}function In(e){let t=X.get(e);if(!t)return{ok:false,reason:"Unknown tag \u2014 rescan and try again."};if(typeof t.requestTVFocus!="function")return{ok:false,reason:"This element exposes no requestTVFocus()."};try{return t.requestTVFocus(),{ok:true}}catch(n){return{ok:false,reason:n?.message??"requestTVFocus() threw."}}}var Ce=["up","down","left","right"];function On(e,t){return`${e}:${t}`}function Me(e,t,n=3,a=0){let i=new Map;for(let l of e){if(!l.resolved||l.tag===null||l.at<a)continue;let s=On(l.tag,l.direction);l.movedTo===null?i.set(s,(i.get(s)??0)+1):i.set(s,0)}let r=new Map;for(let l of t)r.set(l.nativeTag,l);let o=[];return i.forEach((l,s)=>{if(l<n)return;let[c,u]=s.split(":"),d=Number(c),h=u;o.push({tag:d,direction:h,attempts:l,atEdge:Rn(r.get(d),h,t)})}),o.sort((l,s)=>s.attempts-l.attempts)}function Rn(e,t,n){let a=e?.frame;if(!a)return false;let i=a.x+a.width/2,r=a.y+a.height/2;for(let o of n){if(o.nativeTag===e.nativeTag||o.guide)continue;let l=o.frame;if(!l)continue;let s=l.x+l.width/2,c=l.y+l.height/2;switch(t){case"up":if(c<a.y)return false;break;case"down":if(c>a.y+a.height)return false;break;case"left":if(s<a.x)return false;break;case"right":if(s>a.x+a.width)return false;break}}return true}function _n(e){if(e.length===0)return null;let t=1/0,n=1/0,a=-1/0,i=-1/0;for(let r of e)t=Math.min(t,r.x),n=Math.min(n,r.y),a=Math.max(a,r.x+r.width),i=Math.max(i,r.y+r.height);return{x:t,y:n,width:a-t,height:i-n}}function Bn(e,t,n){switch(n){case"up":return t.y<e.y;case"down":return t.y>e.y+e.height;case"left":return t.x<e.x;case"right":return t.x>e.x+e.width;default:return false}}var Kn=2;function Ve(e,t){let n=new Map;for(let r of t)n.set(r.nativeTag,r);let a=new Map;for(let r of e){let o=n.get(r.tag)?.guideAncestorTag??r.tag,l=a.get(o)??{containerTag:o,tags:new Set,directions:new Set};l.tags.add(r.tag),l.directions.add(r.direction),a.set(o,l)}let i=[];return a.forEach(r=>{if(r.directions.size<Kn)return;let o=new Set(r.tags);for(let f of t)f.guideAncestorTag===r.containerTag&&o.add(f.nativeTag);o.add(r.containerTag);let l=n.get(r.containerTag),s=l?.guide&&l.frame?l.frame:_n(Array.from(o).map(f=>n.get(f)?.frame).filter(f=>!!f));if(!s)return;let c=0,u=0;for(let f of Ce)t.some(g=>{if(g.guide||o.has(g.nativeTag)||!g.frame)return false;let O={x:g.frame.x+g.frame.width/2,y:g.frame.y+g.frame.height/2};return Bn(s,O,f)})&&(u+=1,r.directions.has(f)||(c+=1));if(u===0||c>0)return;let d=l?.guide,h=d!==void 0&&(d.trap.up||d.trap.down||d.trap.left||d.trap.right);i.push({tags:Array.from(r.tags).sort((f,g)=>f-g),containerTag:r.containerTag,directions:Ce.filter(f=>r.directions.has(f)),guideTrapTag:h?r.containerTag:void 0})}),i}function Ne(e,t,n=0){let a=new Map;for(let r of t)a.set(r.nativeTag,r);let i=new Map;for(let r of e){let o=r.toTag;if(o===null||r.at<n)continue;let l=a.get(o),s=l?l.guide?"guide":null:t.length>0?"unknown":null;if(!s)continue;let c=i.get(o);c?(c.count+=1,c.at=r.at):i.set(o,{tag:o,reason:s,at:r.at,count:1})}return Array.from(i.values()).sort((r,o)=>o.at-r.at)}function De(e,t,n,a,i=0){let r=Me(t,n,3,i);return{deadEnds:r,traps:Ve(r,n),invisibleStops:Ne(e,n,i),lostCount:a}}function Ie(e,t,n,a){let i=new Set(t),r=e.filter(d=>!d.guide),o=r.filter(d=>!i.has(d.nativeTag)).map(d=>d.nativeTag),l=a.length>=12,s=new Set;for(let d of n)d.toTag!==null&&s.add(d.toTag);let c=new Map;for(let d of e)c.set(d.nativeTag,d);let u=l?o.filter(d=>{if(s.has(d))return false;let h=c.get(d);return h?.frame?r.some(f=>f.nativeTag!==d&&i.has(f.nativeTag)&&Hn(h,f)):false}):[];return{focusables:r.length,visited:r.filter(d=>i.has(d.nativeTag)).length,unvisited:o,suspectedUnreachable:u,meaningful:l}}var Oe=.12;function Hn(e,t){let n=e.frame,a=t.frame;if(!n||!a)return false;let i=n.x<a.x+a.width&&a.x<n.x+n.width,r=n.y<a.y+a.height&&a.y<n.y+n.height;return!!(i&&Math.max(n.y-(a.y+a.height),a.y-(n.y+n.height))<=Oe||r&&Math.max(n.x-(a.x+a.width),a.x-(n.x+n.width))<=Oe)}function Re(e,t,n=[]){let a=[];for(let r of t)r.fromTag!==e||r.direction===null||a.push({at:r.at,direction:r.direction,to:r.toTag});for(let r of n)r.tag!==e||!r.resolved||r.movedTo!==null||a.push({at:r.at,direction:r.direction,to:null});a.sort((r,o)=>r.at-o.at);let i={};for(let r of a)i[r.direction]=r.to;return i}var _e=1.5*1024*1024,zn=500;$&&(ge(),he());var y=null,Q=false,L=null,C=0;function Be(){let e=new Map;for(let t of y?.nodes??[])e.set(t.nativeTag,t);return e}async function j(){if(Q)return y;Q=true;try{return y=await Le(),y}catch{return y}finally{Q=false,Qe()}}function jn(){if(C===0)return;let{currentTag:e}=H();e!==null&&(Be().has(e)||L===null&&(L=setTimeout(()=>{L=null,j()},zn)))}function Un(e,t){let n=[],a=0;for(let i=e.length-1;i>=0;i--){let r=ne(e[i],t).bytes;if(a+r>t&&n.length>0)break;n.push(e[i]),a+=r}return n.reverse(),n}function Wn(){let e=H(),t=y?.nodes??[],n=nt(),a=De(e.transitions,e.probes,t,e.lostCount,y?.scannedAt??0),i=Ie(t,e.visited,e.transitions,e.probes),r=Be(),o=ne(t,_e).bytes,l=Un(e.transitions,Math.max(64*1024,_e-o)),s=a.deadEnds.filter(c=>!c.atEdge).length+a.traps.length+a.invisibleStops.length+(a.lostCount>0?1:0);return{supported:$||N==="web",platform:N,observer:n.status,observerReason:n.reason,keysListening:it(),tracking:e.tracking,presence:e.presence,current:e.currentTag===null?null:{tag:e.currentTag,node:r.get(e.currentTag)??null,since:e.currentSince??Date.now(),edges:Re(e.currentTag,e.transitions,e.probes)},transitions:l,focusables:t,screen:y?.screen??null,scannedAt:y?.scannedAt??null,flags:a,coverage:i,stats:{focusables:i.focusables,visited:i.visited,transitions:e.transitionCount,flagged:s},capturedAt:Date.now()}}var qn={version:1,getSnapshot(){return Wn()},subscribe(e){C+=1,C===1&&(N==="web"&&(ge(),he()),j());let t=ce(()=>{jn(),e()}),n=0,a=null,i=()=>{if(n+=1,(y?.nodes.length??0)>0||n>=100){a=null;return}j(),a=setTimeout(i,100)};return a=setTimeout(i,100),()=>{t(),a!==null&&clearTimeout(a),C=Math.max(0,C-1),C===0&&(L!==null&&(clearTimeout(L),L=null),N==="web"&&(tt(),at()))}},actions:{async rescan(){return{ok:true,focusables:(await j())?.nodes.length??0}},clearHistory(){return se(),{ok:true}},setTracking(e){return ue(e?.enabled!==false),{tracking:H().tracking}},focusElement(e){let t=e?.nativeTag;return typeof t!="number"?{ok:false,reason:"nativeTag is required."}:!$&&N!=="web"?{ok:false,reason:"Not a TV build \u2014 there is no focus engine."}:In(t)}}};export{se as clearHistory,Ie as computeCoverage,Me as detectDeadEnds,De as detectFlags,Ne as detectInvisibleStops,Ve as detectTraps,qn as focusInspectorSyncAdapter,H as getState,Re as observedEdges,oe as recordBlur,ie as recordFocus,le as recordKey,Xe as resetStore,Le as scanFocusables,ue as setTracking,ce as subscribe};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buoy-gg/focus-inspector",
3
- "version": "7.0.62",
3
+ "version": "7.0.64",
4
4
  "description": "Observe focus transitions and discovered focusable elements in React Native TV apps. Review diagnostics in Buoy Desktop.",
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.62"
15
+ "@buoy-gg/shared-ui": "^7.0.64"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": "*"