@limrun/ui 0.20.8 → 0.21.0

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