@limrun/ui 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -8
- package/dist/BufferGeometryUtils-B2-bJqFj.js +1 -0
- package/dist/BufferGeometryUtils-BcXIkYhS.mjs +64 -0
- package/dist/{GLTFLoader-D4AITfgZ.mjs → GLTFLoader-BQvr_TBF.mjs} +138 -137
- package/dist/GLTFLoader-CsxjkQ8a.js +1 -0
- package/dist/components/device-stage.d.ts +61 -0
- package/dist/components/device-view.d.ts +29 -0
- package/dist/components/duo-frame.d.ts +5 -1
- package/dist/components/duo-model.d.ts +2 -1
- package/dist/components/macbook-frame.d.ts +30 -0
- package/dist/components/macbook-geometry.d.ts +77 -0
- package/dist/components/model-source.d.ts +8 -0
- package/dist/components/remote-control.d.ts +40 -1
- package/dist/components/studio-environment.d.ts +6 -0
- package/dist/core/mac-pointer.d.ts +56 -0
- package/dist/{core-CRIachT9.mjs → core-nbvkIrvp.mjs} +24 -24
- package/dist/core.js +12 -12
- package/dist/duo-frame-B04_gIge.js +11 -0
- package/dist/duo-frame-CyoWZakh.mjs +748 -0
- package/dist/duo-model-BYgtCaCR.mjs +4 -0
- package/dist/duo-model-CDWgmLRF.js +1 -0
- package/dist/duo-model.d.ts +2 -0
- package/dist/duo-view-BHwnQmx_.js +1 -0
- package/dist/{duo-view-BeqYIqfQ.mjs → duo-view-DJEQ3Q74.mjs} +84 -86
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +32 -25
- package/dist/lite.cjs +1 -1
- package/dist/lite.js +2 -2
- package/dist/macbook-frame-Be0dCliH.js +3 -0
- package/dist/macbook-frame-DzwIHHCA.mjs +344 -0
- package/dist/macbook-model-BiMxLpmf.mjs +4 -0
- package/dist/macbook-model-BpUdvtlU.js +1 -0
- package/dist/macbook-model.d.ts +2 -0
- package/dist/meshopt_decoder.module-C4Z_evpr.mjs +217 -0
- package/dist/meshopt_decoder.module-DxJdu6ez.js +1 -0
- package/dist/{duo-frame-D1JK_cRk.mjs → model-source-BAZAKTcr.mjs} +6184 -6894
- package/dist/model-source-DbYJQWkh.js +4049 -0
- package/dist/remote-control-Db6ssV0S.js +1 -0
- package/dist/remote-control-PGtDEDgm.mjs +1746 -0
- package/package.json +1 -1
- package/dist/GLTFLoader-C25N9Y4j.js +0 -1
- package/dist/duo-frame-B1NXSk6a.js +0 -4059
- package/dist/duo-view-PsR5b045.js +0 -1
- package/dist/remote-control-DNr0Pyrx.js +0 -1
- package/dist/remote-control-rdm3mDtI.mjs +0 -1299
|
@@ -0,0 +1 @@
|
|
|
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-BHwnQmx_.js")).then(d=>d.duoView)),In=l.lazy(()=>Promise.resolve().then(()=>require("./macbook-frame-Be0dCliH.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;
|