@limrun/ui 0.20.3 → 0.20.5

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