@buoy-gg/focus-inspector 7.0.73 → 7.0.75

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