@limrun/ui 0.20.7 → 0.20.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- "use strict";require('./index.css');const h=require("react/jsx-runtime"),r=require("./core-Bdivxz74.js"),d=require("react"),Xt=require("react-dom"),Ht=async f=>{if(!f)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(f),!0}catch{}try{const i=document.createElement("textarea");i.value=f,i.style.position="fixed",i.style.opacity="0",document.body.appendChild(i),i.select();const g=document.execCommand("copy");return document.body.removeChild(i),g}catch{return!1}},jt=d.memo(function({element:i,screen:g,highlighted:p,selected:O,selectable:H,onClick:R}){const v=r.clampAxFrameForScreen(i.frame,g);if(!v)return null;const W=r.axElementSummary(i);return h.jsx("button",{type:"button",className:i.enabled?"rc-inspect-box":"rc-inspect-box rc-inspect-box-disabled","data-ax-id":i.id,"data-ax-path":i.path,"data-ax-label":i.label||void 0,"data-ax-role":i.role||void 0,"data-highlighted":p?"true":"false","data-selected":O?"true":"false","aria-label":W,onClick:y=>{H&&(y.preventDefault(),y.stopPropagation(),R(i,{x:y.clientX,y:y.clientY}))},style:{left:`${v.x/g.width*100}%`,top:`${v.y/g.height*100}%`,width:`${v.width/g.width*100}%`,height:`${v.height/g.height*100}%`}})},(f,i)=>f.highlighted===i.highlighted&&f.selected===i.selected&&f.selectable===i.selectable&&f.screen.width===i.screen.width&&f.screen.height===i.screen.height&&f.onClick===i.onClick&&r.axElementsEqual(f.element,i.element)),Vt=260,Kt=220,Ut=6,$t=8,Ft=d.memo(function({element:i,platform:g,anchor:p,cursorAnchored:O,showActions:H,onTap:R}){const[v,W]=d.useState(null);d.useEffect(()=>{if(!v)return;const A=window.setTimeout(()=>W(null),1100);return()=>window.clearTimeout(A)},[v]);const y=d.useMemo(()=>{const A=Vt,V=Kt,P=Ut,E=$t,z=typeof window<"u"?window.innerWidth:1024,Ne=typeof window<"u"?window.innerHeight:768,K=p.x+P+A<=z-E,G=p.y-P-V>=E;let Z=K?p.x+P:p.x-P,ae=G?p.y-P:p.y+P;const ee=`translate(${K?"0":"-100%"}, ${G?"-100%":"0"})`;return Z=Math.max(E+(K?0:A),Math.min(z-E-(K?A:0),Z)),ae=Math.max(E+(G?V:0),Math.min(Ne-E-(G?0:V),ae)),{left:`${Z}px`,top:`${ae}px`,transform:ee}},[p.x,p.y]),_=d.useMemo(()=>r.axElementSelectorExpression(i,g),[i,g]),I=g==="ios"?i.selectors.AXUniqueId:i.selectors.resourceId,x=g==="ios"?"AXUniqueId":"resourceId",F=d.useCallback(async(A,V)=>{if(!A)return;await Ht(A)&&W(V)},[]),q=r.axElementRoleLabel(i),X=i.label||i.value||q,Q=r.axElementSummary(i);return Xt.createPortal(h.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":O?"true":"false",style:y,onClick:A=>A.stopPropagation(),onMouseDown:A=>A.stopPropagation(),onMouseMove:A=>A.stopPropagation(),children:[h.jsxs("div",{className:"rc-inspect-card-header",children:[h.jsx("span",{className:"rc-inspect-card-role",children:q}),!i.enabled&&h.jsx("span",{className:"rc-inspect-card-tag",children:"disabled"}),i.focused&&h.jsx("span",{className:"rc-inspect-card-tag rc-inspect-card-tag-blue",children:"focused"})]}),h.jsx("p",{className:"rc-inspect-card-title",title:Q,children:X}),I&&h.jsxs("div",{className:"rc-inspect-card-row",children:[h.jsxs("span",{className:"rc-inspect-card-row-label",children:[x,":"]}),h.jsx("span",{className:"rc-inspect-card-row-value",children:I})]}),i.value&&i.value!==i.label&&h.jsxs("div",{className:"rc-inspect-card-row",children:[h.jsx("span",{className:"rc-inspect-card-row-label",children:"value:"}),h.jsx("span",{className:"rc-inspect-card-row-value",children:i.value})]}),h.jsxs("div",{className:"rc-inspect-card-row",children:[h.jsx("span",{className:"rc-inspect-card-row-label",children:"frame:"}),h.jsxs("span",{className:"rc-inspect-card-row-value",children:[Math.round(i.frame.width),"×",Math.round(i.frame.height)," @ ",Math.round(i.frame.x),",",Math.round(i.frame.y)]})]}),H&&h.jsxs("div",{className:"rc-inspect-card-actions",children:[h.jsx("button",{type:"button",className:"rc-inspect-card-btn rc-inspect-card-btn-primary",disabled:!R,onClick:()=>R?.(i,p),children:"Tap"}),h.jsx("button",{type:"button",className:v==="selector"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!_,title:_??"No usable selector for this element",onClick:()=>F(_??void 0,"selector"),children:v==="selector"?"Copied!":"Copy selector"}),h.jsx("button",{type:"button",className:v==="id"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!I,title:I??`No ${x}`,onClick:()=>F(I,"id"),children:v==="id"?"Copied!":`Copy ${x}`})]})]}),document.body)}),zt=d.memo(function({snapshot:i,geometry:g,highlightedId:p,selectedId:O,mode:H,cursorPosition:R,frozenCursorPosition:v,onSelectChange:W,onTapElement:y}){const _=H==="select",I=_?p!==null&&p!==O:p!==null,x=_?p??O:p,F=d.useMemo(()=>{const E=new Map;if(!i)return E;for(const z of i.elements)E.set(z.id,z);return E},[i]),q=d.useMemo(()=>x?F.get(x)??null:null,[x,F]);if(!(!!i&&!!g&&i.screen.width>0&&i.screen.height>0&&i.elements.length>0))return null;const Q=I?R:v??R,A=I,V=_&&!I&&O!==null,P=E=>{_&&E.target===E.currentTarget&&W(null,null)};return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:_?"rc-inspect-overlay rc-inspect-overlay-select":"rc-inspect-overlay",style:{left:`${g.left}px`,top:`${g.top}px`,width:`${g.width}px`,height:`${g.height}px`},onClick:P,children:i.elements.map(E=>h.jsx(jt,{element:E,screen:i.screen,highlighted:E.id===p,selected:E.id===O,selectable:_,onClick:W},E.id))}),q&&Q&&h.jsx(Ft,{element:q,platform:i.platform,anchor:Q,cursorAnchored:A,showActions:V,onTap:y})]})});function Bt(f,i){if(!i.startsWith("lim_st_"))return!1;try{const g=new URL(f).pathname.split("/").map(decodeURIComponent).find(y=>/^(ios|android)_[a-z0-9_]+$/.test(y));if(!g)return!1;const p=g.split("_")[0],O=i.slice(7).split(".");if(O.length!==3||O.some(y=>!y))return!1;const H=atob(O[1].replace(/-/g,"+").replace(/_/g,"/")),R=JSON.parse(new TextDecoder().decode(Uint8Array.from(H,y=>y.charCodeAt(0))));if(!R||typeof R!="object"||!("scopes"in R))return!1;const v=R.scopes;if(!Array.isArray(v)||!v.every(y=>typeof y=="string"))return!1;let W=!1;for(const y of v){const[_,I,x,F]=y.split(":");if(!(F!==void 0||_!==p&&_!=="*")&&!(I!==g&&I!=="*")){if(x==="stream"||x==="all")return!1;x==="watch"&&(W=!0)}}return W}catch{return!1}}const qt=d.lazy(()=>Promise.resolve().then(()=>require("./duo-view-BMPB0h3C.js")).then(f=>f.duoView)),De=f=>Object.entries(r.AMOTION_EVENT).find(([g,p])=>g.startsWith("ACTION_")&&p===f)?.[0]??String(f),at=1920,lt=1200,Gt=(f,i)=>f===at&&i===lt||f===lt&&i===at,Jt={ios:{videoBorderRadiusMultiplier:.15,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:.9678},landscape:{widthMultiplier:.9678}}},android:{videoBorderRadiusMultiplier:.13,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:.967},landscape:{widthMultiplier:.962}}}},Qt={"iphone-se":{videoBorderRadiusMultiplier:0,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:667/889},landscape:{widthMultiplier:667/889}}},"iphone-17e":{videoBorderRadiusMultiplier:47.33/452,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:844/888},landscape:{widthMultiplier:844/888}}}},Zt={videoBorderRadiusMultiplier:32/1837,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:2560/2798},landscape:{widthMultiplier:2560/2798}}};function en(f){const i=f.code,g=r.codeMap[i];if(!g)return r.debugWarn(`Unknown event.code: ${i}, key: ${f.key}`),null;let p=r.ANDROID_KEYS.META_NONE;const O=i>="KeyA"&&i<="KeyZ",H=f.getModifierState("CapsLock"),R=f.shiftKey;let v=R;return O&&(v=R!==H),v&&(p|=r.ANDROID_KEYS.META_SHIFT_ON),f.ctrlKey&&(p|=r.ANDROID_KEYS.META_CTRL_ON),f.altKey&&(p|=r.ANDROID_KEYS.META_ALT_ON),f.metaKey&&(p|=r.ANDROID_KEYS.META_META_ON),{keycode:g,metaState:p}}function tn(f,i){const g=Object.keys(f);return g.length===Object.keys(i).length&&g.every(p=>f[p]===i[p])}const nn=d.forwardRef(({className:f,url:i,token:g,sessionId:p,openUrl:O,watchOnly:H=!1,showFrame:R=!0,deviceModel:v,duoModelUrl:W,autoReconnect:y,jitterBufferTargetMs:_,onPlaybackStats:I,onTerminated:x,assets:F,onConnectionStateChange:q,inspectMode:X,onAxSnapshotChange:Q,onInspectSelectionChange:A,onAxStatusChange:V,axPollIntervalMs:P,axMaxBackoffMs:E,androidElementTreeOptions:z,onCameraDemandChange:Ne,onCameraStats:K,onTrace:G,microphoneEnabled:Z=!1,onMicrophoneStateChange:ae},Ve)=>{const Ke=d.useMemo(()=>Bt(i,g),[i,g]),ee=H||Ke,Ae=d.useRef(null),S=d.useRef(null),Ue=d.useRef(null),[dt,ut]=d.useState(!1),j=v==="iphone-duo"||dt,we=v==="iphone-duo"?v:void 0,Oe=d.useRef(null),[$e,ht]=d.useState(null),[Fe,ft]=d.useState(),[gt,pt]=d.useState(!1),[mt,vt]=d.useState(!1),[yt,Et]=d.useState(!1),[xe,ze]=d.useState(!1),[Be,qe]=d.useState(!1),[Tt,Ge]=d.useState({}),Ye=d.useRef(null),C=d.useRef(new Map),te=d.useRef(!1),[Nt,At]=d.useState(!1),b=d.useRef(null),le=d.useRef(null),ve=d.useRef({handle:()=>{},end:()=>{}}),[ne,Re]=d.useState(null),[Je,Pe]=d.useState(null),[Le,ye]=d.useState(null),[ke,Ie]=d.useState(null),[wt,Qe]=d.useState(null),[Ot,Ze]=d.useState(null),be=d.useRef(null),B=d.useRef(void 0),et=e=>{be.current=e,B.current===void 0&&(B.current=window.requestAnimationFrame(()=>{B.current=void 0,Ze(be.current)}))},[Rt,de]=d.useState(null),oe=d.useRef(null);oe.current=Je;const ue=d.useRef(A);ue.current=A;const re=X===!0||X==="hover-only",tt=d.useRef(re);tt.current=re;const It=X==="hover-only"?"hover-only":"select",U=d.useMemo(()=>r.detectPlatform(i),[i]),bt=d.useMemo(()=>p||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[p]),Ee=U==="ios"&&v&&v!=="iphone-duo"?v:void 0,he=U==="android"&&Be?Zt:Ee?Qt[Ee]:Jt[U],fe=F?.[U],nt=Ee&&fe?.modelFrames?.[Ee],ot=U==="android"&&Be?xe?fe?.tabletFrameLandscape:fe?.tabletFrame:Ee?xe?nt?.frameLandscape:nt?.frame:xe?fe?.frameLandscape:fe?.frame,rt=fe?.loadingLogo,Me=!j&&R&&!!ot,T=d.useRef(null),$=e=>T.current?.sendControl(e),We=(e,t)=>T.current?.sendDuoControl(e,t)??Promise.reject(new Error("Simulator disconnected")),it=-10,ct=(e,t)=>{const o=Te();if(!o)return;const n=pe(o,e,t);if(!n)return;const{videoX:s,videoY:l,videoWidth:c,videoHeight:u}=n,a=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_DOWN,it,c,u,s,l,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);a&&$(a),window.setTimeout(()=>{const m=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_UP,it,c,u,s,l,0,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);m&&$(m)},60)},Mt=(e,t)=>{const o=Te();if(!o||t.screen.width<=0||t.screen.height<=0)return;const n=e.frame.x+e.frame.width/2,s=e.frame.y+e.frame.height/2,l=n/t.screen.width*o.actualWidth,c=s/t.screen.height*o.actualHeight,u=o.videoRect.left+o.offsetX+l,a=o.videoRect.top+o.offsetY+c;ct(u,a)},_e=-1,Se=-2,ie=-3,ge=(e,t,o,n,s,l)=>{const c=r.createTouchControlMessage(e,t,o,n,s,l,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);c&&(r.debugLog("[rc-touch] sendSingleTouch",{action:e,actionName:De(e),pointerId:t,x:s,y:l,video:{width:o,height:n}}),$(c))},ce=(e,t,o)=>{if(!o)return;const{videoX:n,videoY:s,videoWidth:l,videoHeight:c}=o;let u=null,a=null,m=1;const M=r.AMOTION_EVENT.BUTTON_PRIMARY;switch(t){case"down":e!==ie&&ve.current.end(),u=C.current.size===0?r.AMOTION_EVENT.ACTION_DOWN:r.AMOTION_EVENT.ACTION_POINTER_DOWN,a={x:n,y:s},C.current.set(e,a),e===-1&&S.current?.focus();break;case"move":C.current.has(e)&&(u=r.AMOTION_EVENT.ACTION_MOVE,a={x:n,y:s},C.current.set(e,a));break;case"up":case"cancel":C.current.has(e)&&(a=C.current.get(e),C.current.delete(e),t==="cancel"?u=r.AMOTION_EVENT.ACTION_CANCEL:u=C.current.size===0?r.AMOTION_EVENT.ACTION_UP:r.AMOTION_EVENT.ACTION_POINTER_UP);break}if(u!==null&&a!==null){r.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:t,action:u,actionName:De(u),positionToSend:a,video:{width:l,height:c},altHeld:te.current,activePointersAfter:Array.from(C.current.entries()).map(([Y,w])=>({id:Y,x:w.x,y:w.y}))});const N=r.createTouchControlMessage(u,e,l,c,a.x,a.y,m,M,M);N&&(r.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:De(u),byteLength:N.byteLength}),$(N))}else(t==="up"||t==="cancel")&&C.current.delete(e)},Xe=e=>{if(te.current!==e&&(te.current=e,At(e),e||Re(null),r.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from(C.current.keys())}),U==="ios"&&T.current?.getState().controlReady)){const t=e?r.ANDROID_KEYS.ACTION_DOWN:r.ANDROID_KEYS.ACTION_UP,o=r.createInjectKeycodeMessage(t,r.ANDROID_KEYS.KEYCODE_ALT_LEFT,0,r.ANDROID_KEYS.META_NONE);r.debugLog("[rc-touch][alt] sending Indigo modifier keycode",{action:t,keycode:r.ANDROID_KEYS.KEYCODE_ALT_LEFT}),o&&$(o)}},Te=()=>{const e=S.current,t=Ae.current;if(!e||!t)return null;const o=e.videoWidth,n=e.videoHeight;if(!o||!n)return null;const s=e.getBoundingClientRect(),l=t.getBoundingClientRect(),c=s.width,u=s.height,a=o/n,m=c/u;let M=c,N=u;a>m?N=c/a:M=u*a;const Y=(c-M)/2,w=(u-N)/2;return{videoWidth:o,videoHeight:n,videoRect:s,containerRect:l,actualWidth:M,actualHeight:N,offsetX:Y,offsetY:w}},pe=(e,t,o)=>{const n=t-e.videoRect.left-e.offsetX,s=o-e.videoRect.top-e.offsetY,l=Math.max(0,Math.min(e.actualWidth,n)),c=Math.max(0,Math.min(e.actualHeight,s)),u=Math.max(0,Math.min(e.videoWidth,l/e.actualWidth*e.videoWidth)),a=Math.max(0,Math.min(e.videoHeight,c/e.actualHeight*e.videoHeight));return{videoX:u,videoY:a,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},_t=(e,t,o)=>{const n=t-e.videoRect.left-e.offsetX,s=o-e.videoRect.top-e.offsetY,l=Math.max(0,Math.min(e.actualWidth,n)),c=Math.max(0,Math.min(e.actualHeight,s)),u=Math.max(0,Math.min(e.videoWidth,l/e.actualWidth*e.videoWidth)),a=Math.max(0,Math.min(e.videoHeight,c/e.actualHeight*e.videoHeight)),m=e.videoWidth-u,M=e.videoHeight-a,N=e.videoRect.left+e.offsetX,Y=e.videoRect.top+e.offsetY,w=N-e.containerRect.left+l,D=Y-e.containerRect.top+c,se=N-e.containerRect.left+(e.actualWidth-l),k=Y-e.containerRect.top+(e.actualHeight-c);return{containerX:w,containerY:D,mirrorContainerX:se,mirrorContainerY:k,videoX:u,videoY:a,mirrorVideoX:m,mirrorVideoY:M,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},St=(e,t,o,n,s,l,c)=>{const u=r.createTwoFingerTouchControlMessage(e,t,o,n,s,l,c);r.debugLog("[rc-touch2] sendTwoFingerMessage (iOS)",{actionName:De(e),video:{width:t,height:o},p0:{x:n,y:s},p1:{x:l,y:c},byteLength:u.byteLength}),$(u)},me=(e,t,o,n,s,l,c,u,a)=>{if(r.debugLog("[rc-touch2] applyTwoFingerEvent",{platform:U,eventType:e,video:{width:t,height:o},p0:{x:n,y:s,id:u},p1:{x:l,y:c,id:a}}),e==="down"&&ve.current.end(),U==="ios"){const m=e==="down"?r.AMOTION_EVENT.ACTION_DOWN:e==="move"?r.AMOTION_EVENT.ACTION_MOVE:r.AMOTION_EVENT.ACTION_UP;St(m,t,o,n,s,l,c)}else e==="down"?(ge(r.AMOTION_EVENT.ACTION_DOWN,u,t,o,n,s),ge(r.AMOTION_EVENT.ACTION_POINTER_DOWN,a,t,o,l,c)):e==="move"?(ge(r.AMOTION_EVENT.ACTION_MOVE,u,t,o,n,s),ge(r.AMOTION_EVENT.ACTION_MOVE,a,t,o,l,c)):(ge(r.AMOTION_EVENT.ACTION_POINTER_UP,a,t,o,l,c),ge(r.AMOTION_EVENT.ACTION_UP,u,t,o,n,s))},Ct=(e,t,o)=>{if(!te.current){ne!==null&&Re(null);return}const n=_t(e,t,o);Re(n)},Dt=(e,t,o)=>{const n=oe.current;if(!n||n.screen.width<=0||n.screen.height<=0)return null;const s=t-e.videoRect.left-e.offsetX,l=o-e.videoRect.top-e.offsetY;if(s<0||l<0||s>e.actualWidth||l>e.actualHeight)return null;const c=s/e.actualWidth*n.screen.width,u=l/e.actualHeight*n.screen.height;return r.axElementAtPoint(n,c,u)},J=e=>{if(j)return;e.preventDefault(),e.stopPropagation();const t=Te();if((X===!0||X==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(et({x:e.clientX,y:e.clientY}),t){const n=Dt(t,e.clientX,e.clientY);ye(n?.id??null)}}else e.type==="mouseleave"&&(et(null),ye(null));if(X!==!0&&(!("touches"in e)&&t&&(e.type==="mousemove"?Ct(t,e.clientX,e.clientY):e.type==="mouseleave"&&Re(null)),!(!T.current?.getState().controlReady||!S.current||!t)))if("touches"in e){const n=e.touches,s=e.changedTouches;let l;switch(e.type){case"touchstart":l="down";break;case"touchmove":l="move";break;case"touchend":l="up";break;case"touchcancel":l="cancel";break;default:return}if(n.length===2){const c=n[0],u=n[1],a=pe(t,c.clientX,c.clientY),m=pe(t,u.clientX,u.clientY);if(!a||!m)return;b.current?b.current.source==="real-touch"&&(b.current.finger0={x:a.videoX,y:a.videoY},b.current.finger1={x:m.videoX,y:m.videoY},me("move",a.videoWidth,a.videoHeight,a.videoX,a.videoY,m.videoX,m.videoY,b.current.pointerId0,b.current.pointerId1)):(b.current={finger0:{x:a.videoX,y:a.videoY},finger1:{x:m.videoX,y:m.videoY},videoSize:{width:a.videoWidth,height:a.videoHeight},source:"real-touch",pointerId0:c.identifier,pointerId1:u.identifier},me("down",a.videoWidth,a.videoHeight,a.videoX,a.videoY,m.videoX,m.videoY,c.identifier,u.identifier))}else if(n.length<2&&b.current?.source==="real-touch"){const c=b.current;me("up",c.videoSize.width,c.videoSize.height,c.finger0.x,c.finger0.y,c.finger1.x,c.finger1.y,c.pointerId0,c.pointerId1),b.current=null;return}else{if(n.length>2)return;{const c=s[0];if(c){const u=pe(t,c.clientX,c.clientY);ce(c.identifier,l,u)}}}}else{let s=null;const l=b.current?.source==="alt-mouse";switch(e.type){case"mousedown":e.button===0&&(s="down");break;case"mousemove":(l||C.current.has(-1))&&(s="move");break;case"mouseup":e.button===0&&(s="up");break;case"mouseleave":(l||C.current.has(-1))&&(s="up");break}if(s){const c=pe(t,e.clientX,e.clientY);if(!c)return;r.debugLog("[rc-touch][mouse] event",{domType:e.type,eventType:s,button:e.button,buttons:e.buttons,client:{x:e.clientX,y:e.clientY},altHeldRef:te.current,inTwoFingerMode:l,geometry:{videoX:c.videoX,videoY:c.videoY,videoWidth:c.videoWidth,videoHeight:c.videoHeight},activePointerIds:Array.from(C.current.keys())}),te.current||l?xt(s,c):ce(-1,s,c)}}},xt=(e,t)=>{const{videoX:o,videoY:n,videoWidth:s,videoHeight:l}=t,c=s-o,u=l-n;if(e==="down"){b.current={finger0:{x:o,y:n},finger1:{x:c,y:u},videoSize:{width:s,height:l},source:"alt-mouse",pointerId0:_e,pointerId1:Se},S.current?.focus(),me("down",s,l,o,n,c,u,_e,Se);return}if(e==="move"){b.current?.source==="alt-mouse"&&(b.current.finger0={x:o,y:n},b.current.finger1={x:c,y:u},me("move",s,l,o,n,c,u,_e,Se));return}if(e==="up"||e==="cancel"){const a=b.current;if(a?.source==="alt-mouse"){const{finger0:m,finger1:M,videoSize:N}=a;me("up",N.width,N.height,m.x,m.y,M.x,M.y,_e,Se),b.current=null}return}},Yt=150,st=()=>{const e=le.current;e&&(window.clearTimeout(e.endTimer),ce(ie,"up",e.pos),le.current=null)},Pt=e=>{if(!T.current?.getState().controlReady||e.ctrlKey||te.current||b.current)return;const t=C.current.size;if(t>1||t===1&&!C.current.has(ie))return;const o=Te();if(!o)return;const n=e.clientX-o.videoRect.left-o.offsetX,s=e.clientY-o.videoRect.top-o.offsetY;if(n<0||n>o.actualWidth||s<0||s>o.actualHeight)return;const l=pe(o,e.clientX,e.clientY);if(!l)return;e.preventDefault();const c=(e.deltaMode===1?16:e.deltaMode===2?o.actualWidth:1)*(o.videoWidth/o.actualWidth),u=(e.deltaMode===1?16:e.deltaMode===2?o.actualHeight:1)*(o.videoHeight/o.actualHeight),a=-e.deltaX*c,m=-e.deltaY*u,M=k=>{window.clearTimeout(k.endTimer),k.endTimer=window.setTimeout(st,Yt)};if(a===0&&m===0){le.current&&M(le.current);return}const N=()=>({videoWidth:l.videoWidth,videoHeight:l.videoHeight,videoX:Math.abs(a)>Math.abs(m)?Math.min(Math.max(l.videoX,l.videoWidth*.2),l.videoWidth*.8):l.videoX,videoY:Math.abs(m)>=Math.abs(a)?Math.min(Math.max(l.videoY,l.videoHeight*.2),l.videoHeight*.8):l.videoY}),Y=k=>({...k,videoX:Math.min(Math.max(k.videoX+a,0),k.videoWidth),videoY:Math.min(Math.max(k.videoY+m,0),k.videoHeight)});let w=le.current;if(w)window.clearTimeout(w.endTimer);else{const k=N();ce(ie,"down",k),w={pos:k,endTimer:0},le.current=w}let D=w.pos,se=Y(D);se.videoX===D.videoX&&se.videoY===D.videoY&&(ce(ie,"up",D),D=N(),ce(ie,"down",D),se=Y(D)),ce(ie,"move",se),w.pos=se,M(w)};d.useEffect(()=>{ve.current={handle:Pt,end:st}}),d.useEffect(()=>{const e=Ae.current;if(!e)return;const t=o=>ve.current.handle(o);return e.addEventListener("wheel",t,{passive:!1}),()=>{ve.current.end(),e.removeEventListener("wheel",t)}},[]),d.useEffect(()=>{const e=n=>{n.key==="Alt"&&Xe(!0)},t=n=>{n.key==="Alt"&&Xe(!1)},o=()=>{Xe(!1)};return window.addEventListener("keydown",e,!0),window.addEventListener("keyup",t,!0),window.addEventListener("blur",o),()=>{window.removeEventListener("keydown",e,!0),window.removeEventListener("keyup",t,!0),window.removeEventListener("blur",o)}},[]);const Ce=e=>{e.preventDefault(),e.stopPropagation();const t=document.activeElement===S.current||j&&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:t}),!t){r.debugWarn("Simulator input not focused, skipping keyboard event");return}if(!T.current?.getState().controlReady){r.debugWarn("Data channel not ready for keyboard event:",T.current?.getState().connection);return}if(e.type==="keydown"){if(e.key.toLowerCase()==="v"&&(e.metaKey||e.ctrlKey)){r.debugLog("Paste shortcut detected"),navigator.clipboard.readText().then(n=>{if(n){r.debugLog("Pasting text via SET_CLIPBOARD:",n.substring(0,20)+(n.length>20?"...":""));const s=r.createSetClipboardMessage(n,!0);$(s)}}).catch(n=>{console.error("Failed to read clipboard contents: ",n)});return}if(e.key.toLowerCase()==="m"&&(e.metaKey||e.ctrlKey)){r.debugLog("Menu shortcut detected");const n=r.createInjectKeycodeMessage(r.ANDROID_KEYS.ACTION_DOWN,r.ANDROID_KEYS.MENU,0,r.ANDROID_KEYS.META_NONE);$(n);const s=r.createInjectKeycodeMessage(r.ANDROID_KEYS.ACTION_UP,r.ANDROID_KEYS.MENU,0,r.ANDROID_KEYS.META_NONE);$(s);return}}const o=en(e);if(o){const{keycode:n,metaState:s}=o,l=e.type==="keydown"?r.ANDROID_KEYS.ACTION_DOWN:r.ANDROID_KEYS.ACTION_UP;r.debugLog(`Sending Keycode: key=${e.key}, code=${n}, action=${l}, meta=${s}`);const c=r.createInjectKeycodeMessage(l,n,0,s);$(c)}else r.debugLog(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`)},Lt=e=>{e.stopPropagation(),T.current?.reconnect()},L=d.useRef({onAxSnapshotChange:Q,onAxStatusChange:V,onCameraDemandChange:Ne,onCameraStats:K,onMicrophoneStateChange:ae,onTrace:G,onTerminated:x,onConnectionStateChange:q,onPlaybackStats:I});L.current={onAxSnapshotChange:Q,onAxStatusChange:V,onCameraDemandChange:Ne,onCameraStats:K,onMicrophoneStateChange:ae,onTrace:G,onTerminated:x,onConnectionStateChange:q,onPlaybackStats:I};const He=!!G;d.useEffect(()=>{Ye.current=null,ze(!1),qe(!1),Ge({})},[i,we]),d.useEffect(()=>{let e=!0;oe.current!==null&&(oe.current=null,Pe(null),r.safeInvoke("onAxSnapshotChange",L.current.onAxSnapshotChange,null));const t=r.createDeviceStream({url:i,token:g,sessionId:bt,watchOnly:ee,deviceModel:we,autoReconnect:y,jitterBufferTargetMs:_,openUrl:O,inspectMode:X,axPollIntervalMs:P,axMaxBackoffMs:E,androidElementTreeOptions:z,microphoneEnabled:Z,onStateChange:n=>{(n.videoReady||n.connection==="idle"||n.connection==="connecting"||n.connection==="reconnecting")&&pt(n.videoReady),vt(n.connection==="failed"),Et(n.connection==="terminated"),ut(n.duo),ht(n.duoState),ft(n.duoError)},onAxSnapshotChange:n=>{e&&(Pe(s=>r.axSnapshotsEqual(s,n)?s:n),L.current.onAxSnapshotChange?.(n))},onAxStatusChange:(...n)=>L.current.onAxStatusChange?.(...n),onCameraDemandChange:(...n)=>L.current.onCameraDemandChange?.(...n),onCameraStats:K?(...n)=>L.current.onCameraStats?.(...n):void 0,onMicrophoneStateChange:(...n)=>L.current.onMicrophoneStateChange?.(...n),onTrace:He?(...n)=>L.current.onTrace?.(...n):void 0,onTerminated:()=>L.current.onTerminated?.(),onConnectionStateChange:(...n)=>L.current.onConnectionStateChange?.(...n),onPlaybackStats:I?(...n)=>L.current.onPlaybackStats?.(...n):void 0});T.current=t;const o=S.current?t.attachVideo(S.current):void 0;return t.start(),()=>{e=!1,t.dispose(),o?.(),T.current=null}},[i,p,we,He,ee]),d.useEffect(()=>{if(j&&Oe.current)return T.current?.attachVideo(Oe.current,"inner")},[j,i,p,we,He,ee]),d.useEffect(()=>{T.current?.updateOptions({token:g,openUrl:O,axPollIntervalMs:P,axMaxBackoffMs:E,androidElementTreeOptions:z,autoReconnect:y,jitterBufferTargetMs:_,microphoneEnabled:Z,inspectMode:X,onPlaybackStats:I?(...e)=>L.current.onPlaybackStats?.(...e):void 0,onCameraStats:K?(...e)=>L.current.onCameraStats?.(...e):void 0})},[g,y,_,Z,X,!!I,!!K,O,P,E,z]);const je=()=>{if(!tt.current)return;const e=Te();if(!e){Qe(null);return}const t={left:e.videoRect.left-e.containerRect.left+e.offsetX,top:e.videoRect.top-e.containerRect.top+e.offsetY,width:e.actualWidth,height:e.actualHeight};Qe(o=>o&&o.left===t.left&&o.top===t.top&&o.width===t.width&&o.height===t.height?o:t)};d.useEffect(()=>{const e=S.current,t=Ue.current,o=Ae.current;if(!e)return;const n=u=>Ge(a=>tn(a,u)?a:u),s=()=>{const u=e.videoWidth>0&&e.videoHeight>0;u&&(Ye.current={width:e.videoWidth,height:e.videoHeight});const a=Ye.current,m=a?`${a.width} / ${a.height}`:void 0;if(!Me||!t){n(!u&&a?{aspectRatio:m,contain:"size",containIntrinsicSize:`${a.width}px ${a.height}px`}:{}),je();return}const M=t.clientWidth,N=t.clientHeight;if(M===0||N===0)return;const Y=a?a.width>a.height:!1;ze(Y),qe(U==="android"&&!!a&&Gt(a.width,a.height));const w=Y?he.videoPosition.landscape:he.videoPosition.portrait;let D={aspectRatio:m};w.heightMultiplier?(D.height=`${N*w.heightMultiplier}px`,D.width="auto"):w.widthMultiplier&&(D.width=`${M*w.widthMultiplier}px`,D.height="auto"),D.borderRadius=`${Y?N*he.videoBorderRadiusMultiplier:M*he.videoBorderRadiusMultiplier}px`,n(D),je()},l=new ResizeObserver(()=>{s()});t&&l.observe(t),l.observe(e),o&&l.observe(o),t&&t.addEventListener("load",s),e.addEventListener("loadedmetadata",s),e.addEventListener("resize",s);const c=()=>T.current?.bumpActivity();return e.addEventListener("resize",c),s(),()=>{l.disconnect(),e.removeEventListener("loadedmetadata",s),e.removeEventListener("resize",s),e.removeEventListener("resize",c),t&&t.removeEventListener("load",s)}},[he,Me,i,v]),d.useEffect(()=>{re?je():(Pe(null),ye(null),Ie(null),Ze(null),de(null),be.current=null,B.current!==void 0&&(window.cancelAnimationFrame(B.current),B.current=void 0))},[re]),d.useEffect(()=>()=>{B.current!==void 0&&(window.cancelAnimationFrame(B.current),B.current=void 0)},[]),d.useEffect(()=>{if(!re)return;const e=t=>{t.key==="Escape"&&(ke||Le)&&(Ie(null),ye(null),de(null),r.safeInvoke("onInspectSelectionChange",ue.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[re,ke,Le]);const kt=()=>{S.current&&S.current.focus()};d.useImperativeHandle(Ve,()=>({openUrl:e=>T.current?.openUrl(e),sendKeyEvent:e=>T.current?.sendKeyEvent(e),screenshot:e=>T.current?.screenshot(e)??Promise.reject(new Error("Simulator disconnected")),terminateApp:e=>T.current?.terminateApp(e)??Promise.reject(new Error("Simulator disconnected")),reconnect:()=>T.current?.reconnect(),refreshAxTree:()=>T.current?.refreshAxTree()??Promise.reject(new Error("Simulator disconnected")),getAxSnapshot:()=>T.current?.getAxSnapshot()??null,setInspectHighlight:e=>{ye(e?.id??null)},setInspectSelection:e=>{Ie(e?.id??null),de(e?be.current:null);const t=oe.current;e&&t?r.safeInvoke("onInspectSelectionChange",ue.current,{element:e,snapshot:t}):r.safeInvoke("onInspectSelectionChange",ue.current,null)},getAxStatus:()=>T.current?.getAxStatus()??"idle"}));const Wt=Nt&&ne!==null;return h.jsxs("div",{ref:Ae,className:["rc-container",f].filter(Boolean).join(" "),style:{touchAction:"none"},onMouseDown:J,onMouseMove:J,onMouseUp:J,onMouseLeave:J,onTouchStart:J,onTouchMove:J,onTouchEnd:J,onTouchCancel:J,children:[Wt&&ne&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"rc-touch-indicator",style:{left:`${ne.containerX}px`,top:`${ne.containerY}px`}}),h.jsx("div",{className:"rc-touch-indicator",style:{left:`${ne.mirrorContainerX}px`,top:`${ne.mirrorContainerY}px`}})]}),Me&&h.jsx("img",{ref:Ue,src:ot,alt:"",className:U==="ios"?"rc-phone-frame rc-phone-frame-ios":"rc-phone-frame",draggable:!1}),h.jsx("video",{ref:S,className:["rc-video",!Me&&"rc-video-frameless",!gt&&"rc-video-loading"].filter(Boolean).join(" "),style:{...Tt,...j?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...rt?{backgroundImage:`url("${rt}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:he.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:j?-1:0,onKeyDown:Ce,onKeyUp:Ce,onClick:kt,onFocus:()=>{S.current&&(S.current.style.outline="none")},onBlur:()=>{S.current&&(S.current.style.outline="none")}}),j&&h.jsx("video",{ref:Oe,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),j&&$e&&h.jsx(d.Suspense,{fallback:h.jsx("div",{children:"Loading iPhone Duo…"}),children:h.jsx(qt,{watchOnly:ee,showFrame:R,modelUrl:W,outer:S.current,inner:Oe.current,state:$e,setAngle:e=>We("setHingeAngle",{angleDegrees:e}),setOrientation:e=>We("setDuoOrientation",{orientation:e}),button:(e,t)=>We("performActions",{actions:[{type:t?"buttonDown":"buttonUp",button:e}]}),touch:(e,t,o,n)=>{T.current?.sendDisplayTouch(e,t,o,n)},onKeyDown:Ce,onKeyUp:Ce})}),j&&Fe&&h.jsx("div",{role:"alert",className:"rc-duo-error",children:Fe}),!j&&re&&h.jsx(zt,{snapshot:Je,geometry:wt,highlightedId:Le,selectedId:ke,mode:It,cursorPosition:Ot,frozenCursorPosition:Rt,onSelectChange:(e,t)=>{Ie(e?.id??null),e&&t?de(t):e||de(null);const o=oe.current;e&&o?r.safeInvoke("onInspectSelectionChange",ue.current,{element:e,snapshot:o}):r.safeInvoke("onInspectSelectionChange",ue.current,null)},onTapElement:ee?void 0:((e,t)=>{if(t){ct(t.x,t.y);return}const o=oe.current;o&&Mt(e,o)})}),yt?h.jsxs("div",{className:"rc-terminated",role:"status",children:[h.jsx("div",{className:"rc-terminated-title",children:"Instance terminated"}),h.jsx("div",{className:"rc-terminated-message",children:"This instance no longer exists and can't be reconnected."})]}):mt&&h.jsx("button",{type:"button",className:"rc-retry-button",onClick:Lt,children:"Retry"})]})});exports.RemoteControl=nn;