@limrun/ui 0.22.5 → 0.22.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- "use strict";require('./index.css');const g=require("react/jsx-runtime"),r=require("./core-BCBQrYsk.js"),l=require("react"),Uo=require("react-dom"),ee={sideBezel:1.7,topBezel:2.4,chin:2.4,baseHeight:2.2,baseOverhang:4,screenRadius:.9,lidThickness:.7},St=100+2*ee.sideBezel,et=St+2*ee.baseOverhang,xt=ee.topBezel+ee.chin+ee.baseHeight,Fo=(xt-2*ee.topBezel)/2,zo=8;function Go(d){const t=100/d,s=t+ee.topBezel+ee.chin;return{screenHeight:t,lidHeight:s,depth:s}}const qo=Math.PI/2,Zo=135,Jo=100,Qo=2400;function en(d){return qo-d*Math.PI/180}function tn(d){const t=Math.max(0,Math.min(1,d));return 1-Math.pow(1-t,3)}function ke(d,t,s,u=6){const v=[],E=[[d/2-s.top,t/2-s.top,s.top,0],[-d/2+s.top,t/2-s.top,s.top,Math.PI/2],[-d/2+s.bottom,-t/2+s.bottom,s.bottom,Math.PI],[d/2-s.bottom,-t/2+s.bottom,s.bottom,Math.PI*1.5]];for(const[y,M,N,S]of E)for(let k=0;k<=u;k++){const R=S+k*Math.PI/2/u;v.push({x:y+N*Math.cos(R),y:M+N*Math.sin(R),nx:Math.cos(R),ny:Math.sin(R)})}return v}function on(d){const{screenHeight:t,lidHeight:s,depth:u}=Go(d),v=[],E=(f,O,A)=>v.push({part:f,kind:O,vertices:new Float32Array(A)}),y=(f,O,A,L,P)=>{const H=A.map(Z=>Z.x),U=A.map(Z=>Z.y),[ne,G,ue,F]=[Math.min(...H),Math.max(...H),Math.min(...U),Math.max(...U)],q=(ne+G)/2,w=(ue+F)/2,ge=(Z,j)=>[...L(Z,j),...P,(Z-ne)/(G-ne||1),(j-ue)/(F-ue||1)],tt=[];for(let Z=0;Z<A.length;Z++){const j=A[Z],Te=A[(Z+1)%A.length];for(const De of[ge(q,w),ge(j.x,j.y),ge(Te.x,Te.y)])tt.push(...De)}E(f,O,tt)},M=(f,O,A,L,P,H,U)=>{const ne=[];for(let G=0;G<A.length;G++){const ue=A[G],F=A[(G+1)%A.length],q=(w,ge)=>[...L(w.x,w.y,ge),...P(w.nx,w.ny),0,0];for(const w of[q(ue,H),q(F,H),q(F,U),q(ue,H),q(F,U),q(ue,U)])ne.push(...w)}E(f,O,ne)},N=ke(St,s,{top:2.2,bottom:.4}),S=f=>f+s/2,k=ee.lidThickness;M("lid","shell",N,(f,O,A)=>[f,S(O),A],(f,O)=>[f,O,0],-k,0),y("lid","shell",N,(f,O)=>[f,S(O),-k],[0,0,-1]),y("lid","glass",ke(St-.5,s-.5,{top:1.95,bottom:.2}),(f,O)=>[f,S(O),.01],[0,0,1]);const R=ee.chin;y("lid","screen",ke(100,t,{top:ee.screenRadius,bottom:0}),(f,O)=>[f,R+t/2+O,.02],[0,0,1]),y("lid","camera",ke(.5,.5,{top:.25,bottom:.25},4),(f,O)=>[f,s-ee.topBezel/2+O,.02],[0,0,1]);const Y=ke(et,u+k,{top:3,bottom:3}),K=f=>(u-k)/2-f;M("base","shell",Y,(f,O,A)=>[f,A,K(O)],(f,O)=>[f,0,-O],-2.2,0),y("base","shell",Y,(f,O)=>[f,0,K(O)],[0,1,0]),y("base","shell",Y,(f,O)=>[f,-2.2,K(O)],[0,-1,0]);const te=(f,O,A,L,P,H,U)=>y("base",f,ke(L,P,{top:U,bottom:U},3),(ne,G)=>[O+ne,H,A-G],[0,1,0]),pe=et*.72,ae=u*.08,_=[.55,1,1,1,1,1],oe=u*.4/_.reduce((f,O)=>f+O,0);te("well",0,ae+u*.4/2,pe+1.4,u*.4+1.4,.01,.8);let B=ae;for(const[f,O]of _.entries()){const A=O*oe,L=pe/14;for(let P=0;P<14;P++){if(f===5&&P>4&&P<9)continue;const H=f===5&&P===4?5:1;te("keys",-pe/2+L*(P+H/2),B+A/2,L*H-.5,A-.5,.03,.3)}B+=A}te("trackpad",0,u*.72,et*.4,u*.36,.01,1.2),y("base","scoop",ke(14,.9,{top:0,bottom:.45},3),(f,O)=>[f,-.45+O,u+.01],[0,0,1]);const D=new Map;for(const f of v){const O=`${f.part}:${f.kind}`;D.set(O,[...D.get(O)??[],f])}return[...D.values()].map(f=>{const O=new Float32Array(f.reduce((L,P)=>L+P.vertices.length,0));let A=0;for(const L of f)O.set(L.vertices,A),A+=L.vertices.length;return{part:f[0].part,kind:f[0].kind,vertices:O}})}function nn(d,t,s=0){const u=d>=t?1:d/t,v=d>=t?t/d:1,E=(1-u)/2,y=s>0?1-v:(1-v)/2;return{repeat:[1/u,1/v],offset:[(0-E)/u,(0-y)/v]}}function rn(d,t,s){const u=d*s.repeat[0]+s.offset[0],v=t*s.repeat[1]+s.offset[1],E=1e-9;if(u<-E||u>1+E||v<-E||v>1+E)return;const y=M=>Math.max(0,Math.min(1,M));return{x:y(u),y:y(1-v)}}const sn=150,cn=8;class an{constructor(t,s=()=>!1){this.send=t,this.blocked=s}send;blocked;last;gesture;screen;pointer(t,s,u){const v=t===r.MAC_INPUT_ACTION.UP&&!!this.last?.buttons;this.blocked()&&!v||(this.last={...s,buttons:u},this.send(r.createMouseControlMessage(t,s.width,s.height,s.x,s.y,u)))}scroll(t,s,u){this.blocked()||this.send(r.createMacScrollMessage(t.width,t.height,t.x,t.y,s,u))}touch(t,s,u){const v=this.gesture;if(s.length>=2){const y={x:s.reduce((M,N)=>M+N.x,0)/s.length,y:s.reduce((M,N)=>M+N.y,0)/s.length};if(v?.mode==="scroll"){const M=u.map(y.x,y.y);M&&t==="touchmove"&&this.scroll(M,(v.x-y.x)*u.scale,(v.y-y.y)*u.scale)}else v?.mode==="press"?this.lift(v,u):v?.mode==="pending"&&clearTimeout(v.timer);return this.gesture={mode:"scroll",...y},!1}const E=s[0];if(E&&t==="touchstart"&&!v)return this.blocked()||!u.contains(E.x,E.y)?!1:(this.screen=u,this.gesture={mode:"pending",x:E.x,y:E.y,timer:setTimeout(()=>this.press(),sn)},!0);if(E&&v?.mode==="pending"){if(Math.hypot(E.x-v.x,E.y-v.y)<cn)return!1;this.press()}if(E&&this.gesture?.mode==="press"){this.gesture={mode:"press",x:E.x,y:E.y};const y=u.map(E.x,E.y);return y&&this.pointer(r.MAC_INPUT_ACTION.MOVE,y,1),!1}if(s.length===0){v?.mode==="pending"&&(t==="touchcancel"?clearTimeout(v.timer):this.press());const y=this.gesture;y?.mode==="press"&&this.lift(y,u),this.gesture=void 0}return!1}release(){clearTimeout(this.gesture?.timer),this.gesture=void 0;const t=this.last;t?.buttons&&this.pointer(r.MAC_INPUT_ACTION.UP,t,0)}press(){const t=this.gesture;if(t?.mode!=="pending")return;clearTimeout(t.timer),this.gesture={mode:"press",x:t.x,y:t.y};const s=this.screen?.map(t.x,t.y);s&&this.pointer(r.MAC_INPUT_ACTION.DOWN,s,1)}lift(t,s){const u=s.map(t.x,t.y);u&&this.pointer(r.MAC_INPUT_ACTION.UP,u,0)}}function ln(d,t){return t.type==="choose"?t.mode===d.mode?d:t.mode==="3d"?{...d,mode:"3d",selection:d.selection+1}:{...d,mode:"2d"}:d.mode!=="3d"||t.selection!==d.selection||d.ready===t.selection?d:{...d,ready:t.selection}}function ao(d){const[t,s]=l.useReducer(ln,{mode:"2d",selection:0,ready:0}),u=l.useRef(t);u.current=t;const v=l.useRef(d);v.current=d;const{mode:E,selection:y,ready:M}=t,N=l.useCallback(R=>s({type:"choose",mode:R}),[]),S=l.useCallback(()=>{const R=u.current;R.mode!=="3d"||R.selection!==y||R.ready===y||(v.current?.(),s({type:"ready",selection:y}))},[y]),k=E==="3d"&&M!==y;return{mode:E,shown:E==="3d"&&!k?"3d":"2d",loading:k,choose:N,onReady:S}}function lo({view:d,label:t}){return g.jsxs("div",{className:"rc-duo-mode",role:"group","aria-label":t,children:[g.jsx("button",{type:"button","aria-pressed":d.mode==="2d",onClick:()=>d.choose("2d"),children:"2D"}),g.jsx("button",{type:"button","aria-pressed":d.mode==="3d","aria-busy":d.loading,title:d.loading?"Loading 3D":void 0,onClick:()=>d.choose("3d"),children:"3D"})]})}const dn=async d=>{if(!d)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(d),!0}catch{}try{const t=document.createElement("textarea");t.value=d,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return!1}},un=l.memo(function({element:t,screen:s,highlighted:u,selected:v,selectable:E,onClick:y}){const M=r.clampAxFrameForScreen(t.frame,s);if(!M)return null;const N=r.axElementSummary(t);return g.jsx("button",{type:"button",className:t.enabled?"rc-inspect-box":"rc-inspect-box rc-inspect-box-disabled","data-ax-id":t.id,"data-ax-path":t.path,"data-ax-label":t.label||void 0,"data-ax-role":t.role||void 0,"data-highlighted":u?"true":"false","data-selected":v?"true":"false","aria-label":N,onClick:S=>{E&&(S.preventDefault(),S.stopPropagation(),y(t,{x:S.clientX,y:S.clientY}))},style:{left:`${M.x/s.width*100}%`,top:`${M.y/s.height*100}%`,width:`${M.width/s.width*100}%`,height:`${M.height/s.height*100}%`}})},(d,t)=>d.highlighted===t.highlighted&&d.selected===t.selected&&d.selectable===t.selectable&&d.screen.width===t.screen.width&&d.screen.height===t.screen.height&&d.onClick===t.onClick&&r.axElementsEqual(d.element,t.element)),hn=260,fn=220,mn=6,pn=8,gn=l.memo(function({element:t,platform:s,anchor:u,cursorAnchored:v,showActions:E,onTap:y}){const[M,N]=l.useState(null);l.useEffect(()=>{if(!M)return;const _=window.setTimeout(()=>N(null),1100);return()=>window.clearTimeout(_)},[M]);const S=l.useMemo(()=>{const _=hn,oe=fn,B=mn,D=pn,f=typeof window<"u"?window.innerWidth:1024,O=typeof window<"u"?window.innerHeight:768,A=u.x+B+_<=f-D,L=u.y-B-oe>=D;let P=A?u.x+B:u.x-B,H=L?u.y-B:u.y+B;const G=`translate(${A?"0":"-100%"}, ${L?"-100%":"0"})`;return P=Math.max(D+(A?0:_),Math.min(f-D-(A?_:0),P)),H=Math.max(D+(L?oe:0),Math.min(O-D-(L?0:oe),H)),{left:`${P}px`,top:`${H}px`,transform:G}},[u.x,u.y]),k=l.useMemo(()=>r.axElementSelectorExpression(t,s),[t,s]),R=s==="ios"?t.selectors.AXUniqueId:t.selectors.resourceId,Y=s==="ios"?"AXUniqueId":"resourceId",K=l.useCallback(async(_,oe)=>{if(!_)return;await dn(_)&&N(oe)},[]),te=r.axElementRoleLabel(t),pe=t.label||t.value||te,ae=r.axElementSummary(t);return Uo.createPortal(g.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":v?"true":"false",style:S,onClick:_=>_.stopPropagation(),onMouseDown:_=>_.stopPropagation(),onMouseMove:_=>_.stopPropagation(),children:[g.jsxs("div",{className:"rc-inspect-card-header",children:[g.jsx("span",{className:"rc-inspect-card-role",children:te}),!t.enabled&&g.jsx("span",{className:"rc-inspect-card-tag",children:"disabled"}),t.focused&&g.jsx("span",{className:"rc-inspect-card-tag rc-inspect-card-tag-blue",children:"focused"})]}),g.jsx("p",{className:"rc-inspect-card-title",title:ae,children:pe}),R&&g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsxs("span",{className:"rc-inspect-card-row-label",children:[Y,":"]}),g.jsx("span",{className:"rc-inspect-card-row-value",children:R})]}),t.value&&t.value!==t.label&&g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsx("span",{className:"rc-inspect-card-row-label",children:"value:"}),g.jsx("span",{className:"rc-inspect-card-row-value",children:t.value})]}),g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsx("span",{className:"rc-inspect-card-row-label",children:"frame:"}),g.jsxs("span",{className:"rc-inspect-card-row-value",children:[Math.round(t.frame.width),"×",Math.round(t.frame.height)," @ ",Math.round(t.frame.x),",",Math.round(t.frame.y)]})]}),E&&g.jsxs("div",{className:"rc-inspect-card-actions",children:[g.jsx("button",{type:"button",className:"rc-inspect-card-btn rc-inspect-card-btn-primary",disabled:!y,onClick:()=>y?.(t,u),children:"Tap"}),g.jsx("button",{type:"button",className:M==="selector"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!k,title:k??"No usable selector for this element",onClick:()=>K(k??void 0,"selector"),children:M==="selector"?"Copied!":"Copy selector"}),g.jsx("button",{type:"button",className:M==="id"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!R,title:R??`No ${Y}`,onClick:()=>K(R,"id"),children:M==="id"?"Copied!":`Copy ${Y}`})]})]}),document.body)}),yn=l.memo(function({snapshot:t,geometry:s,highlightedId:u,selectedId:v,mode:E,cursorPosition:y,frozenCursorPosition:M,onSelectChange:N,onTapElement:S}){const k=E==="select",R=k?u!==null&&u!==v:u!==null,Y=k?u??v:u,K=l.useMemo(()=>{const D=new Map;if(!t)return D;for(const f of t.elements)D.set(f.id,f);return D},[t]),te=l.useMemo(()=>Y?K.get(Y)??null:null,[Y,K]);if(!(!!t&&!!s&&t.screen.width>0&&t.screen.height>0&&t.elements.length>0))return null;const ae=R?y:M??y,_=R,oe=k&&!R&&v!==null,B=D=>{k&&D.target===D.currentTarget&&N(null,null)};return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:k?"rc-inspect-overlay rc-inspect-overlay-select":"rc-inspect-overlay",style:{left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`},onClick:B,children:t.elements.map(D=>g.jsx(un,{element:D,screen:t.screen,highlighted:D.id===u,selected:D.id===v,selectable:k,onClick:N},D.id))}),te&&ae&&g.jsx(gn,{element:te,platform:t.platform,anchor:ae,cursorAnchored:_,showActions:oe,onTap:S})]})});function vn(d,t){if(!t.startsWith("lim_st_"))return!1;try{const s=new URL(d).pathname.split("/").map(decodeURIComponent).find(S=>/^(ios|android)_[a-z0-9_]+$/.test(S));if(!s)return!1;const u=s.split("_")[0],v=t.slice(7).split(".");if(v.length!==3||v.some(S=>!S))return!1;const E=atob(v[1].replace(/-/g,"+").replace(/_/g,"/")),y=JSON.parse(new TextDecoder().decode(Uint8Array.from(E,S=>S.charCodeAt(0))));if(!y||typeof y!="object"||!("scopes"in y))return!1;const M=y.scopes;if(!Array.isArray(M)||!M.every(S=>typeof S=="string"))return!1;let N=!1;for(const S of M){const[k,R,Y,K]=S.split(":");if(!(K!==void 0||k!==u&&k!=="*")&&!(R!==s&&R!=="*")){if(Y==="stream"||Y==="all")return!1;Y==="watch"&&(N=!0)}}return N}catch{return!1}}const Tn=l.lazy(()=>Promise.resolve().then(()=>require("./duo-view-tUJbbWoS.js")).then(d=>d.duoView)),On=l.lazy(()=>Promise.resolve().then(()=>require("./macbook-frame-BxJfxUcU.js"))),gt=d=>Object.entries(r.AMOTION_EVENT).find(([s,u])=>s.startsWith("ACTION_")&&u===d)?.[0]??String(d),so=1920,co=1200,En=(d,t)=>d===so&&t===co||d===co&&t===so,Mn={ios:{videoBorderRadiusMultiplier:.15,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:.9678},landscape:{widthMultiplier:.9678}}},android:{videoBorderRadiusMultiplier:.13,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:.967},landscape:{widthMultiplier:.962}}},macos:{videoBorderRadiusMultiplier:0,loadingLogoSize:"10%",videoPosition:{portrait:{heightMultiplier:1},landscape:{widthMultiplier:1}}}},An={"iphone-se":{videoBorderRadiusMultiplier:0,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:667/889},landscape:{widthMultiplier:667/889}},homeButton:{offset:389/889,diameter:64/889}},"iphone-17e":{videoBorderRadiusMultiplier:47.33/452,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:844/888},landscape:{widthMultiplier:844/888}}}},Ct=16/10,yt=44,bn={videoBorderRadiusMultiplier:32/1837,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:2560/2798},landscape:{widthMultiplier:2560/2798}}};function Nn(d){const t=d.code,s=r.codeMap[t];if(!s)return r.debugWarn(`Unknown event.code: ${t}, key: ${d.key}`),null;let u=r.ANDROID_KEYS.META_NONE;const v=t>="KeyA"&&t<="KeyZ",E=d.getModifierState("CapsLock"),y=d.shiftKey;let M=y;return v&&(M=y!==E),M&&(u|=r.ANDROID_KEYS.META_SHIFT_ON),d.ctrlKey&&(u|=r.ANDROID_KEYS.META_CTRL_ON),d.altKey&&(u|=r.ANDROID_KEYS.META_ALT_ON),d.metaKey&&(u|=r.ANDROID_KEYS.META_META_ON),{keycode:s,metaState:u}}function vt(d,t){const s=Object.keys(d);return s.length===Object.keys(t).length&&s.every(u=>d[u]===t[u])}const _n=l.forwardRef(({className:d,url:t,token:s,sessionId:u,openUrl:v,watchOnly:E=!1,showFrame:y=!0,animateLid:M=!0,deviceModel:N,duoModelUrl:S,macbookModelUrl:k,autoReconnect:R,jitterBufferTargetMs:Y,onPlaybackStats:K,onTerminated:te,assets:pe,onConnectionStateChange:ae,inspectMode:_,onAxSnapshotChange:oe,onInspectSelectionChange:B,onAxStatusChange:D,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:A,onCameraDemandChange:L,onCameraStats:P,onTrace:H,microphoneEnabled:U=!1,onMicrophoneStateChange:ne},G)=>{const ue=l.useMemo(()=>vn(t,s),[t,s]),F=E||ue,q=l.useRef(null),w=l.useRef(null),ge=l.useRef(null),[tt,Z]=l.useState(!1),j=N==="iphone-duo"||tt,Te=N==="iphone-duo"?N:void 0,De=l.useRef(null),[kt,uo]=l.useState(null),[Dt,ho]=l.useState(),[fo,mo]=l.useState(!1),[po,go]=l.useState(!1),[yo,vo]=l.useState(!1),[Tt,Pt]=l.useState(!1),[Lt,Yt]=l.useState(!1),[To,Ht]=l.useState({}),[Wt,Xt]=l.useState(null),[Ot,Oo]=l.useState(null),[Kt,Eo]=l.useState(null),[jt,Vt]=l.useState(null),Ue=ao(()=>ct.current?.release()),ot=l.useRef(!1),Et=l.useRef(null),$=l.useRef(new Map),Oe=l.useRef(!1),[Mo,Ao]=l.useState(!1),W=l.useRef(null),Pe=l.useRef(null),Fe=l.useRef({handle:()=>{},end:()=>{}}),[Ee,nt]=l.useState(null),[$t,Mt]=l.useState(null),[At,ze]=l.useState(null),[bt,it]=l.useState(null),[bo,Bt]=l.useState(null),[No,Ut]=l.useState(null),rt=l.useRef(null),he=l.useRef(void 0),Ft=e=>{rt.current=e,he.current===void 0&&(he.current=window.requestAnimationFrame(()=>{he.current=void 0,Ut(rt.current)}))},[_o,Le]=l.useState(null),Me=l.useRef(null);Me.current=$t;const Ye=l.useRef(B);Ye.current=B;const Ae=_===!0||_==="hover-only",zt=l.useRef(Ae);zt.current=Ae;const wo=_==="hover-only"?"hover-only":"select",V=l.useMemo(()=>r.detectPlatform(t),[t]),Io=l.useMemo(()=>u||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[u]),Ge=V==="ios"&&N&&N!=="iphone-duo"?N:void 0,be=V==="android"&&Lt?bn:Ge?An[Ge]:Mn[V],ie=pe?.[V],Gt=Ge&&ie?.modelFrames?.[Ge],qt=V==="android"&&Lt?Tt?ie?.tabletFrameLandscape:ie?.tabletFrame:Ge?Tt?Gt?.frameLandscape:Gt?.frame:Tt?ie?.frameLandscape:ie?.frame,Zt=ie?.loadingLogo,qe=!j&&V!=="macos"&&y&&!!qt,le=V==="macos"&&y,Ne=le&&ie?.frame&&ie.screen?{src:ie.frame,screen:ie.screen}:void 0,Nt=l.useRef(null),Ro=le&&Ue.mode==="3d",_e=le&&Ue.shown==="3d";ot.current=_e;const Jt=Ue.choose;l.useEffect(()=>{le||Jt("2d")},[le,Jt]);const C=l.useRef(null),se=e=>C.current?.sendControl(e),st=l.useRef(new Set),Qt=l.useRef(!1);Qt.current=_===!0;const ct=l.useRef(null);ct.current||(ct.current=new an(e=>C.current?.sendControl(e),()=>Qt.current));const we=ct.current;l.useEffect(()=>()=>we.release(),[we]);const Ze=l.useCallback(()=>{for(const e of st.current)C.current?.sendControl(r.createMacKeyMessage(r.MAC_INPUT_ACTION.UP,e));st.current.clear()},[]),_t=(e,n)=>C.current?.sendDuoControl(e,n)??Promise.reject(new Error("Simulator disconnected")),eo=-10,to=(e,n)=>{const i=We();if(!i)return;const o=fe(i,e,n);if(!o)return;const{videoX:c,videoY:h,videoWidth:a,videoHeight:m}=o,p=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_DOWN,eo,a,m,c,h,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);p&&se(p),window.setTimeout(()=>{const b=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_UP,eo,a,m,c,h,0,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);b&&se(b)},60)},Co=(e,n)=>{const i=We();if(!i||n.screen.width<=0||n.screen.height<=0)return;const o=e.frame.x+e.frame.width/2,c=e.frame.y+e.frame.height/2,h=o/n.screen.width*i.actualWidth,a=c/n.screen.height*i.actualHeight,m=i.videoRect.left+i.offsetX+h,p=i.videoRect.top+i.offsetY+a;to(m,p)},at=-1,lt=-2,Ie=-3,He=(e,n,i,o,c,h)=>{const a=r.createTouchControlMessage(e,n,i,o,c,h,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);a&&(r.debugLog("[rc-touch] sendSingleTouch",{action:e,actionName:gt(e),pointerId:n,x:c,y:h,video:{width:i,height:o}}),se(a))},Re=(e,n,i)=>{if(!i)return;const{videoX:o,videoY:c,videoWidth:h,videoHeight:a}=i;let m=null,p=null,b=1;const x=r.AMOTION_EVENT.BUTTON_PRIMARY;switch(n){case"down":e!==Ie&&Fe.current.end(),m=$.current.size===0?r.AMOTION_EVENT.ACTION_DOWN:r.AMOTION_EVENT.ACTION_POINTER_DOWN,p={x:o,y:c},$.current.set(e,p),e===-1&&w.current?.focus();break;case"move":$.current.has(e)&&(m=r.AMOTION_EVENT.ACTION_MOVE,p={x:o,y:c},$.current.set(e,p));break;case"up":case"cancel":$.current.has(e)&&(p=$.current.get(e),$.current.delete(e),n==="cancel"?m=r.AMOTION_EVENT.ACTION_CANCEL:m=$.current.size===0?r.AMOTION_EVENT.ACTION_UP:r.AMOTION_EVENT.ACTION_POINTER_UP);break}if(m!==null&&p!==null){r.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:n,action:m,actionName:gt(m),positionToSend:p,video:{width:h,height:a},altHeld:Oe.current,activePointersAfter:Array.from($.current.entries()).map(([Q,X])=>({id:Q,x:X.x,y:X.y}))});const T=r.createTouchControlMessage(m,e,h,a,p.x,p.y,b,x,x);T&&(r.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:gt(m),byteLength:T.byteLength}),se(T))}else(n==="up"||n==="cancel")&&$.current.delete(e)},wt=e=>{if(Oe.current!==e&&(Oe.current=e,Ao(e),e||nt(null),r.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from($.current.keys())}),V==="ios"&&C.current?.getState().controlReady)){const n=e?r.ANDROID_KEYS.ACTION_DOWN:r.ANDROID_KEYS.ACTION_UP,i=r.createInjectKeycodeMessage(n,r.ANDROID_KEYS.KEYCODE_ALT_LEFT,0,r.ANDROID_KEYS.META_NONE);r.debugLog("[rc-touch][alt] sending Indigo modifier keycode",{action:n,keycode:r.ANDROID_KEYS.KEYCODE_ALT_LEFT}),i&&se(i)}},We=()=>{const e=w.current,n=q.current;if(!e||!n)return null;const i=e.videoWidth,o=e.videoHeight;if(!i||!o)return null;const c=e.getBoundingClientRect(),h=n.getBoundingClientRect(),a=c.width,m=c.height,p=i/o,b=a/m;let x=a,T=m;p>b?T=a/p:x=m*p;const Q=(a-x)/2,X=(m-T)/2;return{videoWidth:i,videoHeight:o,videoRect:c,containerRect:h,actualWidth:x,actualHeight:T,offsetX:Q,offsetY:X}},fe=(e,n,i)=>{const o=n-e.videoRect.left-e.offsetX,c=i-e.videoRect.top-e.offsetY,h=Math.max(0,Math.min(e.actualWidth,o)),a=Math.max(0,Math.min(e.actualHeight,c)),m=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),p=Math.max(0,Math.min(e.videoHeight,a/e.actualHeight*e.videoHeight));return{videoX:m,videoY:p,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},So=(e,n,i)=>{const o=n-e.videoRect.left-e.offsetX,c=i-e.videoRect.top-e.offsetY,h=Math.max(0,Math.min(e.actualWidth,o)),a=Math.max(0,Math.min(e.actualHeight,c)),m=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),p=Math.max(0,Math.min(e.videoHeight,a/e.actualHeight*e.videoHeight)),b=e.videoWidth-m,x=e.videoHeight-p,T=e.videoRect.left+e.offsetX,Q=e.videoRect.top+e.offsetY,X=T-e.containerRect.left+h,z=Q-e.containerRect.top+a,re=T-e.containerRect.left+(e.actualWidth-h),I=Q-e.containerRect.top+(e.actualHeight-a);return{containerX:X,containerY:z,mirrorContainerX:re,mirrorContainerY:I,videoX:m,videoY:p,mirrorVideoX:b,mirrorVideoY:x,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},xo=(e,n,i,o,c,h,a)=>{const m=r.createTwoFingerTouchControlMessage(e,n,i,o,c,h,a);r.debugLog("[rc-touch2] sendTwoFingerMessage (iOS)",{actionName:gt(e),video:{width:n,height:i},p0:{x:o,y:c},p1:{x:h,y:a},byteLength:m.byteLength}),se(m)},Xe=(e,n,i,o,c,h,a,m,p)=>{if(r.debugLog("[rc-touch2] applyTwoFingerEvent",{platform:V,eventType:e,video:{width:n,height:i},p0:{x:o,y:c,id:m},p1:{x:h,y:a,id:p}}),e==="down"&&Fe.current.end(),V==="ios"){const b=e==="down"?r.AMOTION_EVENT.ACTION_DOWN:e==="move"?r.AMOTION_EVENT.ACTION_MOVE:r.AMOTION_EVENT.ACTION_UP;xo(b,n,i,o,c,h,a)}else e==="down"?(He(r.AMOTION_EVENT.ACTION_DOWN,m,n,i,o,c),He(r.AMOTION_EVENT.ACTION_POINTER_DOWN,p,n,i,h,a)):e==="move"?(He(r.AMOTION_EVENT.ACTION_MOVE,m,n,i,o,c),He(r.AMOTION_EVENT.ACTION_MOVE,p,n,i,h,a)):(He(r.AMOTION_EVENT.ACTION_POINTER_UP,p,n,i,h,a),He(r.AMOTION_EVENT.ACTION_UP,m,n,i,o,c))},ko=(e,n,i)=>{if(!Oe.current){Ee!==null&&nt(null);return}const o=So(e,n,i);nt(o)},Do=(e,n,i)=>{const o=Me.current;if(!o||o.screen.width<=0||o.screen.height<=0)return null;const c=n-e.videoRect.left-e.offsetX,h=i-e.videoRect.top-e.offsetY;if(c<0||h<0||c>e.actualWidth||h>e.actualHeight)return null;const a=c/e.actualWidth*o.screen.width,m=h/e.actualHeight*o.screen.height;return r.axElementAtPoint(o,a,m)},Po=e=>({map:(n,i)=>{const o=fe(e,n,i);if(o)return{x:o.videoX,y:o.videoY,width:o.videoWidth,height:o.videoHeight}},contains:(n,i)=>{const o=n-e.videoRect.left-e.offsetX,c=i-e.videoRect.top-e.offsetY;return o>=0&&o<=e.actualWidth&&c>=0&&c<=e.actualHeight},scale:e.actualWidth>0?e.videoWidth/e.actualWidth:1}),ye=e=>{if(j||ot.current)return;e.preventDefault(),e.stopPropagation();const n=We();if((_===!0||_==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(Ft({x:e.clientX,y:e.clientY}),n){const o=Do(n,e.clientX,e.clientY);ze(o?.id??null)}}else e.type==="mouseleave"&&(Ft(null),ze(null));if(_!==!0){if(V==="macos"){if(!n||!C.current?.getState().controlReady)return;if("touches"in e){const a=Array.from(e.touches,m=>({x:m.clientX,y:m.clientY}));we.touch(e.type,a,Po(n))&&w.current?.focus();return}const o=fe(n,e.clientX,e.clientY);if(!o)return;const c=e.type==="mousedown"?r.MAC_INPUT_ACTION.DOWN:e.type==="mouseup"?r.MAC_INPUT_ACTION.UP:r.MAC_INPUT_ACTION.MOVE,h=e.type==="mouseleave"?0:e.buttons;e.type==="mousedown"&&w.current?.focus(),we.pointer(c,{x:o.videoX,y:o.videoY,width:o.videoWidth,height:o.videoHeight},h);return}if(!("touches"in e)&&n&&(e.type==="mousemove"?ko(n,e.clientX,e.clientY):e.type==="mouseleave"&&nt(null)),!(!C.current?.getState().controlReady||!w.current||!n))if("touches"in e){const o=e.touches,c=e.changedTouches;let h;switch(e.type){case"touchstart":h="down";break;case"touchmove":h="move";break;case"touchend":h="up";break;case"touchcancel":h="cancel";break;default:return}if(o.length===2){const a=o[0],m=o[1],p=fe(n,a.clientX,a.clientY),b=fe(n,m.clientX,m.clientY);if(!p||!b)return;W.current?W.current.source==="real-touch"&&(W.current.finger0={x:p.videoX,y:p.videoY},W.current.finger1={x:b.videoX,y:b.videoY},Xe("move",p.videoWidth,p.videoHeight,p.videoX,p.videoY,b.videoX,b.videoY,W.current.pointerId0,W.current.pointerId1)):(W.current={finger0:{x:p.videoX,y:p.videoY},finger1:{x:b.videoX,y:b.videoY},videoSize:{width:p.videoWidth,height:p.videoHeight},source:"real-touch",pointerId0:a.identifier,pointerId1:m.identifier},Xe("down",p.videoWidth,p.videoHeight,p.videoX,p.videoY,b.videoX,b.videoY,a.identifier,m.identifier))}else if(o.length<2&&W.current?.source==="real-touch"){const a=W.current;Xe("up",a.videoSize.width,a.videoSize.height,a.finger0.x,a.finger0.y,a.finger1.x,a.finger1.y,a.pointerId0,a.pointerId1),W.current=null;return}else{if(o.length>2)return;{const a=c[0];if(a){const m=fe(n,a.clientX,a.clientY);Re(a.identifier,h,m)}}}}else{let c=null;const h=W.current?.source==="alt-mouse";switch(e.type){case"mousedown":e.button===0&&(c="down");break;case"mousemove":(h||$.current.has(-1))&&(c="move");break;case"mouseup":e.button===0&&(c="up");break;case"mouseleave":(h||$.current.has(-1))&&(c="up");break}if(c){const a=fe(n,e.clientX,e.clientY);if(!a)return;r.debugLog("[rc-touch][mouse] event",{domType:e.type,eventType:c,button:e.button,buttons:e.buttons,client:{x:e.clientX,y:e.clientY},altHeldRef:Oe.current,inTwoFingerMode:h,geometry:{videoX:a.videoX,videoY:a.videoY,videoWidth:a.videoWidth,videoHeight:a.videoHeight},activePointerIds:Array.from($.current.keys())}),Oe.current||h?Lo(c,a):Re(-1,c,a)}}}},Lo=(e,n)=>{const{videoX:i,videoY:o,videoWidth:c,videoHeight:h}=n,a=c-i,m=h-o;if(e==="down"){W.current={finger0:{x:i,y:o},finger1:{x:a,y:m},videoSize:{width:c,height:h},source:"alt-mouse",pointerId0:at,pointerId1:lt},w.current?.focus(),Xe("down",c,h,i,o,a,m,at,lt);return}if(e==="move"){W.current?.source==="alt-mouse"&&(W.current.finger0={x:i,y:o},W.current.finger1={x:a,y:m},Xe("move",c,h,i,o,a,m,at,lt));return}if(e==="up"||e==="cancel"){const p=W.current;if(p?.source==="alt-mouse"){const{finger0:b,finger1:x,videoSize:T}=p;Xe("up",T.width,T.height,b.x,b.y,x.x,x.y,at,lt),W.current=null}return}},Yo=150,oo=()=>{const e=Pe.current;e&&(window.clearTimeout(e.endTimer),Re(Ie,"up",e.pos),Pe.current=null)},Ho=e=>{if(!C.current?.getState().controlReady||e.ctrlKey)return;if(V==="macos"){if(ot.current)return;const I=We();if(!I)return;const Ce=e.clientX-I.videoRect.left-I.offsetX,me=e.clientY-I.videoRect.top-I.offsetY;if(Ce<0||Ce>I.actualWidth||me<0||me>I.actualHeight)return;const de=fe(I,e.clientX,e.clientY);if(!de)return;e.preventDefault();const je=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?I.actualHeight:1;we.scroll({x:de.videoX,y:de.videoY,width:de.videoWidth,height:de.videoHeight},e.deltaX*je,e.deltaY*je);return}if(Oe.current||W.current)return;const n=$.current.size;if(n>1||n===1&&!$.current.has(Ie))return;const i=We();if(!i)return;const o=e.clientX-i.videoRect.left-i.offsetX,c=e.clientY-i.videoRect.top-i.offsetY;if(o<0||o>i.actualWidth||c<0||c>i.actualHeight)return;const h=fe(i,e.clientX,e.clientY);if(!h)return;e.preventDefault();const a=(e.deltaMode===1?16:e.deltaMode===2?i.actualWidth:1)*(i.videoWidth/i.actualWidth),m=(e.deltaMode===1?16:e.deltaMode===2?i.actualHeight:1)*(i.videoHeight/i.actualHeight),p=-e.deltaX*a,b=-e.deltaY*m,x=I=>{window.clearTimeout(I.endTimer),I.endTimer=window.setTimeout(oo,Yo)};if(p===0&&b===0){Pe.current&&x(Pe.current);return}const T=()=>({videoWidth:h.videoWidth,videoHeight:h.videoHeight,videoX:Math.abs(p)>Math.abs(b)?Math.min(Math.max(h.videoX,h.videoWidth*.2),h.videoWidth*.8):h.videoX,videoY:Math.abs(b)>=Math.abs(p)?Math.min(Math.max(h.videoY,h.videoHeight*.2),h.videoHeight*.8):h.videoY}),Q=I=>({...I,videoX:Math.min(Math.max(I.videoX+p,0),I.videoWidth),videoY:Math.min(Math.max(I.videoY+b,0),I.videoHeight)});let X=Pe.current;if(X)window.clearTimeout(X.endTimer);else{const I=T();Re(Ie,"down",I),X={pos:I,endTimer:0},Pe.current=X}let z=X.pos,re=Q(z);re.videoX===z.videoX&&re.videoY===z.videoY&&(Re(Ie,"up",z),z=T(),Re(Ie,"down",z),re=Q(z)),Re(Ie,"move",re),X.pos=re,x(X)};l.useEffect(()=>{Fe.current={handle:Ho,end:oo}}),l.useEffect(()=>{const e=q.current;if(!e)return;const n=i=>Fe.current.handle(i);return e.addEventListener("wheel",n,{passive:!1}),()=>{Fe.current.end(),e.removeEventListener("wheel",n)}},[]),l.useEffect(()=>{const e=c=>{c.key==="Alt"&&wt(!0)},n=c=>{c.key==="Alt"&&wt(!1)},i=()=>{wt(!1),Ze()},o=()=>{document.hidden&&Ze()};return window.addEventListener("keydown",e,!0),window.addEventListener("keyup",n,!0),window.addEventListener("blur",i),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("keydown",e,!0),window.removeEventListener("keyup",n,!0),window.removeEventListener("blur",i),document.removeEventListener("visibilitychange",o)}},[Ze]);const Ke=e=>{e.preventDefault(),e.stopPropagation();const n=document.activeElement===w.current||(j||ot.current)&&document.activeElement===e.currentTarget;if(r.debugLog("Keyboard event:",{type:e.type,key:e.key,keyCode:e.keyCode,code:e.code,target:e.target.tagName,focused:n}),!n){r.debugWarn("Simulator input not focused, skipping keyboard event");return}if(!C.current?.getState().controlReady){r.debugWarn("Data channel not ready for keyboard event:",C.current?.getState().connection);return}if(V==="macos"){if(e.type==="keydown"&&e.repeat)return;const o=r.macKeyCodeFor(e.code);if(o===void 0){r.debugLog(`Ignoring unmapped key for macOS: code=${e.code}`);return}e.type==="keydown"?st.current.add(o):st.current.delete(o),se(r.createMacKeyMessage(e.type==="keydown"?r.MAC_INPUT_ACTION.DOWN:r.MAC_INPUT_ACTION.UP,o));return}if(e.type==="keydown"){if(e.key.toLowerCase()==="v"&&(e.metaKey||e.ctrlKey)){r.debugLog("Paste shortcut detected"),navigator.clipboard.readText().then(o=>{if(o){r.debugLog("Pasting text via SET_CLIPBOARD:",o.substring(0,20)+(o.length>20?"...":""));const c=r.createSetClipboardMessage(o,!0);se(c)}}).catch(o=>{console.error("Failed to read clipboard contents: ",o)});return}if(e.key.toLowerCase()==="m"&&(e.metaKey||e.ctrlKey)){r.debugLog("Menu shortcut detected");const o=r.createInjectKeycodeMessage(r.ANDROID_KEYS.ACTION_DOWN,r.ANDROID_KEYS.MENU,0,r.ANDROID_KEYS.META_NONE);se(o);const c=r.createInjectKeycodeMessage(r.ANDROID_KEYS.ACTION_UP,r.ANDROID_KEYS.MENU,0,r.ANDROID_KEYS.META_NONE);se(c);return}}const i=Nn(e);if(i){const{keycode:o,metaState:c}=i,h=e.type==="keydown"?r.ANDROID_KEYS.ACTION_DOWN:r.ANDROID_KEYS.ACTION_UP;r.debugLog(`Sending Keycode: key=${e.key}, code=${o}, action=${h}, meta=${c}`);const a=r.createInjectKeycodeMessage(h,o,0,c);se(a)}else r.debugLog(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`)},Wo=e=>{e.stopPropagation(),C.current?.reconnect()},J=l.useRef({onAxSnapshotChange:oe,onAxStatusChange:D,onCameraDemandChange:L,onCameraStats:P,onMicrophoneStateChange:ne,onTrace:H,onTerminated:te,onConnectionStateChange:ae,onPlaybackStats:K});J.current={onAxSnapshotChange:oe,onAxStatusChange:D,onCameraDemandChange:L,onCameraStats:P,onMicrophoneStateChange:ne,onTrace:H,onTerminated:te,onConnectionStateChange:ae,onPlaybackStats:K};const It=!!H;l.useEffect(()=>{Et.current=null,Pt(!1),Yt(!1),Ht({}),Xt(null)},[t,Te]),l.useEffect(()=>{let e=!0;Me.current!==null&&(Me.current=null,Mt(null),r.safeInvoke("onAxSnapshotChange",J.current.onAxSnapshotChange,null));const n=r.createDeviceStream({url:t,token:s,sessionId:Io,watchOnly:F,deviceModel:Te,autoReconnect:R,jitterBufferTargetMs:Y,openUrl:v,inspectMode:_,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:A,microphoneEnabled:U,onStateChange:o=>{(o.videoReady||o.connection==="idle"||o.connection==="connecting"||o.connection==="reconnecting")&&mo(o.videoReady),go(o.connection==="failed"),vo(o.connection==="terminated"),Z(o.duo),uo(o.duoState),ho(o.duoError)},onAxSnapshotChange:o=>{e&&(Mt(c=>r.axSnapshotsEqual(c,o)?c:o),J.current.onAxSnapshotChange?.(o))},onAxStatusChange:(...o)=>J.current.onAxStatusChange?.(...o),onCameraDemandChange:(...o)=>J.current.onCameraDemandChange?.(...o),onCameraStats:P?(...o)=>J.current.onCameraStats?.(...o):void 0,onMicrophoneStateChange:(...o)=>J.current.onMicrophoneStateChange?.(...o),onTrace:It?(...o)=>J.current.onTrace?.(...o):void 0,onTerminated:()=>J.current.onTerminated?.(),onConnectionStateChange:(...o)=>J.current.onConnectionStateChange?.(...o),onPlaybackStats:K?(...o)=>J.current.onPlaybackStats?.(...o):void 0});C.current=n;const i=w.current?n.attachVideo(w.current):void 0;return n.start(),()=>{e=!1,n.dispose(),i?.(),C.current=null}},[t,u,Te,It,F]),l.useEffect(()=>{if(j&&De.current)return C.current?.attachVideo(De.current,"inner")},[j,t,u,Te,It,F]),l.useEffect(()=>{C.current?.updateOptions({token:s,openUrl:v,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:A,autoReconnect:R,jitterBufferTargetMs:Y,microphoneEnabled:U,inspectMode:_,onPlaybackStats:K?(...e)=>J.current.onPlaybackStats?.(...e):void 0,onCameraStats:P?(...e)=>J.current.onCameraStats?.(...e):void 0})},[s,R,Y,U,_,!!K,!!P,v,f,O,A]);const Je=()=>{if(!zt.current)return;const e=We();if(!e){Bt(null);return}const n={left:e.videoRect.left-e.containerRect.left+e.offsetX,top:e.videoRect.top-e.containerRect.top+e.offsetY,width:e.actualWidth,height:e.actualHeight};Bt(i=>i&&i.left===n.left&&i.top===n.top&&i.width===n.width&&i.height===n.height?i:n)};l.useEffect(()=>{const e=w.current,n=ge.current,i=q.current;if(!e)return;const o=x=>Ht(T=>vt(T,x)?T:x),c=x=>Xt(T=>T&&x&&vt(T,x)?T:x),h=x=>Oo(T=>T&&x&&vt(T,x)?T:x),a=()=>{const x=e.videoWidth>0&&e.videoHeight>0;x&&(Et.current={width:e.videoWidth,height:e.videoHeight});const T=Et.current,Q=T?`${T.width} / ${T.height}`:void 0,X=Nt.current;if(Ne&&i){if(Vt(T?T.width/T.height:Ct),!X?.naturalWidth)return;const Se=X.naturalWidth/X.naturalHeight,dt=i.clientHeight-yt,xe=i.clientHeight>0?Math.min(i.clientWidth,dt*Se):i.clientWidth;if(xe<=0)return;const Ve=xe/Se,ve=i.clientHeight>0?yt/2:0,{screen:ce}=Ne,ut=ce.notch??0,$e=ce.left*xe,Be=ce.top*Ve,ht=ce.width*xe,ft=ce.height*Ve,io=T?T.width/T.height:Ct,mt=Math.min(ht,ft*io),Rt=mt/io,jo=$e+(ht-mt)/2,Vo=ut>0?Be:Be+(ft-Rt)/2,ro=(Qe,pt,$o,Bo)=>`translate(calc(-50% + ${Qe+$o/2-xe/2}px), calc(-50% + ${pt+Bo/2-Ve/2+ve}px))`;o({width:`${mt}px`,height:`${Rt}px`,transform:ro(jo,Vo,mt,Rt)}),Eo(Qe=>{const pt={width:`${ht}px`,height:`${ft}px`,transform:ro($e,Be,ht,ft)};return Qe&&vt(Qe,pt)?Qe:pt}),h({width:`${xe}px`,height:`${Ve}px`,transform:ve?`translateY(${ve}px)`:void 0}),c(null),Je();return}if(le&&i){const Se=T?T.width/T.height:Ct,dt=i.clientWidth*100/et,Ve=(i.clientHeight-yt)/(1/Se+xt/100),ve=i.clientHeight>0?Math.min(dt,Ve):dt;if(ve<=0)return;const ce=ve/100,ut=ve/Se,$e=i.clientHeight>0?yt/2:0,Be=`${ce*ee.screenRadius}px`;o({aspectRatio:`${Se}`,width:`${ve}px`,height:`${ut}px`,borderRadius:`${Be} ${Be} 0 0`,transform:`translate(-50%, calc(-50% - ${ce*Fo-$e}px))`}),h({width:`${ce*et}px`,height:`${ut+ce*xt}px`,transform:$e?`translateY(${$e}px)`:void 0,"--rc-macbook-unit":`${ce}px`}),Vt(Se),c(null),Je();return}if(h(null),!qe||!n){o(!x&&T?{aspectRatio:Q,contain:"size",containIntrinsicSize:`${T.width}px ${T.height}px`}:{}),c(null),Je();return}const z=n.clientWidth,re=n.clientHeight;if(z===0||re===0)return;const I=T?T.width>T.height:!1;Pt(I),Yt(V==="android"&&!!T&&En(T.width,T.height));const Ce=I?be.videoPosition.landscape:be.videoPosition.portrait;let me={aspectRatio:Q};Ce.heightMultiplier?(me.height=`${re*Ce.heightMultiplier}px`,me.width="auto"):Ce.widthMultiplier&&(me.width=`${z*Ce.widthMultiplier}px`,me.height="auto"),me.borderRadius=`${I?re*be.videoBorderRadiusMultiplier:z*be.videoBorderRadiusMultiplier}px`,o(me);const de=be.homeButton,je=I?z:re,no=`calc(50% + ${je*(de?.offset??0)}px)`;c(de?{width:`${je*de.diameter}px`,height:`${je*de.diameter}px`,left:I?no:"50%",top:I?"50%":no}:null),Je()},m=new ResizeObserver(()=>{a()});n&&m.observe(n),m.observe(e),i&&m.observe(i),n&&n.addEventListener("load",a);const p=Nt.current;p?.addEventListener("load",a),e.addEventListener("loadedmetadata",a),e.addEventListener("resize",a);const b=()=>C.current?.bumpActivity();return e.addEventListener("resize",b),a(),()=>{m.disconnect(),e.removeEventListener("loadedmetadata",a),e.removeEventListener("resize",a),e.removeEventListener("resize",b),n&&n.removeEventListener("load",a),p?.removeEventListener("load",a)}},[be,qe,le,Ne?.src,_e,t,N]),l.useEffect(()=>{Ae?Je():(Mt(null),ze(null),it(null),Ut(null),Le(null),rt.current=null,he.current!==void 0&&(window.cancelAnimationFrame(he.current),he.current=void 0))},[Ae]),l.useEffect(()=>()=>{he.current!==void 0&&(window.cancelAnimationFrame(he.current),he.current=void 0)},[]),l.useEffect(()=>{if(!Ae)return;const e=n=>{n.key==="Escape"&&(bt||At)&&(it(null),ze(null),Le(null),r.safeInvoke("onInspectSelectionChange",Ye.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Ae,bt,At]);const Xo=()=>{w.current&&w.current.focus()};l.useImperativeHandle(G,()=>({openUrl:e=>C.current?.openUrl(e),sendKeyEvent:e=>C.current?.sendKeyEvent(e),screenshot:e=>C.current?.screenshot(e)??Promise.reject(new Error("Simulator disconnected")),terminateApp:e=>C.current?.terminateApp(e)??Promise.reject(new Error("Simulator disconnected")),reconnect:()=>C.current?.reconnect(),refreshAxTree:()=>C.current?.refreshAxTree()??Promise.reject(new Error("Simulator disconnected")),getAxSnapshot:()=>C.current?.getAxSnapshot()??null,setInspectHighlight:e=>{ze(e?.id??null)},setInspectSelection:e=>{it(e?.id??null),Le(e?rt.current:null);const n=Me.current;e&&n?r.safeInvoke("onInspectSelectionChange",Ye.current,{element:e,snapshot:n}):r.safeInvoke("onInspectSelectionChange",Ye.current,null)},getAxStatus:()=>C.current?.getAxStatus()??"idle"}));const Ko=Mo&&Ee!==null;return g.jsxs("div",{ref:q,className:["rc-container",d].filter(Boolean).join(" "),style:{touchAction:"none"},onMouseDown:ye,onMouseMove:ye,onMouseUp:ye,onMouseLeave:ye,onTouchStart:ye,onTouchMove:ye,onTouchEnd:ye,onTouchCancel:ye,onContextMenu:V==="macos"?e=>e.preventDefault():void 0,children:[Ko&&Ee&&g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"rc-touch-indicator",style:{left:`${Ee.containerX}px`,top:`${Ee.containerY}px`}}),g.jsx("div",{className:"rc-touch-indicator",style:{left:`${Ee.mirrorContainerX}px`,top:`${Ee.mirrorContainerY}px`}})]}),qe&&g.jsx("img",{ref:ge,src:qt,alt:"",className:V==="ios"?"rc-phone-frame rc-phone-frame-ios":"rc-phone-frame",draggable:!1}),Ne&&!_e&&Kt&&g.jsx("div",{className:"rc-macbook-screen",style:Kt,"aria-hidden":"true"}),Ne&&!_e&&g.jsx("img",{ref:Nt,src:Ne.src,alt:"",className:"rc-macbook-image",style:Ot??{visibility:"hidden"},draggable:!1}),le&&!Ne&&Ot&&!_e&&g.jsxs("div",{className:"rc-macbook",style:Ot,"aria-hidden":"true",children:[g.jsx("div",{className:"rc-macbook-lid",children:g.jsx("div",{className:"rc-macbook-camera"})}),g.jsx("div",{className:"rc-macbook-base"})]}),qe&&Wt&&!F&&g.jsx("button",{type:"button",className:"rc-home-button","aria-label":"Home",title:"Home",style:Wt,onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),onTouchEnd:e=>{e.stopPropagation(),e.preventDefault(),C.current?.pressButton("home")},onClick:e=>{e.stopPropagation(),C.current?.pressButton("home")}}),g.jsx("video",{ref:w,className:["rc-video",!qe&&!le&&"rc-video-frameless",!fo&&(V==="macos"?"rc-video-loading-desktop":"rc-video-loading")].filter(Boolean).join(" "),style:{...To,...j||_e?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...Zt?{backgroundImage:`url("${Zt}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:be.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:j||_e?-1:0,onKeyDown:Ke,onKeyUp:Ke,onClick:Xo,onFocus:()=>{w.current&&(w.current.style.outline="none")},onBlur:()=>{w.current&&(w.current.style.outline="none"),Ze()}}),Ro&&jt&&g.jsx(l.Suspense,{fallback:null,children:g.jsx(On,{video:w.current,aspect:jt,model:k??ie?.model,animateLid:M,watchOnly:F,onReady:Ue.onReady,pointer:(e,n,i,o)=>{const c=w.current;!c?.videoWidth||!C.current?.getState().controlReady||we.pointer(e==="down"?r.MAC_INPUT_ACTION.DOWN:e==="up"?r.MAC_INPUT_ACTION.UP:r.MAC_INPUT_ACTION.MOVE,{x:n*c.videoWidth,y:i*c.videoHeight,width:c.videoWidth,height:c.videoHeight},o)},scroll:(e,n,i,o)=>{const c=w.current;!c?.videoWidth||!C.current?.getState().controlReady||we.scroll({x:e*c.videoWidth,y:n*c.videoHeight,width:c.videoWidth,height:c.videoHeight},i,o)},onKeyDown:Ke,onKeyUp:Ke,onBlur:Ze})}),le&&g.jsx(lo,{view:Ue,label:"MacBook rendering"}),j&&g.jsx("video",{ref:De,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),j&&kt&&g.jsx(l.Suspense,{fallback:g.jsx("div",{children:"Loading iPhone Duo…"}),children:g.jsx(Tn,{watchOnly:F,showFrame:y,model:S??ie?.model,outer:w.current,inner:De.current,state:kt,setAngle:e=>_t("setHingeAngle",{angleDegrees:e}),setOrientation:e=>_t("setDuoOrientation",{orientation:e}),button:(e,n)=>_t("performActions",{actions:[{type:n?"buttonDown":"buttonUp",button:e}]}),touch:(e,n,i,o)=>{C.current?.sendDisplayTouch(e,n,i,o)},onKeyDown:Ke,onKeyUp:Ke})}),j&&Dt&&g.jsx("div",{role:"alert",className:"rc-duo-error",children:Dt}),!j&&Ae&&g.jsx(yn,{snapshot:$t,geometry:bo,highlightedId:At,selectedId:bt,mode:wo,cursorPosition:No,frozenCursorPosition:_o,onSelectChange:(e,n)=>{it(e?.id??null),e&&n?Le(n):e||Le(null);const i=Me.current;e&&i?r.safeInvoke("onInspectSelectionChange",Ye.current,{element:e,snapshot:i}):r.safeInvoke("onInspectSelectionChange",Ye.current,null)},onTapElement:F?void 0:((e,n)=>{if(n){to(n.x,n.y);return}const i=Me.current;i&&Co(e,i)})}),yo?g.jsxs("div",{className:"rc-terminated",role:"status",children:[g.jsx("div",{className:"rc-terminated-title",children:"Instance terminated"}),g.jsx("div",{className:"rc-terminated-message",children:"This instance no longer exists and can't be reconnected."})]}):po&&g.jsx("button",{type:"button",className:"rc-retry-button",onClick:Wo,children:"Retry"})]})});exports.DeviceModeToggle=lo;exports.MACBOOK_LID_MAX_DEGREES=Zo;exports.MACBOOK_LID_OPENING_MS=Qo;exports.MACBOOK_LID_OPEN_DEGREES=Jo;exports.MACBOOK_VERTEX_FLOATS=zo;exports.RemoteControl=_n;exports.lidEase=tn;exports.lidRotation=en;exports.macbookMeshes=on;exports.streamFit=nn;exports.streamPoint=rn;exports.useDeviceView=ao;