@limrun/ui 0.22.2 → 0.22.3

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.
@@ -0,0 +1 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limrun/ui",
3
- "version": "0.22.2",
3
+ "version": "0.22.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,3 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),f=require("react"),c=require("./remote-control-DfhrxDXL.js"),r=require("./model-source-D3_k9qRK.js"),N={front:{yaw:0,pitch:.1,label:"Front"},desk:{yaw:-.5,pitch:.42,label:"Desk"},side:{yaw:-1.15,pitch:.16,label:"Side"}},xe=28,Ne={environment:.45,hemisphere:1,key:{intensity:2.2,position:[-120,220,260]},rim:{intensity:.7,position:[220,40,-220]}};function je(v,j){const n=r.DoubleSide;switch(v){case"screen":return j;case"shell":return new r.MeshStandardMaterial({color:3421498,metalness:.9,roughness:.34,side:n});case"glass":return new r.MeshPhysicalMaterial({color:328966,roughness:.06,clearcoat:1,side:n});case"camera":return new r.MeshStandardMaterial({color:790549,roughness:.2,side:n});case"well":return new r.MeshStandardMaterial({color:1052690,roughness:.9,side:n});case"keys":return new r.MeshStandardMaterial({color:723725,roughness:.7,side:n});case"trackpad":return new r.MeshPhysicalMaterial({color:2895153,metalness:.4,roughness:.3,clearcoat:.6,side:n});case"scoop":return new r.MeshStandardMaterial({color:1579035,metalness:.6,roughness:.5,side:n})}}const Ge={glass:1,camera:2,screen:2,well:1,keys:2,trackpad:1,scoop:1};function Fe(v){const j=f.useRef(null),n=f.useRef(v);n.current=v;const[re,z]=f.useState(),[ke,Se]=f.useState(!1),oe=f.useRef(!1),{view:ne,viewRef:$,chooseView:De,locked:x,lockedRef:_e,setLocked:Ae,orbit:se,drag:Be}=r.useStageView("front"),P=f.useRef(()=>{}),k=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),p=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),[G,Z]=f.useState(c.MACBOOK_LID_OPEN_DEGREES),F=f.useRef(void 0),ie=f.useId(),ce=o=>{const u=p.current;k.current=o,F.current={from:u,to:o,start:performance.now(),duration:c.MACBOOK_LID_OPENING_MS*Math.abs(o-u)/c.MACBOOK_LID_OPEN_DEGREES},P.current()};return f.useEffect(()=>P.current(),[ne,x]),f.useEffect(()=>{const o=j.current,u=v.video;if(!o||!u)return;const ae=()=>{Se(!0),n.current.onReady?.()};z(void 0);const S=new r.PerspectiveCamera(xe,1,10,4e3);let J=1;const K=r.createDeviceStage({container:o,videos:[u],maxPixelRatio:2,lighting:Ne,resize:(e,t)=>{J=e/t,S.aspect=J,S.updateProjectionMatrix()},frame:(e,t)=>Ie(e,t)});if(!K){z("3D rendering is unavailable in this browser. Enable WebGL to use the 3D MacBook."),ae();return}const{renderer:T,scene:le,invalidate:C}=K;let U=!1;const y=new r.VideoTexture(u);y.colorSpace=r.SRGBColorSpace,y.minFilter=r.LinearFilter,y.magFilter=r.LinearFilter,y.anisotropy=T.capabilities.getMaxAnisotropy();const D=new r.MeshBasicMaterial({map:y,toneMapped:!1,side:r.DoubleSide}),de={value:!1};D.onBeforeCompile=e=>{e.uniforms.fillAbove=de,e.fragmentShader=`uniform bool fillAbove;
2
- ${e.fragmentShader}`.replace("#include <map_fragment>",`#include <map_fragment>
3
- if (vMapUv.x < 0.0 || vMapUv.x > 1.0 || vMapUv.y < 0.0 || (vMapUv.y > 1.0 && !fillAbove)) diffuseColor.rgb = vec3(0.0);`)},D.customProgramCacheKey=()=>"macbook-fitted-screen";let I=n.current.aspect,Q=0,_=c.streamFit(I,I);const Re=()=>{const e=u.videoWidth&&u.videoHeight?u.videoWidth/u.videoHeight:I;_=c.streamFit(e,I,Q),y.repeat.set(_.repeat[0],_.repeat[1]),y.offset.set(_.offset[0],_.offset[1])},g=new r.Group,E=new r.Group,h=new r.Group;h.rotation.x=c.lidRotation(p.current),E.add(h),g.add(E),le.add(g);const ue=[D],Y=[];let X;for(const e of c.macbookMeshes(n.current.aspect)){const t=new r.BufferGeometry,a=new r.InterleavedBuffer(e.vertices,c.MACBOOK_VERTEX_FLOATS);t.setAttribute("position",new r.InterleavedBufferAttribute(a,3,0)),t.setAttribute("normal",new r.InterleavedBufferAttribute(a,3,3)),t.setAttribute("uv",new r.InterleavedBufferAttribute(a,2,6));const s=je(e.kind,D),d=Ge[e.kind];d&&(s.polygonOffset=!0,s.polygonOffsetFactor=-d,s.polygonOffsetUnits=-d);const w=new r.Mesh(t,s);e.kind==="screen"&&(X=w),(e.part==="lid"?h:E).add(w),Y.push(t),s!==D&&Y.push(s)}const fe=new r.Box3,me=e=>{const t=h.rotation.x;return h.rotation.x=c.lidRotation(c.MACBOOK_LID_OPEN_DEGREES),e.updateMatrixWorld(!0),fe.setFromObject(e),h.rotation.x=t,fe},pe=()=>{g.rotation.set(0,0,0),E.position.set(0,0,0),E.position.copy(me(g).getCenter(new r.Vector3)).negate()};pe();const Pe=!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;let ee=!1;const he=()=>{g.visible=!0,!oe.current&&n.current.animateLid!==!1&&!Pe&&(p.current=0,h.rotation.x=c.lidRotation(0),Z(0),ce(c.MACBOOK_LID_OPEN_DEGREES)),oe.current=!0,ee=!0,C()},Ce=async e=>{const{GLTFLoader:t}=await Promise.resolve().then(()=>require("./GLTFLoader-CfPNHfJQ.js")),{scene:a}=await r.loadModel(new t,e),s=[];if(a.traverse(l=>{if(l instanceof r.Mesh){s.push(l.geometry);for(const Le of Array.isArray(l.material)?l.material:[l.material]){s.push(Le);for(const Oe of Object.values(Le))Oe instanceof r.Texture&&s.push(Oe)}}}),U){for(const l of s)l.dispose();return}ue.push(...s);const d=a.getObjectByName("macbook-base"),w=a.getObjectByName("macbook-lid"),M=a.getObjectByName("macbook-screen");if(!d||!w||!(M instanceof r.Mesh))throw new Error("it has no macbook-base, macbook-lid or macbook-screen");for(const l of[...E.children])l!==h&&E.remove(l);h.clear(),E.add(d);for(const l of[...w.children])h.add(l);M.material=D,X=M;const R=M.userData.aspect;typeof R=="number"&&R>0&&(I=R);const b=M.userData.notch;typeof b=="number"&&b>=0&&b<.5&&(Q=b),de.value=Q>0;for(const l of Y.splice(0))l.dispose();pe()},te=n.current.model;te&&(g.visible=!1,Ce(te).catch(e=>{U||z(`The MacBook model could not load: ${e instanceof Error?e.message:e}`)}).finally(()=>{U||he()}));const V=new r.Vector3;let O=0;const ve=new r.Raycaster,we=new r.Vector2;let i,A=N[$.current].yaw,B=N[$.current].pitch;P.current=C;const W=e=>{if(!X)return;const t=T.domElement.getBoundingClientRect();we.set((e.clientX-t.left)/t.width*2-1,1-(e.clientY-t.top)/t.height*2),ve.setFromCamera(we,S);const a=ve.intersectObject(E,!0)[0],s=a?.object===X?a.uv:void 0;return s&&c.streamPoint(s.x,s.y,_)},Me=e=>{if(C(),i)return;const t=n.current.watchOnly||e.altKey?void 0:W(e);!t&&(_e.current||e.button!==0)||(o.focus({preventScroll:!0}),o.setPointerCapture(e.pointerId),i={pointer:e.pointerId,kind:t?"screen":"orbit",clientX:e.clientX,clientY:e.clientY,x:t?.x??0,y:t?.y??0},t&&n.current.pointer("down",t.x,t.y,e.buttons))},be=e=>{if(C(),!i){const t=n.current.watchOnly?void 0:W(e);T.domElement.style.cursor=t?"none":"",t&&n.current.pointer("move",t.x,t.y,0);return}if(i.pointer===e.pointerId){if(i.kind==="screen"){const t=W(e);t&&(i.x=t.x,i.y=t.y),n.current.pointer("move",i.x,i.y,e.buttons)}else Be(e.clientX-i.clientX,e.clientY-i.clientY,1.2);i.clientX=e.clientX,i.clientY=e.clientY}},L=e=>{C(),!(!i||e&&i.pointer!==e.pointerId)&&(i.kind==="screen"&&n.current.pointer("up",i.x,i.y,e?.buttons??0),i=void 0)},Ee=e=>{if(n.current.watchOnly||e.ctrlKey)return;const t=W(e);if(!t)return;e.preventDefault();const a=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?o.clientHeight:1;n.current.scroll(t.x,t.y,e.deltaX*a,e.deltaY*a)},q=e=>e.stopPropagation(),ye=["mousedown","mousemove","mouseup","touchstart","touchmove","touchend","touchcancel"];for(const e of ye)o.addEventListener(e,q);const ge=e=>e.preventDefault(),H=()=>{L(),n.current.onBlur()};o.addEventListener("pointerdown",Me),o.addEventListener("pointermove",be),o.addEventListener("pointerup",L),o.addEventListener("pointercancel",L),o.addEventListener("lostpointercapture",L),o.addEventListener("wheel",Ee,{passive:!1}),o.addEventListener("wheel",q),o.addEventListener("contextmenu",ge),o.addEventListener("focusout",H),window.addEventListener("blur",H);const Ie=(e,t)=>{const a=N[$.current];let s=!1;const d=F.current;if(d){const l=d.duration>0?(e-d.start)/d.duration:1;p.current=d.from+(d.to-d.from)*c.lidEase(l),l>=1?F.current=void 0:s=!0,Z(p.current)}else p.current!==k.current&&(p.current=r.MathUtils.damp(p.current,k.current,14,t),Math.abs(p.current-k.current)<.05?p.current=k.current:s=!0);h.rotation.x=c.lidRotation(p.current);const w=a.yaw+se.yaw,M=a.pitch+se.pitch;A=r.MathUtils.damp(A,w,10,t),B=r.MathUtils.damp(B,M,10,t),Math.abs(A-w)<5e-4&&(A=w),Math.abs(B-M)<5e-4&&(B=M),Re(),g.rotation.set(B,A,0,"XYZ"),me(g).getSize(V);const R=Math.tan(r.MathUtils.degToRad(xe/2)),b=Math.max(V.y/2/R,V.x/2/(R*J))*1.12+V.z/2;return O=O?r.MathUtils.damp(O,b,10,t):b,Math.abs(O-b)<.01&&(O=b),S.position.set(0,0,O),S.lookAt(0,0,0),T.render(le,S),ee&&(ee=!1,ae()),s||A!==w||B!==M||O!==b};return K.start(),te||he(),()=>{U=!0,P.current=()=>{},L();for(const e of ye)o.removeEventListener(e,q);o.removeEventListener("pointerdown",Me),o.removeEventListener("pointermove",be),o.removeEventListener("pointerup",L),o.removeEventListener("pointercancel",L),o.removeEventListener("lostpointercapture",L),o.removeEventListener("wheel",Ee),o.removeEventListener("wheel",q),o.removeEventListener("contextmenu",ge),o.removeEventListener("focusout",H),window.removeEventListener("blur",H);for(const e of[...ue,...Y])e.dispose();y.dispose(),K.dispose()}},[v.video,v.aspect,v.model]),m.jsxs("div",{className:"rc-duo rc-macbook-3d",style:ke?void 0:{visibility:"hidden"},children:[m.jsx("div",{ref:j,className:"rc-duo-stage","data-position-locked":x,tabIndex:0,role:"application","aria-label":"MacBook running macOS. Use the screen to control the guest. Drag around the MacBook to turn it when position is unlocked.",onKeyDown:v.onKeyDown,onKeyUp:v.onKeyUp}),m.jsxs("div",{className:"rc-duo-controls",onPointerDown:o=>o.stopPropagation(),children:[m.jsxs("div",{className:"rc-duo-hinge",children:[m.jsx("button",{type:"button",className:"rc-duo-fold",onClick:()=>ce(G<45?c.MACBOOK_LID_OPEN_DEGREES:0),children:G<45?"Open":"Close"}),m.jsx("label",{htmlFor:ie,children:"Lid"}),m.jsx("input",{id:ie,type:"range",min:0,max:c.MACBOOK_LID_MAX_DEGREES,step:1,value:Math.round(G),onChange:o=>{const u=Number(o.target.value);F.current=void 0,k.current=u,Z(u),P.current()}}),m.jsxs("output",{children:[Math.round(G),"°"]})]}),m.jsxs("div",{className:"rc-duo-views",children:[Object.keys(N).map(o=>m.jsx("button",{type:"button","aria-pressed":ne===o,onClick:()=>{De(o)},children:N[o].label},o)),m.jsx("button",{type:"button",className:"rc-duo-lock","aria-pressed":x,title:x?"Position is locked. The screen still controls macOS.":"Drag around the MacBook to turn it. Alt-drag turns it from the screen.",onClick:()=>Ae(!x),children:x?"Position locked":"Lock position"})]})]}),re&&m.jsx("div",{role:"alert",className:"rc-duo-error",children:re})]})}exports.default=Fe;
@@ -1 +0,0 @@
1
- "use strict";require('./index.css');const g=require("react/jsx-runtime"),r=require("./core-BCBQrYsk.js"),l=require("react"),Qo=require("react-dom"),te={sideBezel:1.7,topBezel:2.4,chin:2.4,baseHeight:2.2,baseOverhang:4,screenRadius:.9,lidThickness:.7},kt=100+2*te.sideBezel,it=kt+2*te.baseOverhang,Dt=te.topBezel+te.chin+te.baseHeight,en=(Dt-2*te.topBezel)/2,tn=8;function on(d){const t=100/d,s=t+te.topBezel+te.chin;return{screenHeight:t,lidHeight:s,depth:s}}const nn=Math.PI/2,rn=135,sn=100,cn=2400;function an(d){return nn-d*Math.PI/180}function ln(d){const t=Math.max(0,Math.min(1,d));return 1-Math.pow(1-t,3)}function Ye(d,t,s,u=6){const v=[],A=[[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[p,E,M,x]of A)for(let k=0;k<=u;k++){const R=x+k*Math.PI/2/u;v.push({x:p+M*Math.cos(R),y:E+M*Math.sin(R),nx:Math.cos(R),ny:Math.sin(R)})}return v}function dn(d){const{screenHeight:t,lidHeight:s,depth:u}=on(d),v=[],A=(m,T,O)=>v.push({part:m,kind:T,vertices:new Float32Array(O)}),p=(m,T,O,L,P)=>{const Y=O.map(Z=>Z.x),U=O.map(Z=>Z.y),[ie,q,ue,F]=[Math.min(...Y),Math.max(...Y),Math.min(...U),Math.max(...U)],G=(ie+q)/2,N=(ue+F)/2,be=(Z,j)=>[...L(Z,j),...P,(Z-ie)/(q-ie||1),(j-ue)/(F-ue||1)],rt=[];for(let Z=0;Z<O.length;Z++){const j=O[Z],Me=O[(Z+1)%O.length];for(const We of[be(G,N),be(j.x,j.y),be(Me.x,Me.y)])rt.push(...We)}A(m,T,rt)},E=(m,T,O,L,P,Y,U)=>{const ie=[];for(let q=0;q<O.length;q++){const ue=O[q],F=O[(q+1)%O.length],G=(N,be)=>[...L(N.x,N.y,be),...P(N.nx,N.ny),0,0];for(const N of[G(ue,Y),G(F,Y),G(F,U),G(ue,Y),G(F,U),G(ue,U)])ie.push(...N)}A(m,T,ie)},M=Ye(kt,s,{top:2.2,bottom:.4}),x=m=>m+s/2,k=te.lidThickness;E("lid","shell",M,(m,T,O)=>[m,x(T),O],(m,T)=>[m,T,0],-k,0),p("lid","shell",M,(m,T)=>[m,x(T),-k],[0,0,-1]),p("lid","glass",Ye(kt-.5,s-.5,{top:1.95,bottom:.2}),(m,T)=>[m,x(T),.01],[0,0,1]);const R=te.chin;p("lid","screen",Ye(100,t,{top:te.screenRadius,bottom:0}),(m,T)=>[m,R+t/2+T,.02],[0,0,1]),p("lid","camera",Ye(.5,.5,{top:.25,bottom:.25},4),(m,T)=>[m,s-te.topBezel/2+T,.02],[0,0,1]);const H=Ye(it,u+k,{top:3,bottom:3}),K=m=>(u-k)/2-m;E("base","shell",H,(m,T,O)=>[m,O,K(T)],(m,T)=>[m,0,-T],-2.2,0),p("base","shell",H,(m,T)=>[m,0,K(T)],[0,1,0]),p("base","shell",H,(m,T)=>[m,-2.2,K(T)],[0,-1,0]);const oe=(m,T,O,L,P,Y,U)=>p("base",m,Ye(L,P,{top:U,bottom:U},3),(ie,q)=>[T+ie,Y,O-q],[0,1,0]),ve=it*.72,ae=u*.08,I=[.55,1,1,1,1,1],ne=u*.4/I.reduce((m,T)=>m+T,0);oe("well",0,ae+u*.4/2,ve+1.4,u*.4+1.4,.01,.8);let $=ae;for(const[m,T]of I.entries()){const O=T*ne,L=ve/14;for(let P=0;P<14;P++){if(m===5&&P>4&&P<9)continue;const Y=m===5&&P===4?5:1;oe("keys",-ve/2+L*(P+Y/2),$+O/2,L*Y-.5,O-.5,.03,.3)}$+=O}oe("trackpad",0,u*.72,it*.4,u*.36,.01,1.2),p("base","scoop",Ye(14,.9,{top:0,bottom:.45},3),(m,T)=>[m,-.45+T,u+.01],[0,0,1]);const D=new Map;for(const m of v){const T=`${m.part}:${m.kind}`;D.set(T,[...D.get(T)??[],m])}return[...D.values()].map(m=>{const T=new Float32Array(m.reduce((L,P)=>L+P.vertices.length,0));let O=0;for(const L of m)T.set(L.vertices,O),O+=L.vertices.length;return{part:m[0].part,kind:m[0].kind,vertices:T}})}function un(d,t,s=0){const u=1-s,v=t/u,A=d>=v?1:d/v,p=(d>=v?v/d:1)*u,E=(1-A)/2,M=s>0?u-p:(u-p)/2;return{repeat:[1/A,1/p],offset:[(0-E)/A,(0-M)/p]}}function hn(d,t,s){const u=d*s.repeat[0]+s.offset[0],v=t*s.repeat[1]+s.offset[1],A=1e-9;if(u<-A||u>1+A||v<-A||v>1+A)return;const p=E=>Math.max(0,Math.min(1,E));return{x:p(u),y:p(1-v)}}const fn=150,mn=8;class pn{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 p={x:s.reduce((E,M)=>E+M.x,0)/s.length,y:s.reduce((E,M)=>E+M.y,0)/s.length};if(v?.mode==="scroll"){const E=u.map(p.x,p.y);E&&t==="touchmove"&&this.scroll(E,(v.x-p.x)*u.scale,(v.y-p.y)*u.scale)}else v?.mode==="press"?this.lift(v,u):v?.mode==="pending"&&clearTimeout(v.timer);return this.gesture={mode:"scroll",...p},!1}const A=s[0];if(A&&t==="touchstart"&&!v)return this.blocked()||!u.contains(A.x,A.y)?!1:(this.screen=u,this.gesture={mode:"pending",x:A.x,y:A.y,timer:setTimeout(()=>this.press(),fn)},!0);if(A&&v?.mode==="pending"){if(Math.hypot(A.x-v.x,A.y-v.y)<mn)return!1;this.press()}if(A&&this.gesture?.mode==="press"){this.gesture={mode:"press",x:A.x,y:A.y};const p=u.map(A.x,A.y);return p&&this.pointer(r.MAC_INPUT_ACTION.MOVE,p,1),!1}if(s.length===0){v?.mode==="pending"&&(t==="touchcancel"?clearTimeout(v.timer):this.press());const p=this.gesture;p?.mode==="press"&&this.lift(p,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 gn(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 yo(d){const[t,s]=l.useReducer(gn,{mode:"2d",selection:0,ready:0}),u=l.useRef(t);u.current=t;const v=l.useRef(d);v.current=d;const{mode:A,selection:p,ready:E}=t,M=l.useCallback(R=>s({type:"choose",mode:R}),[]),x=l.useCallback(()=>{const R=u.current;R.mode!=="3d"||R.selection!==p||R.ready===p||(v.current?.(),s({type:"ready",selection:p}))},[p]),k=A==="3d"&&E!==p;return{mode:A,shown:A==="3d"&&!k?"3d":"2d",loading:k,choose:M,onReady:x}}function vo({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 yn=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}},vn=l.memo(function({element:t,screen:s,highlighted:u,selected:v,selectable:A,onClick:p}){const E=r.clampAxFrameForScreen(t.frame,s);if(!E)return null;const M=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":M,onClick:x=>{A&&(x.preventDefault(),x.stopPropagation(),p(t,{x:x.clientX,y:x.clientY}))},style:{left:`${E.x/s.width*100}%`,top:`${E.y/s.height*100}%`,width:`${E.width/s.width*100}%`,height:`${E.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)),bn=260,Tn=220,An=6,En=8,On=l.memo(function({element:t,platform:s,anchor:u,cursorAnchored:v,showActions:A,onTap:p}){const[E,M]=l.useState(null);l.useEffect(()=>{if(!E)return;const I=window.setTimeout(()=>M(null),1100);return()=>window.clearTimeout(I)},[E]);const x=l.useMemo(()=>{const I=bn,ne=Tn,$=An,D=En,m=typeof window<"u"?window.innerWidth:1024,T=typeof window<"u"?window.innerHeight:768,O=u.x+$+I<=m-D,L=u.y-$-ne>=D;let P=O?u.x+$:u.x-$,Y=L?u.y-$:u.y+$;const q=`translate(${O?"0":"-100%"}, ${L?"-100%":"0"})`;return P=Math.max(D+(O?0:I),Math.min(m-D-(O?I:0),P)),Y=Math.max(D+(L?ne:0),Math.min(T-D-(L?0:ne),Y)),{left:`${P}px`,top:`${Y}px`,transform:q}},[u.x,u.y]),k=l.useMemo(()=>r.axElementSelectorExpression(t,s),[t,s]),R=s==="ios"?t.selectors.AXUniqueId:t.selectors.resourceId,H=s==="ios"?"AXUniqueId":"resourceId",K=l.useCallback(async(I,ne)=>{if(!I)return;await yn(I)&&M(ne)},[]),oe=r.axElementRoleLabel(t),ve=t.label||t.value||oe,ae=r.axElementSummary(t);return Qo.createPortal(g.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":v?"true":"false",style:x,onClick:I=>I.stopPropagation(),onMouseDown:I=>I.stopPropagation(),onMouseMove:I=>I.stopPropagation(),children:[g.jsxs("div",{className:"rc-inspect-card-header",children:[g.jsx("span",{className:"rc-inspect-card-role",children:oe}),!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:ve}),R&&g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsxs("span",{className:"rc-inspect-card-row-label",children:[H,":"]}),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)]})]}),A&&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:!p,onClick:()=>p?.(t,u),children:"Tap"}),g.jsx("button",{type:"button",className:E==="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:E==="selector"?"Copied!":"Copy selector"}),g.jsx("button",{type:"button",className:E==="id"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!R,title:R??`No ${H}`,onClick:()=>K(R,"id"),children:E==="id"?"Copied!":`Copy ${H}`})]})]}),document.body)}),Mn=l.memo(function({snapshot:t,geometry:s,highlightedId:u,selectedId:v,mode:A,cursorPosition:p,frozenCursorPosition:E,onSelectChange:M,onTapElement:x}){const k=A==="select",R=k?u!==null&&u!==v:u!==null,H=k?u??v:u,K=l.useMemo(()=>{const D=new Map;if(!t)return D;for(const m of t.elements)D.set(m.id,m);return D},[t]),oe=l.useMemo(()=>H?K.get(H)??null:null,[H,K]);if(!(!!t&&!!s&&t.screen.width>0&&t.screen.height>0&&t.elements.length>0))return null;const ae=R?p:E??p,I=R,ne=k&&!R&&v!==null,$=D=>{k&&D.target===D.currentTarget&&M(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:$,children:t.elements.map(D=>g.jsx(vn,{element:D,screen:t.screen,highlighted:D.id===u,selected:D.id===v,selectable:k,onClick:M},D.id))}),oe&&ae&&g.jsx(On,{element:oe,platform:t.platform,anchor:ae,cursorAnchored:I,showActions:ne,onTap:x})]})});function Nn(d,t){if(!t.startsWith("lim_st_"))return!1;try{const s=new URL(d).pathname.split("/").map(decodeURIComponent).find(x=>/^(ios|android)_[a-z0-9_]+$/.test(x));if(!s)return!1;const u=s.split("_")[0],v=t.slice(7).split(".");if(v.length!==3||v.some(x=>!x))return!1;const A=atob(v[1].replace(/-/g,"+").replace(/_/g,"/")),p=JSON.parse(new TextDecoder().decode(Uint8Array.from(A,x=>x.charCodeAt(0))));if(!p||typeof p!="object"||!("scopes"in p))return!1;const E=p.scopes;if(!Array.isArray(E)||!E.every(x=>typeof x=="string"))return!1;let M=!1;for(const x of E){const[k,R,H,K]=x.split(":");if(!(K!==void 0||k!==u&&k!=="*")&&!(R!==s&&R!=="*")){if(H==="stream"||H==="all")return!1;H==="watch"&&(M=!0)}}return M}catch{return!1}}const wn=l.lazy(()=>Promise.resolve().then(()=>require("./duo-view-B60dcPNt.js")).then(d=>d.duoView)),In=l.lazy(()=>Promise.resolve().then(()=>require("./macbook-frame-CaCXZbOa.js"))),gt=d=>Object.entries(r.AMOTION_EVENT).find(([s,u])=>s.startsWith("ACTION_")&&u===d)?.[0]??String(d),po=1920,go=1200,_n=(d,t)=>d===po&&t===go||d===go&&t===po,Rn={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}}}},Cn={"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}}}},St=16/10,yt=44,xn={videoBorderRadiusMultiplier:32/1837,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:2560/2798},landscape:{widthMultiplier:2560/2798}}};function Sn(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",A=d.getModifierState("CapsLock"),p=d.shiftKey;let E=p;return v&&(E=p!==A),E&&(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 nt(d,t){const s=Object.keys(d);return s.length===Object.keys(t).length&&s.every(u=>d[u]===t[u])}const kn=l.forwardRef(({className:d,url:t,token:s,sessionId:u,openUrl:v,watchOnly:A=!1,showFrame:p=!0,animateLid:E=!0,deviceModel:M,duoModelUrl:x,macbookModelUrl:k,autoReconnect:R,jitterBufferTargetMs:H,onPlaybackStats:K,onTerminated:oe,assets:ve,onConnectionStateChange:ae,inspectMode:I,onAxSnapshotChange:ne,onInspectSelectionChange:$,onAxStatusChange:D,axPollIntervalMs:m,axMaxBackoffMs:T,androidElementTreeOptions:O,onCameraDemandChange:L,onCameraStats:P,onTrace:Y,microphoneEnabled:U=!1,onMicrophoneStateChange:ie},q)=>{const ue=l.useMemo(()=>Nn(t,s),[t,s]),F=A||ue,G=l.useRef(null),N=l.useRef(null),be=l.useRef(null),[rt,Z]=l.useState(!1),j=M==="iphone-duo"||rt,Me=M==="iphone-duo"?M:void 0,We=l.useRef(null),[Pt,bo]=l.useState(null),[Lt,To]=l.useState(),[Ao,Eo]=l.useState(!1),[Oo,Mo]=l.useState(!1),[No,wo]=l.useState(!1),[vt,Ht]=l.useState(!1),[Yt,Wt]=l.useState(!1),[Io,Xt]=l.useState({}),[Kt,jt]=l.useState(null),[bt,_o]=l.useState(null),[Tt,Ro]=l.useState(null),Vt=l.useRef(null),[Bt,Co]=l.useState(null),[$t,Ut]=l.useState(null),Ge=yo(()=>ut.current?.release()),st=l.useRef(!1),At=l.useRef(null),B=l.useRef(new Map),Ne=l.useRef(!1),[xo,So]=l.useState(!1),W=l.useRef(null),Xe=l.useRef(null),Ze=l.useRef({handle:()=>{},end:()=>{}}),[we,ct]=l.useState(null),[Ft,Et]=l.useState(null),[Ot,Je]=l.useState(null),[Mt,at]=l.useState(null),[ko,zt]=l.useState(null),[Do,qt]=l.useState(null),lt=l.useRef(null),he=l.useRef(void 0),Gt=e=>{lt.current=e,he.current===void 0&&(he.current=window.requestAnimationFrame(()=>{he.current=void 0,qt(lt.current)}))},[Po,Ke]=l.useState(null),Ie=l.useRef(null);Ie.current=Ft;const je=l.useRef($);je.current=$;const _e=I===!0||I==="hover-only",Zt=l.useRef(_e);Zt.current=_e;const Lo=I==="hover-only"?"hover-only":"select",V=l.useMemo(()=>r.detectPlatform(t),[t]),Ho=l.useMemo(()=>u||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[u]),Qe=V==="ios"&&M&&M!=="iphone-duo"?M:void 0,Re=V==="android"&&Yt?xn:Qe?Cn[Qe]:Rn[V],re=ve?.[V],Jt=Qe&&re?.modelFrames?.[Qe],Qt=V==="android"&&Yt?vt?re?.tabletFrameLandscape:re?.tabletFrame:Qe?vt?Jt?.frameLandscape:Jt?.frame:vt?re?.frameLandscape:re?.frame,eo=re?.loadingLogo,et=!j&&V!=="macos"&&p&&!!Qt,le=V==="macos"&&p,fe=le&&re?.frame&&re.screen?{src:re.frame,screen:re.screen}:void 0,Nt=l.useRef(null),Yo=le&&Ge.mode==="3d",me=le&&Ge.shown==="3d";st.current=me;const to=Ge.choose;l.useEffect(()=>{le||to("2d")},[le,to]);const oo=!!fe&&!me&&!!Tt;l.useEffect(()=>{const e=N.current,n=Vt.current,i=n?.getContext("2d");if(!oo||!e||!n||!i)return;const o=()=>{if(e.videoWidth){n.width!==e.videoWidth&&(n.width=e.videoWidth);try{i.drawImage(e,0,0,e.videoWidth,1,0,0,n.width,1)}catch{}}};let c=!1,h;const a=()=>{c||(o(),h=e.requestVideoFrameCallback(a))},f="requestVideoFrameCallback"in e?void 0:window.setInterval(o,1e3/30);return f===void 0&&(h=e.requestVideoFrameCallback(a)),o(),()=>{c=!0,h!==void 0&&e.cancelVideoFrameCallback(h),window.clearInterval(f)}},[oo]);const C=l.useRef(null),ce=e=>C.current?.sendControl(e),dt=l.useRef(new Set),no=l.useRef(!1);no.current=I===!0;const ut=l.useRef(null);ut.current||(ut.current=new pn(e=>C.current?.sendControl(e),()=>no.current));const Ce=ut.current;l.useEffect(()=>()=>Ce.release(),[Ce]);const tt=l.useCallback(()=>{for(const e of dt.current)C.current?.sendControl(r.createMacKeyMessage(r.MAC_INPUT_ACTION.UP,e));dt.current.clear()},[]),wt=(e,n)=>C.current?.sendDuoControl(e,n)??Promise.reject(new Error("Simulator disconnected")),io=-10,ro=(e,n)=>{const i=Be();if(!i)return;const o=pe(i,e,n);if(!o)return;const{videoX:c,videoY:h,videoWidth:a,videoHeight:f}=o,y=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_DOWN,io,a,f,c,h,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);y&&ce(y),window.setTimeout(()=>{const w=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_UP,io,a,f,c,h,0,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);w&&ce(w)},60)},Wo=(e,n)=>{const i=Be();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,f=i.videoRect.left+i.offsetX+h,y=i.videoRect.top+i.offsetY+a;ro(f,y)},ht=-1,ft=-2,xe=-3,Ve=(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}}),ce(a))},Se=(e,n,i)=>{if(!i)return;const{videoX:o,videoY:c,videoWidth:h,videoHeight:a}=i;let f=null,y=null,w=1;const S=r.AMOTION_EVENT.BUTTON_PRIMARY;switch(n){case"down":e!==xe&&Ze.current.end(),f=B.current.size===0?r.AMOTION_EVENT.ACTION_DOWN:r.AMOTION_EVENT.ACTION_POINTER_DOWN,y={x:o,y:c},B.current.set(e,y),e===-1&&N.current?.focus();break;case"move":B.current.has(e)&&(f=r.AMOTION_EVENT.ACTION_MOVE,y={x:o,y:c},B.current.set(e,y));break;case"up":case"cancel":B.current.has(e)&&(y=B.current.get(e),B.current.delete(e),n==="cancel"?f=r.AMOTION_EVENT.ACTION_CANCEL:f=B.current.size===0?r.AMOTION_EVENT.ACTION_UP:r.AMOTION_EVENT.ACTION_POINTER_UP);break}if(f!==null&&y!==null){r.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:n,action:f,actionName:gt(f),positionToSend:y,video:{width:h,height:a},altHeld:Ne.current,activePointersAfter:Array.from(B.current.entries()).map(([Q,X])=>({id:Q,x:X.x,y:X.y}))});const b=r.createTouchControlMessage(f,e,h,a,y.x,y.y,w,S,S);b&&(r.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:gt(f),byteLength:b.byteLength}),ce(b))}else(n==="up"||n==="cancel")&&B.current.delete(e)},It=e=>{if(Ne.current!==e&&(Ne.current=e,So(e),e||ct(null),r.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from(B.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&&ce(i)}},Be=()=>{const e=N.current,n=G.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,f=c.height,y=i/o,w=a/f;let S=a,b=f;y>w?b=a/y:S=f*y;const Q=(a-S)/2,X=(f-b)/2;return{videoWidth:i,videoHeight:o,videoRect:c,containerRect:h,actualWidth:S,actualHeight:b,offsetX:Q,offsetY:X}},pe=(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)),f=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),y=Math.max(0,Math.min(e.videoHeight,a/e.actualHeight*e.videoHeight));return{videoX:f,videoY:y,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Xo=(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)),f=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),y=Math.max(0,Math.min(e.videoHeight,a/e.actualHeight*e.videoHeight)),w=e.videoWidth-f,S=e.videoHeight-y,b=e.videoRect.left+e.offsetX,Q=e.videoRect.top+e.offsetY,X=b-e.containerRect.left+h,z=Q-e.containerRect.top+a,se=b-e.containerRect.left+(e.actualWidth-h),_=Q-e.containerRect.top+(e.actualHeight-a);return{containerX:X,containerY:z,mirrorContainerX:se,mirrorContainerY:_,videoX:f,videoY:y,mirrorVideoX:w,mirrorVideoY:S,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Ko=(e,n,i,o,c,h,a)=>{const f=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:f.byteLength}),ce(f)},$e=(e,n,i,o,c,h,a,f,y)=>{if(r.debugLog("[rc-touch2] applyTwoFingerEvent",{platform:V,eventType:e,video:{width:n,height:i},p0:{x:o,y:c,id:f},p1:{x:h,y:a,id:y}}),e==="down"&&Ze.current.end(),V==="ios"){const w=e==="down"?r.AMOTION_EVENT.ACTION_DOWN:e==="move"?r.AMOTION_EVENT.ACTION_MOVE:r.AMOTION_EVENT.ACTION_UP;Ko(w,n,i,o,c,h,a)}else e==="down"?(Ve(r.AMOTION_EVENT.ACTION_DOWN,f,n,i,o,c),Ve(r.AMOTION_EVENT.ACTION_POINTER_DOWN,y,n,i,h,a)):e==="move"?(Ve(r.AMOTION_EVENT.ACTION_MOVE,f,n,i,o,c),Ve(r.AMOTION_EVENT.ACTION_MOVE,y,n,i,h,a)):(Ve(r.AMOTION_EVENT.ACTION_POINTER_UP,y,n,i,h,a),Ve(r.AMOTION_EVENT.ACTION_UP,f,n,i,o,c))},jo=(e,n,i)=>{if(!Ne.current){we!==null&&ct(null);return}const o=Xo(e,n,i);ct(o)},Vo=(e,n,i)=>{const o=Ie.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,f=h/e.actualHeight*o.screen.height;return r.axElementAtPoint(o,a,f)},Bo=e=>({map:(n,i)=>{const o=pe(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}),Te=e=>{if(j||st.current)return;e.preventDefault(),e.stopPropagation();const n=Be();if((I===!0||I==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(Gt({x:e.clientX,y:e.clientY}),n){const o=Vo(n,e.clientX,e.clientY);Je(o?.id??null)}}else e.type==="mouseleave"&&(Gt(null),Je(null));if(I!==!0){if(V==="macos"){if(!n||!C.current?.getState().controlReady)return;if("touches"in e){const a=Array.from(e.touches,f=>({x:f.clientX,y:f.clientY}));Ce.touch(e.type,a,Bo(n))&&N.current?.focus();return}const o=pe(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"&&N.current?.focus(),Ce.pointer(c,{x:o.videoX,y:o.videoY,width:o.videoWidth,height:o.videoHeight},h);return}if(!("touches"in e)&&n&&(e.type==="mousemove"?jo(n,e.clientX,e.clientY):e.type==="mouseleave"&&ct(null)),!(!C.current?.getState().controlReady||!N.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],f=o[1],y=pe(n,a.clientX,a.clientY),w=pe(n,f.clientX,f.clientY);if(!y||!w)return;W.current?W.current.source==="real-touch"&&(W.current.finger0={x:y.videoX,y:y.videoY},W.current.finger1={x:w.videoX,y:w.videoY},$e("move",y.videoWidth,y.videoHeight,y.videoX,y.videoY,w.videoX,w.videoY,W.current.pointerId0,W.current.pointerId1)):(W.current={finger0:{x:y.videoX,y:y.videoY},finger1:{x:w.videoX,y:w.videoY},videoSize:{width:y.videoWidth,height:y.videoHeight},source:"real-touch",pointerId0:a.identifier,pointerId1:f.identifier},$e("down",y.videoWidth,y.videoHeight,y.videoX,y.videoY,w.videoX,w.videoY,a.identifier,f.identifier))}else if(o.length<2&&W.current?.source==="real-touch"){const a=W.current;$e("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 f=pe(n,a.clientX,a.clientY);Se(a.identifier,h,f)}}}}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||B.current.has(-1))&&(c="move");break;case"mouseup":e.button===0&&(c="up");break;case"mouseleave":(h||B.current.has(-1))&&(c="up");break}if(c){const a=pe(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:Ne.current,inTwoFingerMode:h,geometry:{videoX:a.videoX,videoY:a.videoY,videoWidth:a.videoWidth,videoHeight:a.videoHeight},activePointerIds:Array.from(B.current.keys())}),Ne.current||h?$o(c,a):Se(-1,c,a)}}}},$o=(e,n)=>{const{videoX:i,videoY:o,videoWidth:c,videoHeight:h}=n,a=c-i,f=h-o;if(e==="down"){W.current={finger0:{x:i,y:o},finger1:{x:a,y:f},videoSize:{width:c,height:h},source:"alt-mouse",pointerId0:ht,pointerId1:ft},N.current?.focus(),$e("down",c,h,i,o,a,f,ht,ft);return}if(e==="move"){W.current?.source==="alt-mouse"&&(W.current.finger0={x:i,y:o},W.current.finger1={x:a,y:f},$e("move",c,h,i,o,a,f,ht,ft));return}if(e==="up"||e==="cancel"){const y=W.current;if(y?.source==="alt-mouse"){const{finger0:w,finger1:S,videoSize:b}=y;$e("up",b.width,b.height,w.x,w.y,S.x,S.y,ht,ft),W.current=null}return}},Uo=150,so=()=>{const e=Xe.current;e&&(window.clearTimeout(e.endTimer),Se(xe,"up",e.pos),Xe.current=null)},Fo=e=>{if(!C.current?.getState().controlReady||e.ctrlKey)return;if(V==="macos"){if(st.current)return;const _=Be();if(!_)return;const ke=e.clientX-_.videoRect.left-_.offsetX,ge=e.clientY-_.videoRect.top-_.offsetY;if(ke<0||ke>_.actualWidth||ge<0||ge>_.actualHeight)return;const de=pe(_,e.clientX,e.clientY);if(!de)return;e.preventDefault();const Fe=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?_.actualHeight:1;Ce.scroll({x:de.videoX,y:de.videoY,width:de.videoWidth,height:de.videoHeight},e.deltaX*Fe,e.deltaY*Fe);return}if(Ne.current||W.current)return;const n=B.current.size;if(n>1||n===1&&!B.current.has(xe))return;const i=Be();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=pe(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),f=(e.deltaMode===1?16:e.deltaMode===2?i.actualHeight:1)*(i.videoHeight/i.actualHeight),y=-e.deltaX*a,w=-e.deltaY*f,S=_=>{window.clearTimeout(_.endTimer),_.endTimer=window.setTimeout(so,Uo)};if(y===0&&w===0){Xe.current&&S(Xe.current);return}const b=()=>({videoWidth:h.videoWidth,videoHeight:h.videoHeight,videoX:Math.abs(y)>Math.abs(w)?Math.min(Math.max(h.videoX,h.videoWidth*.2),h.videoWidth*.8):h.videoX,videoY:Math.abs(w)>=Math.abs(y)?Math.min(Math.max(h.videoY,h.videoHeight*.2),h.videoHeight*.8):h.videoY}),Q=_=>({..._,videoX:Math.min(Math.max(_.videoX+y,0),_.videoWidth),videoY:Math.min(Math.max(_.videoY+w,0),_.videoHeight)});let X=Xe.current;if(X)window.clearTimeout(X.endTimer);else{const _=b();Se(xe,"down",_),X={pos:_,endTimer:0},Xe.current=X}let z=X.pos,se=Q(z);se.videoX===z.videoX&&se.videoY===z.videoY&&(Se(xe,"up",z),z=b(),Se(xe,"down",z),se=Q(z)),Se(xe,"move",se),X.pos=se,S(X)};l.useEffect(()=>{Ze.current={handle:Fo,end:so}}),l.useEffect(()=>{const e=G.current;if(!e)return;const n=i=>Ze.current.handle(i);return e.addEventListener("wheel",n,{passive:!1}),()=>{Ze.current.end(),e.removeEventListener("wheel",n)}},[]),l.useEffect(()=>{const e=c=>{c.key==="Alt"&&It(!0)},n=c=>{c.key==="Alt"&&It(!1)},i=()=>{It(!1),tt()},o=()=>{document.hidden&&tt()};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)}},[tt]);const Ue=e=>{e.preventDefault(),e.stopPropagation();const n=document.activeElement===N.current||(j||st.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"?dt.current.add(o):dt.current.delete(o),ce(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);ce(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);ce(o);const c=r.createInjectKeycodeMessage(r.ANDROID_KEYS.ACTION_UP,r.ANDROID_KEYS.MENU,0,r.ANDROID_KEYS.META_NONE);ce(c);return}}const i=Sn(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);ce(a)}else r.debugLog(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`)},zo=e=>{e.stopPropagation(),C.current?.reconnect()},J=l.useRef({onAxSnapshotChange:ne,onAxStatusChange:D,onCameraDemandChange:L,onCameraStats:P,onMicrophoneStateChange:ie,onTrace:Y,onTerminated:oe,onConnectionStateChange:ae,onPlaybackStats:K});J.current={onAxSnapshotChange:ne,onAxStatusChange:D,onCameraDemandChange:L,onCameraStats:P,onMicrophoneStateChange:ie,onTrace:Y,onTerminated:oe,onConnectionStateChange:ae,onPlaybackStats:K};const _t=!!Y;l.useEffect(()=>{At.current=null,Ht(!1),Wt(!1),Xt({}),jt(null)},[t,Me]),l.useEffect(()=>{let e=!0;Ie.current!==null&&(Ie.current=null,Et(null),r.safeInvoke("onAxSnapshotChange",J.current.onAxSnapshotChange,null));const n=r.createDeviceStream({url:t,token:s,sessionId:Ho,watchOnly:F,deviceModel:Me,autoReconnect:R,jitterBufferTargetMs:H,openUrl:v,inspectMode:I,axPollIntervalMs:m,axMaxBackoffMs:T,androidElementTreeOptions:O,microphoneEnabled:U,onStateChange:o=>{(o.videoReady||o.connection==="idle"||o.connection==="connecting"||o.connection==="reconnecting")&&Eo(o.videoReady),Mo(o.connection==="failed"),wo(o.connection==="terminated"),Z(o.duo),bo(o.duoState),To(o.duoError)},onAxSnapshotChange:o=>{e&&(Et(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:_t?(...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=N.current?n.attachVideo(N.current):void 0;return n.start(),()=>{e=!1,n.dispose(),i?.(),C.current=null}},[t,u,Me,_t,F]),l.useEffect(()=>{if(j&&We.current)return C.current?.attachVideo(We.current,"inner")},[j,t,u,Me,_t,F]),l.useEffect(()=>{C.current?.updateOptions({token:s,openUrl:v,axPollIntervalMs:m,axMaxBackoffMs:T,androidElementTreeOptions:O,autoReconnect:R,jitterBufferTargetMs:H,microphoneEnabled:U,inspectMode:I,onPlaybackStats:K?(...e)=>J.current.onPlaybackStats?.(...e):void 0,onCameraStats:P?(...e)=>J.current.onCameraStats?.(...e):void 0})},[s,R,H,U,I,!!K,!!P,v,m,T,O]);const ot=()=>{if(!Zt.current)return;const e=Be();if(!e){zt(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};zt(i=>i&&i.left===n.left&&i.top===n.top&&i.width===n.width&&i.height===n.height?i:n)};l.useEffect(()=>{const e=N.current,n=be.current,i=G.current;if(!e)return;const o=S=>Xt(b=>nt(b,S)?b:S),c=S=>jt(b=>b&&S&&nt(b,S)?b:S),h=S=>_o(b=>b&&S&&nt(b,S)?b:S),a=()=>{const S=e.videoWidth>0&&e.videoHeight>0;S&&(At.current={width:e.videoWidth,height:e.videoHeight});const b=At.current,Q=b?`${b.width} / ${b.height}`:void 0,X=Nt.current;if(fe&&i){if(Ut(b?b.width/b.height:St),!X?.naturalWidth)return;const De=X.naturalWidth/X.naturalHeight,mt=i.clientHeight-yt,Pe=i.clientHeight>0?Math.min(i.clientWidth,mt*De):i.clientWidth;if(Pe<=0)return;const Ae=Pe/De,Ee=i.clientHeight>0?yt/2:0,{screen:ee}=fe,Le=ee.notch??0,ze=ee.left*Pe,He=ee.top*Ae,pt=ee.width*Pe,ao=He+Le*ee.height*Ae,lo=(1-Le)*ee.height*Ae,uo=b?b.width/b.height:St,qe=Math.min(pt,lo*uo),Rt=qe/uo,ho=ze+(pt-qe)/2,fo=Le>0?ao:ao+(lo-Rt)/2,Ct=(ye,Oe,Zo,Jo)=>`translate(calc(-50% + ${ye+Zo/2-Pe/2}px), calc(-50% + ${Oe+Jo/2-Ae/2+Ee}px))`;o({width:`${qe}px`,height:`${Rt}px`,transform:Ct(ho,fo,qe,Rt)});const xt=fo-He;Ro(ye=>{const Oe=Le>0&&xt>0?{width:`${qe}px`,height:`${xt+1}px`,transform:Ct(ho,He,qe,xt+1)}:null;return ye&&Oe&&nt(ye,Oe)?ye:Oe});const mo=ee.height*Ae;Co(ye=>{const Oe={width:`${pt}px`,height:`${mo}px`,transform:Ct(ze,He,pt,mo)};return ye&&nt(ye,Oe)?ye:Oe}),h({width:`${Pe}px`,height:`${Ae}px`,transform:Ee?`translateY(${Ee}px)`:void 0}),c(null),ot();return}if(le&&i){const De=b?b.width/b.height:St,mt=i.clientWidth*100/it,Ae=(i.clientHeight-yt)/(1/De+Dt/100),Ee=i.clientHeight>0?Math.min(mt,Ae):mt;if(Ee<=0)return;const ee=Ee/100,Le=Ee/De,ze=i.clientHeight>0?yt/2:0,He=`${ee*te.screenRadius}px`;o({aspectRatio:`${De}`,width:`${Ee}px`,height:`${Le}px`,borderRadius:`${He} ${He} 0 0`,transform:`translate(-50%, calc(-50% - ${ee*en-ze}px))`}),h({width:`${ee*it}px`,height:`${Le+ee*Dt}px`,transform:ze?`translateY(${ze}px)`:void 0,"--rc-macbook-unit":`${ee}px`}),Ut(De),c(null),ot();return}if(h(null),!et||!n){o(!S&&b?{aspectRatio:Q,contain:"size",containIntrinsicSize:`${b.width}px ${b.height}px`}:{}),c(null),ot();return}const z=n.clientWidth,se=n.clientHeight;if(z===0||se===0)return;const _=b?b.width>b.height:!1;Ht(_),Wt(V==="android"&&!!b&&_n(b.width,b.height));const ke=_?Re.videoPosition.landscape:Re.videoPosition.portrait;let ge={aspectRatio:Q};ke.heightMultiplier?(ge.height=`${se*ke.heightMultiplier}px`,ge.width="auto"):ke.widthMultiplier&&(ge.width=`${z*ke.widthMultiplier}px`,ge.height="auto"),ge.borderRadius=`${_?se*Re.videoBorderRadiusMultiplier:z*Re.videoBorderRadiusMultiplier}px`,o(ge);const de=Re.homeButton,Fe=_?z:se,co=`calc(50% + ${Fe*(de?.offset??0)}px)`;c(de?{width:`${Fe*de.diameter}px`,height:`${Fe*de.diameter}px`,left:_?co:"50%",top:_?"50%":co}:null),ot()},f=new ResizeObserver(()=>{a()});n&&f.observe(n),f.observe(e),i&&f.observe(i),n&&n.addEventListener("load",a);const y=Nt.current;y?.addEventListener("load",a),e.addEventListener("loadedmetadata",a),e.addEventListener("resize",a);const w=()=>C.current?.bumpActivity();return e.addEventListener("resize",w),a(),()=>{f.disconnect(),e.removeEventListener("loadedmetadata",a),e.removeEventListener("resize",a),e.removeEventListener("resize",w),n&&n.removeEventListener("load",a),y?.removeEventListener("load",a)}},[Re,et,le,fe?.src,me,t,M]),l.useEffect(()=>{_e?ot():(Et(null),Je(null),at(null),qt(null),Ke(null),lt.current=null,he.current!==void 0&&(window.cancelAnimationFrame(he.current),he.current=void 0))},[_e]),l.useEffect(()=>()=>{he.current!==void 0&&(window.cancelAnimationFrame(he.current),he.current=void 0)},[]),l.useEffect(()=>{if(!_e)return;const e=n=>{n.key==="Escape"&&(Mt||Ot)&&(at(null),Je(null),Ke(null),r.safeInvoke("onInspectSelectionChange",je.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[_e,Mt,Ot]);const qo=()=>{N.current&&N.current.focus()};l.useImperativeHandle(q,()=>({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=>{Je(e?.id??null)},setInspectSelection:e=>{at(e?.id??null),Ke(e?lt.current:null);const n=Ie.current;e&&n?r.safeInvoke("onInspectSelectionChange",je.current,{element:e,snapshot:n}):r.safeInvoke("onInspectSelectionChange",je.current,null)},getAxStatus:()=>C.current?.getAxStatus()??"idle"}));const Go=xo&&we!==null;return g.jsxs("div",{ref:G,className:["rc-container",d].filter(Boolean).join(" "),style:{touchAction:"none"},onMouseDown:Te,onMouseMove:Te,onMouseUp:Te,onMouseLeave:Te,onTouchStart:Te,onTouchMove:Te,onTouchEnd:Te,onTouchCancel:Te,onContextMenu:V==="macos"?e=>e.preventDefault():void 0,children:[Go&&we&&g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"rc-touch-indicator",style:{left:`${we.containerX}px`,top:`${we.containerY}px`}}),g.jsx("div",{className:"rc-touch-indicator",style:{left:`${we.mirrorContainerX}px`,top:`${we.mirrorContainerY}px`}})]}),et&&g.jsx("img",{ref:be,src:Qt,alt:"",className:V==="ios"?"rc-phone-frame rc-phone-frame-ios":"rc-phone-frame",draggable:!1}),fe&&!me&&Bt&&g.jsx("div",{className:"rc-macbook-screen",style:Bt,"aria-hidden":"true"}),fe&&!me&&Tt&&g.jsx("canvas",{ref:Vt,className:"rc-macbook-band",style:Tt,height:1}),fe&&!me&&g.jsx("img",{ref:Nt,src:fe.src,alt:"",className:"rc-macbook-image",style:bt??{visibility:"hidden"},draggable:!1}),le&&!fe&&bt&&!me&&g.jsxs("div",{className:"rc-macbook",style:bt,"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"})]}),et&&Kt&&!F&&g.jsx("button",{type:"button",className:"rc-home-button","aria-label":"Home",title:"Home",style:Kt,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:N,className:["rc-video",!et&&!le&&"rc-video-frameless",!Ao&&(V==="macos"?"rc-video-loading-desktop":"rc-video-loading")].filter(Boolean).join(" "),style:{...Io,...j||me?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...eo?{backgroundImage:`url("${eo}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:Re.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:j||me?-1:0,onKeyDown:Ue,onKeyUp:Ue,onClick:qo,onFocus:()=>{N.current&&(N.current.style.outline="none")},onBlur:()=>{N.current&&(N.current.style.outline="none"),tt()}}),Yo&&$t&&g.jsx(l.Suspense,{fallback:null,children:g.jsx(In,{video:N.current,aspect:$t,model:k??re?.model,animateLid:E,watchOnly:F,onReady:Ge.onReady,pointer:(e,n,i,o)=>{const c=N.current;!c?.videoWidth||!C.current?.getState().controlReady||Ce.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=N.current;!c?.videoWidth||!C.current?.getState().controlReady||Ce.scroll({x:e*c.videoWidth,y:n*c.videoHeight,width:c.videoWidth,height:c.videoHeight},i,o)},onKeyDown:Ue,onKeyUp:Ue,onBlur:tt})}),le&&g.jsx(vo,{view:Ge,label:"MacBook rendering"}),j&&g.jsx("video",{ref:We,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),j&&Pt&&g.jsx(l.Suspense,{fallback:g.jsx("div",{children:"Loading iPhone Duo…"}),children:g.jsx(wn,{watchOnly:F,showFrame:p,model:x??re?.model,outer:N.current,inner:We.current,state:Pt,setAngle:e=>wt("setHingeAngle",{angleDegrees:e}),setOrientation:e=>wt("setDuoOrientation",{orientation:e}),button:(e,n)=>wt("performActions",{actions:[{type:n?"buttonDown":"buttonUp",button:e}]}),touch:(e,n,i,o)=>{C.current?.sendDisplayTouch(e,n,i,o)},onKeyDown:Ue,onKeyUp:Ue})}),j&&Lt&&g.jsx("div",{role:"alert",className:"rc-duo-error",children:Lt}),!j&&_e&&g.jsx(Mn,{snapshot:Ft,geometry:ko,highlightedId:Ot,selectedId:Mt,mode:Lo,cursorPosition:Do,frozenCursorPosition:Po,onSelectChange:(e,n)=>{at(e?.id??null),e&&n?Ke(n):e||Ke(null);const i=Ie.current;e&&i?r.safeInvoke("onInspectSelectionChange",je.current,{element:e,snapshot:i}):r.safeInvoke("onInspectSelectionChange",je.current,null)},onTapElement:F?void 0:((e,n)=>{if(n){ro(n.x,n.y);return}const i=Ie.current;i&&Wo(e,i)})}),No?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."})]}):Oo&&g.jsx("button",{type:"button",className:"rc-retry-button",onClick:zo,children:"Retry"})]})});exports.DeviceModeToggle=vo;exports.MACBOOK_LID_MAX_DEGREES=rn;exports.MACBOOK_LID_OPENING_MS=cn;exports.MACBOOK_LID_OPEN_DEGREES=sn;exports.MACBOOK_VERTEX_FLOATS=tn;exports.RemoteControl=kn;exports.lidEase=ln;exports.lidRotation=an;exports.macbookMeshes=dn;exports.streamFit=un;exports.streamPoint=hn;exports.useDeviceView=yo;