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