@limrun/ui 0.20.0 → 0.20.1

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