@limrun/ui 0.19.0 → 0.20.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.
@@ -0,0 +1 @@
1
+ "use strict";require('./index.css');const g=require("react/jsx-runtime"),r=require("./core-DkhLItUD.js"),l=require("react"),Yt=require("react-dom");function ot(h){var i,m,f="";if(typeof h=="string"||typeof h=="number")f+=h;else if(typeof h=="object")if(Array.isArray(h)){var w=h.length;for(i=0;i<w;i++)h[i]&&(m=ot(h[i]))&&(f&&(f+=" "),f+=m)}else for(m in h)h[m]&&(f&&(f+=" "),f+=m);return f}function ie(){for(var h,i,m=0,f="",w=arguments.length;m<w;m++)(h=arguments[m])&&(i=ot(h))&&(f&&(f+=" "),f+=i);return f}const Pt=async h=>{if(!h)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(h),!0}catch{}try{const i=document.createElement("textarea");i.value=h,i.style.position="fixed",i.style.opacity="0",document.body.appendChild(i),i.select();const m=document.execCommand("copy");return document.body.removeChild(i),m}catch{return!1}},kt=l.memo(function({element:i,screen:m,highlighted:f,selected:w,selectable:H,onClick:b}){const N=r.clampAxFrameForScreen(i.frame,m);if(!N)return null;const L=r.axElementSummary(i);return g.jsx("button",{type:"button",className:ie("rc-inspect-box",!i.enabled&&"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":f?"true":"false","data-selected":w?"true":"false","aria-label":L,onClick:P=>{H&&(P.preventDefault(),P.stopPropagation(),b(i,{x:P.clientX,y:P.clientY}))},style:{left:`${N.x/m.width*100}%`,top:`${N.y/m.height*100}%`,width:`${N.width/m.width*100}%`,height:`${N.height/m.height*100}%`}})},(h,i)=>h.highlighted===i.highlighted&&h.selected===i.selected&&h.selectable===i.selectable&&h.screen.width===i.screen.width&&h.screen.height===i.screen.height&&h.onClick===i.onClick&&r.axElementsEqual(h.element,i.element)),Lt=260,Xt=220,Wt=6,Ht=8,Vt=l.memo(function({element:i,platform:m,anchor:f,cursorAnchored:w,showActions:H,onTap:b}){const[N,L]=l.useState(null);l.useEffect(()=>{if(!N)return;const A=window.setTimeout(()=>L(null),1100);return()=>window.clearTimeout(A)},[N]);const P=l.useMemo(()=>{const A=Lt,X=Xt,D=Wt,v=Ht,U=typeof window<"u"?window.innerWidth:1024,Z=typeof window<"u"?window.innerHeight:768,z=f.x+D+A<=U-v,B=f.y-D-X>=v;let ce=z?f.x+D:f.x-D,me=B?f.y-D:f.y+D;const Ae=`translate(${z?"0":"-100%"}, ${B?"-100%":"0"})`;return ce=Math.max(v+(z?0:A),Math.min(U-v-(z?A:0),ce)),me=Math.max(v+(B?X:0),Math.min(Z-v-(B?0:X),me)),{left:`${ce}px`,top:`${me}px`,transform:Ae}},[f.x,f.y]),M=l.useMemo(()=>r.axElementSelectorExpression(i,m),[i,m]),k=m==="ios"?i.selectors.AXUniqueId:i.selectors.resourceId,j=m==="ios"?"AXUniqueId":"resourceId",F=l.useCallback(async(A,X)=>{if(!A)return;await Pt(A)&&L(X)},[]),C=r.axElementRoleLabel(i),ge=i.label||i.value||C,Q=r.axElementSummary(i);return Yt.createPortal(g.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":w?"true":"false",style:P,onClick:A=>A.stopPropagation(),onMouseDown:A=>A.stopPropagation(),onMouseMove:A=>A.stopPropagation(),children:[g.jsxs("div",{className:"rc-inspect-card-header",children:[g.jsx("span",{className:"rc-inspect-card-role",children:C}),!i.enabled&&g.jsx("span",{className:"rc-inspect-card-tag",children:"disabled"}),i.focused&&g.jsx("span",{className:"rc-inspect-card-tag rc-inspect-card-tag-blue",children:"focused"})]}),g.jsx("p",{className:"rc-inspect-card-title",title:Q,children:ge}),k&&g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsxs("span",{className:"rc-inspect-card-row-label",children:[j,":"]}),g.jsx("span",{className:"rc-inspect-card-row-value",children:k})]}),i.value&&i.value!==i.label&&g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsx("span",{className:"rc-inspect-card-row-label",children:"value:"}),g.jsx("span",{className:"rc-inspect-card-row-value",children:i.value})]}),g.jsxs("div",{className:"rc-inspect-card-row",children:[g.jsx("span",{className:"rc-inspect-card-row-label",children:"frame:"}),g.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&&g.jsxs("div",{className:"rc-inspect-card-actions",children:[g.jsx("button",{type:"button",className:"rc-inspect-card-btn rc-inspect-card-btn-primary",onClick:()=>b(i,f),children:"Tap"}),g.jsx("button",{type:"button",className:ie("rc-inspect-card-btn",N==="selector"&&"rc-inspect-card-btn-copied"),disabled:!M,title:M??"No usable selector for this element",onClick:()=>F(M??void 0,"selector"),children:N==="selector"?"Copied!":"Copy selector"}),g.jsx("button",{type:"button",className:ie("rc-inspect-card-btn",N==="id"&&"rc-inspect-card-btn-copied"),disabled:!k,title:k??`No ${j}`,onClick:()=>F(k,"id"),children:N==="id"?"Copied!":`Copy ${j}`})]})]}),document.body)}),jt=l.memo(function({snapshot:i,geometry:m,highlightedId:f,selectedId:w,mode:H,cursorPosition:b,frozenCursorPosition:N,onSelectChange:L,onTapElement:P}){const M=H==="select",k=M?f!==null&&f!==w:f!==null,j=M?f??w:f,F=l.useMemo(()=>{const v=new Map;if(!i)return v;for(const U of i.elements)v.set(U.id,U);return v},[i]),C=l.useMemo(()=>j?F.get(j)??null:null,[j,F]);if(!(!!i&&!!m&&i.screen.width>0&&i.screen.height>0&&i.elements.length>0))return null;const Q=k?b:N??b,A=k,X=M&&!k&&w!==null,D=v=>{M&&v.target===v.currentTarget&&L(null,null)};return g.jsxs(g.Fragment,{children:[g.jsx("div",{className:ie("rc-inspect-overlay",M&&"rc-inspect-overlay-select"),style:{left:`${m.left}px`,top:`${m.top}px`,width:`${m.width}px`,height:`${m.height}px`},onClick:D,children:i.elements.map(v=>g.jsx(kt,{element:v,screen:i.screen,highlighted:v.id===f,selected:v.id===w,selectable:M,onClick:L},v.id))}),C&&Q&&g.jsx(Vt,{element:C,platform:i.platform,anchor:Q,cursorAnchored:A,showActions:X,onTap:P})]})}),Kt=l.lazy(()=>Promise.resolve().then(()=>require("./duo-view-Bhr7zyWr.js")).then(h=>h.duoView)),Se=h=>Object.entries(r.AMOTION_EVENT).find(([m,f])=>m.startsWith("ACTION_")&&f===h)?.[0]??String(h),tt=1920,nt=1200,$t=(h,i)=>h===tt&&i===nt||h===nt&&i===tt,Ft={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 Ut(h){const i=h.code,m=r.codeMap[i];if(!m)return r.debugWarn(`Unknown event.code: ${i}, key: ${h.key}`),null;let f=r.ANDROID_KEYS.META_NONE;const w=i>="KeyA"&&i<="KeyZ",H=h.getModifierState("CapsLock"),b=h.shiftKey;let N=b;return w&&(N=b!==H),N&&(f|=r.ANDROID_KEYS.META_SHIFT_ON),h.ctrlKey&&(f|=r.ANDROID_KEYS.META_CTRL_ON),h.altKey&&(f|=r.ANDROID_KEYS.META_ALT_ON),h.metaKey&&(f|=r.ANDROID_KEYS.META_META_ON),{keycode:m,metaState:f}}const zt=l.forwardRef(({className:h,url:i,token:m,sessionId:f,openUrl:w,showFrame:H=!0,deviceModel:b,duoModelUrl:N,autoReconnect:L=!1,jitterBufferTargetMs:P,onPlaybackStats:M,onTerminated:k,assets:j,onConnectionStateChange:F,inspectMode:C,onAxSnapshotChange:ge,onInspectSelectionChange:Q,onAxStatusChange:A,axPollIntervalMs:X,axMaxBackoffMs:D,androidElementTreeOptions:v,onCameraDemandChange:U,onCameraStats:Z,onTrace:z,microphoneEnabled:B=!1,onMicrophoneStateChange:ce},me)=>{const pe=l.useRef(null),R=l.useRef(null),Ae=l.useRef(null),[rt,it]=l.useState(!1),W=b==="iphone-duo"||rt,we=l.useRef(null),[He,ct]=l.useState(null),[Ve,st]=l.useState(),[at,ut]=l.useState(!1),[lt,dt]=l.useState(!1),[ht,ft]=l.useState(!1),[je,Ke]=l.useState(!1),[gt,$e]=l.useState(!1),[mt,De]=l.useState({}),xe=l.useRef(null),_=l.useRef(new Map),J=l.useRef(!1),[pt,vt]=l.useState(!1),O=l.useRef(null),se=l.useRef(null),ve=l.useRef({handle:()=>{},end:()=>{}}),[ee,Oe]=l.useState(null),[Fe,Ye]=l.useState(null),[Pe,ye]=l.useState(null),[ke,Ie]=l.useState(null),[yt,Ue]=l.useState(null),[Et,ze]=l.useState(null),Re=l.useRef(null),K=l.useRef(void 0),Be=e=>{Re.current=e,K.current===void 0&&(K.current=window.requestAnimationFrame(()=>{K.current=void 0,ze(Re.current)}))},[Tt,ae]=l.useState(null),te=l.useRef(null);te.current=Fe;const ue=l.useRef(Q);ue.current=Q;const Ee=C===!0||C==="hover-only",Nt=C==="hover-only"?"hover-only":"select",q=l.useMemo(()=>r.detectPlatform(i),[i]),At=l.useMemo(()=>f||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[f]),le=Ft[q],Te=j?.[q],qe=q==="android"&&gt?je?Te?.tabletFrameLandscape:Te?.tabletFrame:je?Te?.frameLandscape:Te?.frame,Ge=Te?.loadingLogo,be=!W&&H&&!!qe,y=l.useRef(null),V=e=>y.current?.sendControl(e),Le=(e,n)=>y.current?.sendDuoControl(e,n)??Promise.reject(new Error("Simulator disconnected")),Qe=-10,Ze=(e,n)=>{const o=Ne();if(!o)return;const t=he(o,e,n);if(!t)return;const{videoX:s,videoY:a,videoWidth:c,videoHeight:u}=t,d=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_DOWN,Qe,c,u,s,a,1,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);d&&V(d),window.setTimeout(()=>{const p=r.createTouchControlMessage(r.AMOTION_EVENT.ACTION_UP,Qe,c,u,s,a,0,r.AMOTION_EVENT.BUTTON_PRIMARY,r.AMOTION_EVENT.BUTTON_PRIMARY);p&&V(p)},60)},wt=(e,n)=>{const o=Ne();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,d=o.videoRect.top+o.offsetY+c;Ze(u,d)},Me=-1,_e=-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:Se(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,d=null,p=1;const I=r.AMOTION_EVENT.BUTTON_PRIMARY;switch(n){case"down":e!==ne&&ve.current.end(),u=_.current.size===0?r.AMOTION_EVENT.ACTION_DOWN:r.AMOTION_EVENT.ACTION_POINTER_DOWN,d={x:t,y:s},_.current.set(e,d),e===-1&&R.current?.focus();break;case"move":_.current.has(e)&&(u=r.AMOTION_EVENT.ACTION_MOVE,d={x:t,y:s},_.current.set(e,d));break;case"up":case"cancel":_.current.has(e)&&(d=_.current.get(e),_.current.delete(e),n==="cancel"?u=r.AMOTION_EVENT.ACTION_CANCEL:u=_.current.size===0?r.AMOTION_EVENT.ACTION_UP:r.AMOTION_EVENT.ACTION_POINTER_UP);break}if(u!==null&&d!==null){r.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:n,action:u,actionName:Se(u),positionToSend:d,video:{width:a,height:c},altHeld:J.current,activePointersAfter:Array.from(_.current.entries()).map(([S,T])=>({id:S,x:T.x,y:T.y}))});const E=r.createTouchControlMessage(u,e,a,c,d.x,d.y,p,I,I);E&&(r.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:Se(u),byteLength:E.byteLength}),V(E))}else(n==="up"||n==="cancel")&&_.current.delete(e)},Xe=e=>{if(J.current!==e&&(J.current=e,vt(e),e||Oe(null),r.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from(_.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)}},Ne=()=>{const e=R.current,n=pe.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,d=o/t,p=c/u;let I=c,E=u;d>p?E=c/d:I=u*d;const S=(c-I)/2,T=(u-E)/2;return{videoWidth:o,videoHeight:t,videoRect:s,containerRect:a,actualWidth:I,actualHeight:E,offsetX:S,offsetY:T}},he=(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)),d=Math.max(0,Math.min(e.videoHeight,c/e.actualHeight*e.videoHeight));return{videoX:u,videoY:d,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Ot=(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)),d=Math.max(0,Math.min(e.videoHeight,c/e.actualHeight*e.videoHeight)),p=e.videoWidth-u,I=e.videoHeight-d,E=e.videoRect.left+e.offsetX,S=e.videoRect.top+e.offsetY,T=E-e.containerRect.left+a,$=S-e.containerRect.top+c,re=E-e.containerRect.left+(e.actualWidth-a),Y=S-e.containerRect.top+(e.actualHeight-c);return{containerX:T,containerY:$,mirrorContainerX:re,mirrorContainerY:Y,videoX:u,videoY:d,mirrorVideoX:p,mirrorVideoY:I,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},It=(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:Se(e),video:{width:n,height:o},p0:{x:t,y:s},p1:{x:a,y:c},byteLength:u.byteLength}),V(u)},fe=(e,n,o,t,s,a,c,u,d)=>{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:d}}),e==="down"&&ve.current.end(),q==="ios"){const p=e==="down"?r.AMOTION_EVENT.ACTION_DOWN:e==="move"?r.AMOTION_EVENT.ACTION_MOVE:r.AMOTION_EVENT.ACTION_UP;It(p,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,d,n,o,a,c)):e==="move"?(de(r.AMOTION_EVENT.ACTION_MOVE,u,n,o,t,s),de(r.AMOTION_EVENT.ACTION_MOVE,d,n,o,a,c)):(de(r.AMOTION_EVENT.ACTION_POINTER_UP,d,n,o,a,c),de(r.AMOTION_EVENT.ACTION_UP,u,n,o,t,s))},Rt=(e,n,o)=>{if(!J.current){ee!==null&&Oe(null);return}const t=Ot(e,n,o);Oe(t)},bt=(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=Ne();if((C===!0||C==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(Be({x:e.clientX,y:e.clientY}),n){const t=bt(n,e.clientX,e.clientY);ye(t?.id??null)}}else e.type==="mouseleave"&&(Be(null),ye(null));if(C!==!0&&(!("touches"in e)&&n&&(e.type==="mousemove"?Rt(n,e.clientX,e.clientY):e.type==="mouseleave"&&Oe(null)),!(!y.current?.getState().controlReady||!R.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],d=he(n,c.clientX,c.clientY),p=he(n,u.clientX,u.clientY);if(!d||!p)return;O.current?O.current.source==="real-touch"&&(O.current.finger0={x:d.videoX,y:d.videoY},O.current.finger1={x:p.videoX,y:p.videoY},fe("move",d.videoWidth,d.videoHeight,d.videoX,d.videoY,p.videoX,p.videoY,O.current.pointerId0,O.current.pointerId1)):(O.current={finger0:{x:d.videoX,y:d.videoY},finger1:{x:p.videoX,y:p.videoY},videoSize:{width:d.videoWidth,height:d.videoHeight},source:"real-touch",pointerId0:c.identifier,pointerId1:u.identifier},fe("down",d.videoWidth,d.videoHeight,d.videoX,d.videoY,p.videoX,p.videoY,c.identifier,u.identifier))}else if(t.length<2&&O.current?.source==="real-touch"){const c=O.current;fe("up",c.videoSize.width,c.videoSize.height,c.finger0.x,c.finger0.y,c.finger1.x,c.finger1.y,c.pointerId0,c.pointerId1),O.current=null;return}else{if(t.length>2)return;{const c=s[0];if(c){const u=he(n,c.clientX,c.clientY);oe(c.identifier,a,u)}}}}else{let s=null;const a=O.current?.source==="alt-mouse";switch(e.type){case"mousedown":e.button===0&&(s="down");break;case"mousemove":(a||_.current.has(-1))&&(s="move");break;case"mouseup":e.button===0&&(s="up");break;case"mouseleave":(a||_.current.has(-1))&&(s="up");break}if(s){const c=he(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(_.current.keys())}),J.current||a?Mt(s,c):oe(-1,s,c)}}},Mt=(e,n)=>{const{videoX:o,videoY:t,videoWidth:s,videoHeight:a}=n,c=s-o,u=a-t;if(e==="down"){O.current={finger0:{x:o,y:t},finger1:{x:c,y:u},videoSize:{width:s,height:a},source:"alt-mouse",pointerId0:Me,pointerId1:_e},R.current?.focus(),fe("down",s,a,o,t,c,u,Me,_e);return}if(e==="move"){O.current?.source==="alt-mouse"&&(O.current.finger0={x:o,y:t},O.current.finger1={x:c,y:u},fe("move",s,a,o,t,c,u,Me,_e));return}if(e==="up"||e==="cancel"){const d=O.current;if(d?.source==="alt-mouse"){const{finger0:p,finger1:I,videoSize:E}=d;fe("up",E.width,E.height,p.x,p.y,I.x,I.y,Me,_e),O.current=null}return}},_t=150,Je=()=>{const e=se.current;e&&(window.clearTimeout(e.endTimer),oe(ne,"up",e.pos),se.current=null)},Ct=e=>{if(e.ctrlKey||J.current||O.current)return;const n=_.current.size;if(n>1||n===1&&!_.current.has(ne))return;const o=Ne();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=he(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),d=-e.deltaX*c,p=-e.deltaY*u,I=Y=>{window.clearTimeout(Y.endTimer),Y.endTimer=window.setTimeout(Je,_t)};if(d===0&&p===0){se.current&&I(se.current);return}const E=()=>({videoWidth:a.videoWidth,videoHeight:a.videoHeight,videoX:Math.abs(d)>Math.abs(p)?Math.min(Math.max(a.videoX,a.videoWidth*.2),a.videoWidth*.8):a.videoX,videoY:Math.abs(p)>=Math.abs(d)?Math.min(Math.max(a.videoY,a.videoHeight*.2),a.videoHeight*.8):a.videoY}),S=Y=>({...Y,videoX:Math.min(Math.max(Y.videoX+d,0),Y.videoWidth),videoY:Math.min(Math.max(Y.videoY+p,0),Y.videoHeight)});let T=se.current;if(T)window.clearTimeout(T.endTimer);else{const Y=E();oe(ne,"down",Y),T={pos:Y,endTimer:0},se.current=T}let $=T.pos,re=S($);re.videoX===$.videoX&&re.videoY===$.videoY&&(oe(ne,"up",$),$=E(),oe(ne,"down",$),re=S($)),oe(ne,"move",re),T.pos=re,I(T)};l.useEffect(()=>{ve.current={handle:Ct,end:Je}}),l.useEffect(()=>{const e=pe.current;if(!e)return;const n=o=>ve.current.handle(o);return e.addEventListener("wheel",n,{passive:!1}),()=>{ve.current.end(),e.removeEventListener("wheel",n)}},[]),l.useEffect(()=>{const e=t=>{t.key==="Alt"&&Xe(!0)},n=t=>{t.key==="Alt"&&Xe(!1)},o=()=>{Xe(!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 Ce=e=>{e.preventDefault(),e.stopPropagation();const n=document.activeElement===R.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=Ut(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}`)},St=e=>{e.stopPropagation(),y.current?.reconnect()},x=l.useRef({onAxSnapshotChange:ge,onAxStatusChange:A,onCameraDemandChange:U,onCameraStats:Z,onMicrophoneStateChange:ce,onTrace:z,onTerminated:k,onConnectionStateChange:F,onPlaybackStats:M});x.current={onAxSnapshotChange:ge,onAxStatusChange:A,onCameraDemandChange:U,onCameraStats:Z,onMicrophoneStateChange:ce,onTrace:z,onTerminated:k,onConnectionStateChange:F,onPlaybackStats:M};const We=!!z;l.useEffect(()=>{xe.current=null,Ke(!1),$e(!1),De({})},[i,b]),l.useEffect(()=>{let e=!0;te.current!==null&&(te.current=null,Ye(null),r.safeInvoke("onAxSnapshotChange",x.current.onAxSnapshotChange,null));const n=r.createDeviceStream({url:i,token:m,sessionId:At,deviceModel:b,autoReconnect:L,jitterBufferTargetMs:P,openUrl:w,inspectMode:C,axPollIntervalMs:X,axMaxBackoffMs:D,androidElementTreeOptions:v,microphoneEnabled:B,onStateChange:t=>{(t.videoReady||t.connection==="idle"||t.connection==="connecting"||t.connection==="reconnecting")&&ut(t.videoReady),dt(t.connection==="failed"),ft(t.connection==="terminated"),it(t.duo),ct(t.duoState),st(t.duoError)},onAxSnapshotChange:t=>{e&&(Ye(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:We?(...t)=>x.current.onTrace?.(...t):void 0,onTerminated:()=>x.current.onTerminated?.(),onConnectionStateChange:(...t)=>x.current.onConnectionStateChange?.(...t),onPlaybackStats:M?(...t)=>x.current.onPlaybackStats?.(...t):void 0});y.current=n;const o=R.current?n.attachVideo(R.current):void 0;return n.start(),()=>{e=!1,n.dispose(),o?.(),y.current=null}},[i,m,f,b,We]),l.useEffect(()=>{if(W&&we.current)return y.current?.attachVideo(we.current,"inner")},[W,i,m,f,b,We]),l.useEffect(()=>{y.current?.updateOptions({openUrl:w,axPollIntervalMs:X,axMaxBackoffMs:D,androidElementTreeOptions:v,autoReconnect:L,jitterBufferTargetMs:P,microphoneEnabled:B,inspectMode:C,onPlaybackStats:M?(...e)=>x.current.onPlaybackStats?.(...e):void 0,onCameraStats:Z?(...e)=>x.current.onCameraStats?.(...e):void 0})},[L,P,B,C,!!M,!!Z,w,X,D,v]);const et=()=>{const e=Ne();if(!e){Ue(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};Ue(o=>o&&o.left===n.left&&o.top===n.top&&o.width===n.width&&o.height===n.height?o:n)};l.useEffect(()=>{const e=R.current,n=Ae.current,o=pe.current;if(!e)return;const t=()=>{const c=e.videoWidth>0&&e.videoHeight>0;c&&(xe.current={width:e.videoWidth,height:e.videoHeight});const u=xe.current,d=u?`${u.width} / ${u.height}`:void 0;if(!be||!n){De(!c&&u?{aspectRatio:d,contain:"size",containIntrinsicSize:`${u.width}px ${u.height}px`}:{}),et();return}const p=n.clientWidth,I=n.clientHeight;if(p===0||I===0)return;const E=u?u.width>u.height:!1;Ke(E),$e(q==="android"&&!!u&&$t(u.width,u.height));const S=E?le.videoPosition.landscape:le.videoPosition.portrait;let T={aspectRatio:d};S.heightMultiplier?(T.height=`${I*S.heightMultiplier}px`,T.width="auto"):S.widthMultiplier&&(T.width=`${p*S.widthMultiplier}px`,T.height="auto"),T.borderRadius=`${E?I*le.videoBorderRadiusMultiplier:p*le.videoBorderRadiusMultiplier}px`,De(T),et()},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)}},[le,be,i,b]),l.useEffect(()=>{Ee||(Ye(null),ye(null),Ie(null),ze(null),ae(null),Re.current=null,K.current!==void 0&&(window.cancelAnimationFrame(K.current),K.current=void 0))},[Ee]),l.useEffect(()=>()=>{K.current!==void 0&&(window.cancelAnimationFrame(K.current),K.current=void 0)},[]),l.useEffect(()=>{if(!Ee)return;const e=n=>{n.key==="Escape"&&(ke||Pe)&&(Ie(null),ye(null),ae(null),r.safeInvoke("onInspectSelectionChange",ue.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Ee,ke,Pe]);const Dt=()=>{R.current&&R.current.focus()};l.useImperativeHandle(me,()=>({openUrl:e=>y.current?.openUrl(e),sendKeyEvent:e=>y.current?.sendKeyEvent(e),screenshot:e=>y.current?.screenshot(e)??Promise.reject(new Error("Simulator disconnected")),terminateApp:e=>y.current?.terminateApp(e)??Promise.reject(new Error("Simulator disconnected")),reconnect:()=>y.current?.reconnect(),refreshAxTree:()=>y.current?.refreshAxTree()??Promise.reject(new Error("Simulator disconnected")),getAxSnapshot:()=>y.current?.getAxSnapshot()??null,setInspectHighlight:e=>{ye(e?.id??null)},setInspectSelection:e=>{Ie(e?.id??null),ae(e?Re.current:null);const n=te.current;e&&n?r.safeInvoke("onInspectSelectionChange",ue.current,{element:e,snapshot:n}):r.safeInvoke("onInspectSelectionChange",ue.current,null)},getAxStatus:()=>y.current?.getAxStatus()??"idle"}));const xt=pt&&ee!==null;return g.jsxs("div",{ref:pe,className:ie("rc-container",h),style:{touchAction:"none"},onMouseDown:G,onMouseMove:G,onMouseUp:G,onMouseLeave:G,onTouchStart:G,onTouchMove:G,onTouchEnd:G,onTouchCancel:G,children:[xt&&ee&&g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"rc-touch-indicator",style:{left:`${ee.containerX}px`,top:`${ee.containerY}px`}}),g.jsx("div",{className:"rc-touch-indicator",style:{left:`${ee.mirrorContainerX}px`,top:`${ee.mirrorContainerY}px`}})]}),be&&g.jsx("img",{ref:Ae,src:qe,alt:"",className:q==="ios"?ie("rc-phone-frame","rc-phone-frame-ios"):"rc-phone-frame",draggable:!1}),g.jsx("video",{ref:R,className:ie("rc-video",!be&&"rc-video-frameless",!at&&"rc-video-loading"),style:{...mt,...W?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...Ge?{backgroundImage:`url("${Ge}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:le.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:W?-1:0,onKeyDown:Ce,onKeyUp:Ce,onClick:Dt,onFocus:()=>{R.current&&(R.current.style.outline="none")},onBlur:()=>{R.current&&(R.current.style.outline="none")}}),W&&g.jsx("video",{ref:we,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),W&&He&&g.jsx(l.Suspense,{fallback:g.jsx("div",{children:"Loading iPhone Duo…"}),children:g.jsx(Kt,{showFrame:H,modelUrl:N,outer:R.current,inner:we.current,state:He,setAngle:e=>Le("setHingeAngle",{angleDegrees:e}),setOrientation:e=>Le("setDuoOrientation",{orientation:e}),button:(e,n)=>Le("performActions",{actions:[{type:n?"buttonDown":"buttonUp",button:e}]}),touch:(e,n,o,t)=>{y.current?.sendDisplayTouch(e,n,o,t)},onKeyDown:Ce,onKeyUp:Ce})}),W&&Ve&&g.jsx("div",{role:"alert",className:"rc-duo-error",children:Ve}),!W&&Ee&&g.jsx(jt,{snapshot:Fe,geometry:yt,highlightedId:Pe,selectedId:ke,mode:Nt,cursorPosition:Et,frozenCursorPosition:Tt,onSelectChange:(e,n)=>{Ie(e?.id??null),e&&n?ae(n):e||ae(null);const o=te.current;e&&o?r.safeInvoke("onInspectSelectionChange",ue.current,{element:e,snapshot:o}):r.safeInvoke("onInspectSelectionChange",ue.current,null)},onTapElement:(e,n)=>{if(n){Ze(n.x,n.y);return}const o=te.current;o&&wt(e,o)}}),ht?g.jsxs("div",{className:"rc-terminated",role:"status",children:[g.jsx("div",{className:"rc-terminated-title",children:"Instance terminated"}),g.jsx("div",{className:"rc-terminated-message",children:"This instance no longer exists and can't be reconnected."})]}):lt&&g.jsx("button",{type:"button",className:"rc-retry-button",onClick:St,children:"Retry"})]})});exports.RemoteControl=zt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limrun/ui",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,7 +22,12 @@
22
22
  "import": "./dist/lite.js",
23
23
  "require": "./dist/lite.cjs"
24
24
  },
25
- "./package.json": "./package.json"
25
+ "./package.json": "./package.json",
26
+ "./core": {
27
+ "types": "./dist/core.d.ts",
28
+ "import": "./dist/core.js",
29
+ "require": "./dist/core.cjs"
30
+ }
26
31
  },
27
32
  "scripts": {
28
33
  "dev": "vite",
@@ -31,7 +36,8 @@
31
36
  "lint": "eslint .",
32
37
  "preview": "vite preview",
33
38
  "test": "vitest run",
34
- "test:watch": "vitest"
39
+ "test:watch": "vitest",
40
+ "prepare": "npm run build"
35
41
  },
36
42
  "repository": {
37
43
  "type": "git",
@@ -66,6 +72,10 @@
66
72
  },
67
73
  "resolutions": {
68
74
  "vite": "^7.3.7",
69
- "@vitest/mocker": "4.1.12"
70
- }
75
+ "@vitest/mocker": "4.1.12",
76
+ "**/@microsoft/api-extractor/minimatch": "11.0.1",
77
+ "**/@typescript-eslint/typescript-estree/minimatch": "11.0.1",
78
+ "**/@vue/language-core/minimatch": "11.0.1"
79
+ },
80
+ "packageManager": "yarn@1.22.22"
71
81
  }
@@ -1 +0,0 @@
1
- "use strict";const n=require("react/jsx-runtime"),d=require("react"),E=require("./remote-control-DUG1S1Jq.js");function X(e,o,r){const[c,i]=d.useState(e),s=d.useRef({nativeAngle:e,send:o,failed:r});s.current={nativeAngle:e,send:o,failed:r};const f=d.useRef(void 0),x=d.useRef(!1),l=d.useRef(null);return d.useEffect(()=>(l.current=new E.HingeSender(async p=>{await s.current.send(p),f.current===p&&(f.current=void 0)},p=>{f.current=void 0,s.current.failed(String(p)),i(s.current.nativeAngle)}),()=>l.current?.stop()),[]),d.useEffect(()=>{!x.current&&f.current===void 0&&i(e)},[e]),{angle:c,changeAngle:p=>{s.current.failed(void 0),f.current=p,i(p),l.current?.set(p)},interacting:x}}function Y({angle:e,changeAngle:o,interacting:r,rotate:c,onFold:i,foldTarget:s,onHingeDrag:f,children:x}){const l=d.useId();return n.jsxs("div",{className:"rc-duo-controls",onPointerDown:u=>u.stopPropagation(),children:[n.jsxs("div",{className:"rc-duo-hinge",children:[n.jsx("button",{className:"rc-duo-fold",onClick:i??(()=>o(e<90?180:0)),children:(s??e)<90?"Unfold":"Fold"}),n.jsx("label",{htmlFor:l,children:"Hinge"}),n.jsx("input",{id:l,type:"range",min:0,max:180,step:1,value:e,onPointerDown:u=>{f?.(),r.current=!0,u.currentTarget.setPointerCapture(u.pointerId)},onPointerUp:()=>{r.current=!1},onPointerCancel:()=>{r.current=!1},onLostPointerCapture:()=>{r.current=!1},onChange:u=>o(Number(u.target.value))}),n.jsxs("output",{children:[Math.round(e),"°"]}),n.jsx("button",{className:"rc-duo-rotate","aria-label":"Rotate device",title:"Rotate device",onClick:c,children:n.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[n.jsx("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2"}),n.jsx("path",{d:"M3 9a9 9 0 0 1 3-5M3 4v5h5M21 15a9 9 0 0 1-3 5m3 0v-5h-5"})]})})]}),x&&n.jsx("div",{className:"rc-duo-views","aria-label":"Device view",children:x})]})}function $({button:e}){return n.jsx("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e==="side"?n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6",y:"10",width:"12",height:"11",rx:"2"}),n.jsx("path",{d:"M8 10V7a4 4 0 0 1 8 0v3"})]}):n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3 9h4l5-5v16l-5-5H3zM17 12h5"}),e==="volumeUp"&&n.jsx("path",{d:"M19.5 9.5v5"})]})})}function z(e,o,r,c,i,s){return"M"+(e+i)+","+o+"H"+(e+r-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+c-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+i)+"a"+i+","+i+" 0 0 1 "+-i+","+-i+"V"+(o+i)+"a"+i+","+i+" 0 0 1 "+i+","+-i+"Z"}function G({inner:e,width:o,height:r}){const c=d.useId().replace(/:/g,""),i=e?8.4:1.25,s=8.4;return n.jsxs("svg",{className:"rc-duo-flat-frame",viewBox:"0 0 "+o+" "+r,"aria-hidden":"true",children:[n.jsxs("defs",{children:[n.jsxs("linearGradient",{id:c+"-silver",x1:"0",y1:"0",x2:"1",y2:"1",children:[n.jsx("stop",{offset:"0",stopColor:"#62676b"}),n.jsx("stop",{offset:"0.035",stopColor:"#f9faf9"}),n.jsx("stop",{offset:"0.11",stopColor:"#b0b4b6"}),n.jsx("stop",{offset:"0.31",stopColor:"#fdfefd"}),n.jsx("stop",{offset:"0.43",stopColor:"#797f84"}),n.jsx("stop",{offset:"0.51",stopColor:"#e8eaea"}),n.jsx("stop",{offset:"0.7",stopColor:"#979da1"}),n.jsx("stop",{offset:"0.87",stopColor:"#fafbf9"}),n.jsx("stop",{offset:"1",stopColor:"#5f676c"})]}),n.jsxs("linearGradient",{id:c+"-spine",children:[n.jsx("stop",{stopColor:"#4a5154"}),n.jsx("stop",{offset:"0.16",stopColor:"#d6d9d9"}),n.jsx("stop",{offset:"0.4",stopColor:"#f8f9f7"}),n.jsx("stop",{offset:"0.62",stopColor:"#a2a8ab"}),n.jsx("stop",{offset:"0.83",stopColor:"#e4e7e5"}),n.jsx("stop",{offset:"1",stopColor:"#666e72"})]})]}),!e&&n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"-2.3",y:"0.7",width:"3.3",height:r-1.4,rx:"0.85",fill:"url(#"+c+"-spine)",stroke:"#8b9296",strokeWidth:"0.15"}),n.jsx("path",{d:"M-.6 2V"+(r-2),stroke:"#f5f6f4",strokeWidth:"0.22"})]}),n.jsx("path",{d:z(0,0,o,r,i,s),fill:"url(#"+c+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),n.jsx("path",{d:z(.48,.48,o-.96,r-.96,Math.max(.5,i-.48),s-.48),fill:"none",stroke:"#ffffff",strokeOpacity:"0.85",strokeWidth:"0.2"}),n.jsx("path",{d:z(1.12,1.12,o-2.24,r-2.24,e?7.15:.65,7.15),fill:"#090b0d",stroke:"#34393c",strokeWidth:"0.2"}),[o-16,e?19:16].map(f=>n.jsx(d.Fragment,{children:n.jsx("path",{d:"M"+f+",0.17v0.82M"+f+","+(r-1)+"v0.82",stroke:"#b1b2ac",strokeWidth:"1.1"})},f)),e&&[0,r-.6].map(f=>n.jsx("rect",{x:o/2-2.2,y:f,width:"4.4",height:"0.6",rx:"0.18",fill:"url(#"+c+"-spine)",stroke:"#697074",strokeWidth:"0.14"},f)),n.jsx("path",{d:"M"+(o-.1)+",20h-.9m.9,"+(r-40)+"h-.9",stroke:"#b1b2ac",strokeWidth:"1.05"})]})}function re(e,o,r,c){const i=E.DUO_DIMENSIONS.width/(e?1:2),s=E.DUO_DIMENSIONS.height,f=e?157.5:77.1,x=e?110.8:112.2,l=(o+(e?3:0))%4,u=Math.max(0,Math.min((r-120)/(l%2?s:i),(c-120)/(l%2?i:s))),p=(h,v)=>{h=(h-i/2)*u,v=(v-s/2)*u;const w=l===1?{x:-v,y:h}:l===2?{x:-h,y:-v}:l===3?{x:v,y:-h}:{x:h,y:v};return{x:w.x+r/2,y:w.y+c/2}},S=(l%2?s:i)*u,D=(l%2?i:s)*u,k={min:{x:(r-S)/2,y:(c-D)/2},max:{x:(r+S)/2,y:(c+D)/2}},y=[{button:"volumeDown",x:i-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:i-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:i+.35,y:s/2-21,width:.7,height:13,edge:"right"}],g=["top","right","bottom","left"],b=y.map(h=>{const v=g[(g.indexOf(h.edge)+l)%4],w=p(h.x,h.y);return v==="top"&&(w.y=k.min.y-28),v==="bottom"&&(w.y=k.max.y+28),v==="left"&&(w.x=k.min.x-28),v==="right"&&(w.x=k.max.x+28),{button:h.button,edge:v,...w,targetX:w.x,targetY:w.y}}),m=b.filter(h=>h.button!=="side"),j=l%2?"y":"x";m.sort((h,v)=>h[j]-v[j]);const P=l%2?"targetY":"targetX";if(m[1][j]-m[0][j]<44){const h=(m[0][j]+m[1][j])/2;m[0][P]=h-22,m[1][P]=h+22}return{bodyWidth:i,bodyHeight:s,screenWidth:f,screenHeight:x,scale:u,turns:l,buttons:y,guides:b,rect:k,iconSize:Math.min(A(k),12*u)}}function A(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function Z(e,o,r){return[["top",r.min.y-o,e,r.min.x,r.max.x],["bottom",o-r.max.y,e,r.min.x,r.max.x],["left",r.min.x-e,o,r.min.y,r.max.y],["right",e-r.max.x,o,r.min.y,r.max.y]].filter(([,i,s,f,x])=>i>=-7&&i<=52&&s>=f-12&&s<=x+12).sort((i,s)=>Math.abs(i[1])-Math.abs(s[1]))[0]?.[0]}function B(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return;const o=Math.min(1,1024/Math.max(e.videoWidth,e.videoHeight)),r=document.createElement("canvas");try{const c=r.getContext("2d");return c?(r.width=Math.round(e.videoWidth*o),r.height=Math.round(e.videoHeight*o),c.drawImage(e,0,0,r.width,r.height),r):void 0}catch{return}}function ne(e,o){let r=!1,c;const i=u=>{r||(l(),o(u))},s=()=>{if(r)return;const u=B(e);u&&i(u)},f=()=>{c=void 0,s(),r||(c=e?.requestVideoFrameCallback?.(f))},x=setTimeout(()=>i(void 0),2500);c=e?.requestVideoFrameCallback?.(f),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function l(){r=!0,clearTimeout(x),c!==void 0&&e?.cancelVideoFrameCallback(c),e?.removeEventListener("loadeddata",s)}return l}function oe(e,o,r,c,i=!0){const s=d.useRef(void 0),f=d.useRef(c),x=d.useRef({inner:o,frame:r});x.current={inner:o,frame:r};const[l,u]=d.useState(),p=d.useRef(void 0),S=d.useRef(void 0),D=d.useCallback(()=>{clearTimeout(S.current),p.current=void 0,u(void 0)},[]),k=y=>{if(!i||y===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||p.current)return;const g=B(e.current);if(!g)return;const b=x.current;p.current={from:b,to:b,before:g,ready:!1},u(p.current),S.current=setTimeout(D,5e3)};return d.useEffect(()=>()=>clearTimeout(S.current),[]),d.useLayoutEffect(()=>{const y=s.current,g={inner:o,frame:r};s.current=g;const b=f.current!==c;if(f.current=c,!y)return;const m=Math.abs(y.frame.rect.min.x+y.frame.rect.max.x-r.rect.min.x-r.rect.max.x)>.5||Math.abs(y.frame.rect.min.y+y.frame.rect.max.y-r.rect.min.y-r.rect.max.y)>.5;if(!i||m||b){D();return}if(y.inner===o||(u(void 0),!y.frame.scale||!r.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const j=p.current?.before??B(e.current),P=p.current?.from??y;clearTimeout(S.current),p.current=void 0,j&&u({from:P,to:g,before:j,ready:!1})},[o,r.scale,r.turns,r.rect.min.x,r.rect.min.y,c,i]),d.useEffect(()=>{if(!l||l.from.inner===o)return;const y=ne(e.current,m=>{m?u(j=>j&&{...j,to:x.current,after:m,ready:!0}):D()}),g=window.matchMedia?.("(prefers-reduced-motion: reduce)"),b=()=>{g?.matches&&u(void 0)};return g?.addEventListener("change",b),()=>{y(),g?.removeEventListener("change",b)}},[l?.from,o]),{motion:l,finish:D,prepare:k}}function se({pose:e,image:o,scale:r}){const{bodyWidth:c,bodyHeight:i,screenWidth:s,screenHeight:f}=e.frame,x=s*r,l=f*r;return n.jsxs("div",{className:"rc-duo-fold-still",style:{width:c*r,height:i*r},children:[n.jsx(G,{inner:e.inner,width:c,height:i}),n.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:l,left:(c-s)*r/2,top:(i-f)*r/2,borderRadius:e.inner?5.3*r:[.8,6.6,6.6,.8].map(u=>u*r+"px").join(" ")},children:o&&n.jsx("canvas",{ref:u=>{u&&(u.width=o.width,u.height=o.height,u.getContext("2d")?.drawImage(o,0,0))},style:{width:e.inner?l:x,height:e.inner?x:l,transform:`translate(-50%, -50%) rotate(${e.inner?90:0}deg)`}})})]})}function ie({motion:e,onFinish:o}){const r=d.useRef(null),[c,i]=d.useState(!1);return d.useEffect(()=>{if(i(!1),!e.ready)return;let s=!1,f;return Promise.resolve().then(()=>require("./duo-fold-renderer-DdltAnF7.js")).then(({renderFold:x})=>{s||!r.current||(f=x(r.current,e,o),i(!0))}).catch(()=>{s||o()}),()=>{s=!0,f?.()}},[e.ready,e.from,o]),n.jsxs(n.Fragment,{children:[!c&&n.jsx("div",{className:"rc-duo-fold-hold","aria-hidden":"true",style:{width:e.from.frame.bodyWidth*e.from.frame.scale,height:e.from.frame.bodyHeight*e.from.frame.scale,transform:`translate(-50%, -50%) rotate(${e.from.frame.turns*90}deg)`},children:n.jsx(se,{pose:e.from,image:e.before,scale:e.from.frame.scale})}),n.jsx("canvas",{ref:r,className:"rc-duo-fold-canvas","aria-hidden":"true",style:{visibility:c?"visible":"hidden"}})]})}const ae=d.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-BZ-XDtxc.js")).then(e=>e.duoFrame));function ce(e){const[o,r]=d.useState("2d");return n.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o==="3d"?n.jsx(d.Suspense,{fallback:n.jsx(K,{...e}),children:n.jsx(ae,{...e})}):n.jsx(K,{...e}),e.showFrame!==!1&&n.jsxs("div",{className:"rc-duo-mode",role:"group","aria-label":"Device rendering",children:[n.jsx("button",{type:"button","aria-pressed":o==="2d",onClick:()=>r("2d"),children:"2D"}),n.jsx("button",{type:"button","aria-pressed":o==="3d",onClick:()=>r("3d"),children:"3D"})]})]})}function K(e){const o=e.showFrame!==!1,r=d.useRef(null),c=d.useRef(null),i=d.useRef(e);i.current=e;const[s,f]=d.useState({width:0,height:0}),[x,l]=d.useState(),[u,p]=d.useState(),[S,D]=d.useState(),[k,y]=d.useState(),g=d.useRef(void 0),b=d.useRef(null),m=e.state.displays.find(t=>t.id===(e.state.angleDegrees<90?"outer":"inner")),j=m?.id==="inner"?e.inner:e.outer,P=m?.orientation===2?2:m?.orientation===3?1:m?.orientation===4?3:0,h=m?.id==="inner",v={portrait:0,pud:2,"landscape-left":3,"landscape-right":1}[e.state.orientation],w=o?(v+(h?1:0))%4:P,M=re(h,w,s.width,s.height),H=o?M.screenWidth:(h?m?.height:m?.width)??1,W=o?M.screenHeight:(h?m?.width:m?.height)??1,F=o?M.bodyWidth:H,R=o?M.bodyHeight:W,C=o?M.scale:Math.max(0,Math.min(s.width/(M.turns%2?R:F),s.height/(M.turns%2?F:R))),U=H*C,L=W*C;d.useEffect(()=>{const t=new ResizeObserver(([a])=>{a&&f({width:a.contentRect.width,height:a.contentRect.height})});return r.current&&t.observe(r.current),()=>t.disconnect()},[]),d.useEffect(()=>{const t=c.current;if(!t||!j)return;const a=()=>{t.srcObject!==j.srcObject&&(t.srcObject=j.srcObject),t.play().catch(()=>{}),e.outer?.pause(),e.inner?.pause()};return a(),j.addEventListener("loadedmetadata",a),()=>{j.removeEventListener("loadedmetadata",a),t.pause(),t.srcObject=null;for(const O of[e.outer,e.inner])O?.play().catch(()=>{})}},[j,e.outer,e.inner]);const{motion:N,finish:V,prepare:J}=oe(c,h,M,e.state.orientation,o),{angle:Q,changeAngle:ee,interacting:te}=X(e.state.angleDegrees,async t=>{J(t>=90);try{await e.setAngle(t)}catch(a){throw V(),a}},l),I=()=>{if(!g.current)return;const{screenId:t,x:a,y:O}=g.current;i.current.touch(1,t,a,O),g.current=void 0};d.useEffect(()=>{b.current=new E.DuoButtonSender((a,O)=>i.current.button(a,O),a=>l(String(a)));const t=()=>{I(),b.current?.release(),y(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),d.useEffect(()=>{I()},[m?.screenId,w]);const T=()=>{b.current?.release(),y(void 0)},_=t=>({onPointerDown:a=>{N||a.button!==0||(a.currentTarget.setPointerCapture(a.pointerId),b.current?.press(t),y(t))},onPointerUp:T,onPointerCancel:T,onLostPointerCapture:T,onBlur:T,onPointerEnter:()=>D(t),onPointerLeave:()=>D(void 0),onFocus:()=>p(M.guides.find(a=>a.button===t)?.edge),onKeyDown:a=>{N||(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),a.repeat||(b.current?.press(t),y(t)))},onKeyUp:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),T())}}),q=t=>{const a=t.currentTarget.getBoundingClientRect();return E.flatDisplayTouch((t.clientX-a.left)/a.width,(t.clientY-a.top)/a.height,w)};return n.jsxs("div",{className:o?"rc-duo":"rc-duo rc-duo-frameless",children:[n.jsxs("div",{ref:r,className:"rc-duo-flat-stage","data-folding":!!N,"aria-busy":!!N,onPointerMove:t=>{if(!o)return;const a=t.currentTarget.getBoundingClientRect();p(Z(t.clientX-a.left,t.clientY-a.top,M.rect))},onPointerLeave:()=>{p(void 0),D(void 0)},children:[n.jsxs("div",{className:"rc-duo-flat-device","data-display":h?"inner":"outer",style:{width:F*C,height:R*C,transform:"translate(-50%, -50%) rotate("+M.turns*90+"deg)"},children:[o&&n.jsx(G,{inner:h,width:F,height:R}),n.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(F-H)/2*C,top:(R-W)/2*C,borderRadius:o?h?5.3*C:[.8,6.6,6.6,.8].map(t=>t*C+"px").join(" "):0},onKeyDown:N?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(N||g.current||t.button!==0||!m)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const a=q(t);g.current={pointer:t.pointerId,screenId:m.screenId,...a},e.touch(0,m.screenId,a.x,a.y)},onPointerMove:t=>{if(g.current?.pointer!==t.pointerId)return;const a=q(t);Object.assign(g.current,a),e.touch(2,g.current.screenId,a.x,a.y)},onPointerUp:t=>{g.current?.pointer===t.pointerId&&I()},onPointerCancel:I,onLostPointerCapture:I,children:n.jsx("video",{ref:c,autoPlay:!0,muted:!0,playsInline:!0,style:{width:h?L:U,height:h?U:L,transform:"translate(-50%, -50%) rotate("+(h?90:0)+"deg)"}})}),o&&M.buttons.map(t=>n.jsx("button",{type:"button",className:"rc-duo-physical","data-duo-button":t.button,"data-edge":t.edge,"data-highlighted":S===t.button,"data-pressed":k===t.button,"aria-label":E.DUO_BUTTONS[t.button]+" physical button",title:E.DUO_BUTTONS[t.button],style:{left:t.x*C,top:t.y*C,width:t.edge==="top"?Math.max(28,t.width*C):28,height:t.edge==="top"?28:Math.max(28,t.height*C)},..._(t.button),children:n.jsx("span",{style:{width:Math.max(2,t.width*C),height:Math.max(2,t.height*C)}})},t.button))]}),o&&M.guides.map(t=>n.jsx("button",{type:"button",className:"rc-duo-hardware","data-duo-button":t.button,"data-visible":u===t.edge,"data-pressed":k===t.button,"aria-label":E.DUO_BUTTONS[t.button],title:E.DUO_BUTTONS[t.button],style:{left:t.targetX,top:t.targetY,"--duo-hardware-icon-size":`${M.iconSize}px`,"--duo-hardware-icon-x":`${t.x-t.targetX}px`,"--duo-hardware-icon-y":`${t.y-t.targetY}px`},..._(t.button),children:n.jsx($,{button:t.button})},t.button)),N&&n.jsx(ie,{motion:N,onFinish:V})]}),o&&n.jsx(Y,{angle:Q,changeAngle:ee,interacting:te,rotate:()=>{e.setOrientation(e.state.orientation==="portrait"?"landscape-left":"portrait").catch(t=>l(String(t)))},children:n.jsx("span",{className:"rc-duo-view-label",children:"Front view"})}),x&&n.jsx("div",{role:"alert",className:"rc-duo-error",children:x})]})}const de=Object.freeze(Object.defineProperty({__proto__:null,default:ce},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=Y;exports.DuoHardwareIcon=$;exports.duoView=de;exports.flatHoverEdge=Z;exports.hardwareIconSize=A;exports.useDuoHinge=X;