@limrun/ui 0.20.3 → 0.20.5

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