@limrun/ui 0.21.0 → 0.22.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.
Files changed (45) hide show
  1. package/README.md +36 -8
  2. package/dist/BufferGeometryUtils-Dm5SmmmT.mjs +64 -0
  3. package/dist/BufferGeometryUtils-Dne8i0aT.js +1 -0
  4. package/dist/GLTFLoader-DzSwAt9C.js +1 -0
  5. package/dist/{GLTFLoader-D4AITfgZ.mjs → GLTFLoader-L51A9w-A.mjs} +138 -137
  6. package/dist/components/device-view.d.ts +29 -0
  7. package/dist/components/duo-frame.d.ts +5 -1
  8. package/dist/components/duo-model.d.ts +2 -1
  9. package/dist/components/macbook-frame.d.ts +30 -0
  10. package/dist/components/macbook-geometry.d.ts +77 -0
  11. package/dist/components/model-source.d.ts +8 -0
  12. package/dist/components/remote-control.d.ts +40 -1
  13. package/dist/components/studio-environment.d.ts +6 -0
  14. package/dist/core/mac-pointer.d.ts +56 -0
  15. package/dist/{core-CRIachT9.mjs → core-nbvkIrvp.mjs} +24 -24
  16. package/dist/core.js +12 -12
  17. package/dist/duo-frame-CHI6g7BR.mjs +758 -0
  18. package/dist/duo-frame-Cj-xHHW3.js +11 -0
  19. package/dist/duo-model-BYgtCaCR.mjs +4 -0
  20. package/dist/duo-model-CDWgmLRF.js +1 -0
  21. package/dist/duo-model.d.ts +2 -0
  22. package/dist/{duo-view-BeqYIqfQ.mjs → duo-view-Biy9MAlH.mjs} +84 -86
  23. package/dist/duo-view-D0Ndj2Ee.js +1 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.css +1 -1
  26. package/dist/index.js +32 -25
  27. package/dist/lite.cjs +1 -1
  28. package/dist/lite.js +2 -2
  29. package/dist/macbook-frame-BHQtQNGV.mjs +349 -0
  30. package/dist/macbook-frame-CQyZhRFn.js +3 -0
  31. package/dist/macbook-model-BiMxLpmf.mjs +4 -0
  32. package/dist/macbook-model-BpUdvtlU.js +1 -0
  33. package/dist/macbook-model.d.ts +2 -0
  34. package/dist/meshopt_decoder.module-C4Z_evpr.mjs +217 -0
  35. package/dist/meshopt_decoder.module-DxJdu6ez.js +1 -0
  36. package/dist/{duo-frame-D1JK_cRk.mjs → model-source-BjSq5Any.mjs} +5353 -6125
  37. package/dist/model-source-S12HoOoQ.js +4049 -0
  38. package/dist/remote-control-BGKETUbE.mjs +1746 -0
  39. package/dist/remote-control-OLgfUSR1.js +1 -0
  40. package/package.json +1 -1
  41. package/dist/GLTFLoader-C25N9Y4j.js +0 -1
  42. package/dist/duo-frame-B1NXSk6a.js +0 -4059
  43. package/dist/duo-view-PsR5b045.js +0 -1
  44. package/dist/remote-control-DNr0Pyrx.js +0 -1
  45. package/dist/remote-control-rdm3mDtI.mjs +0 -1299
@@ -1 +0,0 @@
1
- "use strict";const r=require("react/jsx-runtime"),u=require("react"),E=require("./core-BCBQrYsk.js");function Y(e,o,n){const[i,a]=u.useState(e),s=u.useRef({nativeAngle:e,send:o,failed:n});s.current={nativeAngle:e,send:o,failed:n};const l=u.useRef(void 0),x=u.useRef(!1),d=u.useRef(null);return u.useEffect(()=>(d.current=new E.HingeSender(async h=>{await s.current.send(h),l.current===h&&(l.current=void 0)},h=>{l.current=void 0,s.current.failed(String(h)),a(s.current.nativeAngle)}),()=>d.current?.stop()),[]),u.useEffect(()=>{!x.current&&l.current===void 0&&a(e)},[e]),{angle:i,changeAngle:h=>{s.current.failed(void 0),l.current=h,a(h),d.current?.set(h)},interacting:x}}function $({angle:e,watchOnly:o=!1,changeAngle:n,interacting:i,rotate:a,onFold:s,foldTarget:l,onHingeDrag:x,children:d}){const f=u.useId();return r.jsxs("div",{className:"rc-duo-controls",onPointerDown:h=>h.stopPropagation(),children:[r.jsxs("div",{className:"rc-duo-hinge",children:[r.jsx("button",{disabled:o,className:"rc-duo-fold",onClick:s??(()=>n(e<90?180:0)),children:(l??e)<90?"Unfold":"Fold"}),r.jsx("label",{htmlFor:f,children:"Hinge"}),r.jsx("input",{id:f,type:"range",disabled:o,min:0,max:180,step:1,value:e,onPointerDown:h=>{x?.(),i.current=!0,h.currentTarget.setPointerCapture(h.pointerId)},onPointerUp:()=>{i.current=!1},onPointerCancel:()=>{i.current=!1},onLostPointerCapture:()=>{i.current=!1},onChange:h=>n(Number(h.target.value))}),r.jsxs("output",{children:[Math.round(e),"°"]}),r.jsx("button",{disabled:o,className:"rc-duo-rotate","aria-label":"Rotate device",title:"Rotate device",onClick:a,children:r.jsxs("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[r.jsx("rect",{x:"7",y:"3",width:"10",height:"18",rx:"2"}),r.jsx("path",{d:"M3 9a9 9 0 0 1 3-5M3 4v5h5M21 15a9 9 0 0 1-3 5m3 0v-5h-5"})]})})]}),d&&r.jsx("div",{className:"rc-duo-views","aria-label":"Device view",children:d})]})}function G({button:e}){return r.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"?r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"6",y:"10",width:"12",height:"11",rx:"2"}),r.jsx("path",{d:"M8 10V7a4 4 0 0 1 8 0v3"})]}):r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M3 9h4l5-5v16l-5-5H3zM17 12h5"}),e==="volumeUp"&&r.jsx("path",{d:"M19.5 9.5v5"})]})})}function B(e,o,n,i,a,s){return"M"+(e+a)+","+o+"H"+(e+n-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+i-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+a)+"a"+a+","+a+" 0 0 1 "+-a+","+-a+"V"+(o+a)+"a"+a+","+a+" 0 0 1 "+a+","+-a+"Z"}function A({inner:e,width:o,height:n}){const i=u.useId().replace(/:/g,""),a=e?8.4:1.25,s=8.4;return r.jsxs("svg",{className:"rc-duo-flat-frame",viewBox:"0 0 "+o+" "+n,"aria-hidden":"true",children:[r.jsxs("defs",{children:[r.jsxs("linearGradient",{id:i+"-silver",x1:"0",y1:"0",x2:"1",y2:"1",children:[r.jsx("stop",{offset:"0",stopColor:"#62676b"}),r.jsx("stop",{offset:"0.035",stopColor:"#f9faf9"}),r.jsx("stop",{offset:"0.11",stopColor:"#b0b4b6"}),r.jsx("stop",{offset:"0.31",stopColor:"#fdfefd"}),r.jsx("stop",{offset:"0.43",stopColor:"#797f84"}),r.jsx("stop",{offset:"0.51",stopColor:"#e8eaea"}),r.jsx("stop",{offset:"0.7",stopColor:"#979da1"}),r.jsx("stop",{offset:"0.87",stopColor:"#fafbf9"}),r.jsx("stop",{offset:"1",stopColor:"#5f676c"})]}),r.jsxs("linearGradient",{id:i+"-spine",children:[r.jsx("stop",{stopColor:"#4a5154"}),r.jsx("stop",{offset:"0.16",stopColor:"#d6d9d9"}),r.jsx("stop",{offset:"0.4",stopColor:"#f8f9f7"}),r.jsx("stop",{offset:"0.62",stopColor:"#a2a8ab"}),r.jsx("stop",{offset:"0.83",stopColor:"#e4e7e5"}),r.jsx("stop",{offset:"1",stopColor:"#666e72"})]})]}),!e&&r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"-2.3",y:"0.7",width:"3.3",height:n-1.4,rx:"0.85",fill:"url(#"+i+"-spine)",stroke:"#8b9296",strokeWidth:"0.15"}),r.jsx("path",{d:"M-.6 2V"+(n-2),stroke:"#f5f6f4",strokeWidth:"0.22"})]}),r.jsx("path",{d:B(0,0,o,n,a,s),fill:"url(#"+i+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),r.jsx("path",{d:B(.48,.48,o-.96,n-.96,Math.max(.5,a-.48),s-.48),fill:"none",stroke:"#ffffff",strokeOpacity:"0.85",strokeWidth:"0.2"}),r.jsx("path",{d:B(1.12,1.12,o-2.24,n-2.24,e?7.15:.65,7.15),fill:"#090b0d",stroke:"#34393c",strokeWidth:"0.2"}),[o-16,e?19:16].map(l=>r.jsx(u.Fragment,{children:r.jsx("path",{d:"M"+l+",0.17v0.82M"+l+","+(n-1)+"v0.82",stroke:"#b1b2ac",strokeWidth:"1.1"})},l)),e&&[0,n-.6].map(l=>r.jsx("rect",{x:o/2-2.2,y:l,width:"4.4",height:"0.6",rx:"0.18",fill:"url(#"+i+"-spine)",stroke:"#697074",strokeWidth:"0.14"},l)),r.jsx("path",{d:"M"+(o-.1)+",20h-.9m.9,"+(n-40)+"h-.9",stroke:"#b1b2ac",strokeWidth:"1.05"})]})}function ne(e,o,n,i){const a=E.DUO_DIMENSIONS.width/(e?1:2),s=E.DUO_DIMENSIONS.height,l=e?157.5:77.1,x=e?110.8:112.2,d=(o+(e?3:0))%4,f=Math.max(0,Math.min((n-120)/(d%2?s:a),(i-120)/(d%2?a:s))),h=(y,m)=>{y=(y-a/2)*f,m=(m-s/2)*f;const C=d===1?{x:-m,y}:d===2?{x:-y,y:-m}:d===3?{x:m,y:-y}:{x:y,y:m};return{x:C.x+n/2,y:C.y+i/2}},N=(d%2?s:a)*f,D=(d%2?a:s)*f,k={min:{x:(n-N)/2,y:(i-D)/2},max:{x:(n+N)/2,y:(i+D)/2}},g=[{button:"volumeDown",x:a-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:a-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:a+.35,y:s/2-21,width:.7,height:13,edge:"right"}],b=["top","right","bottom","left"],j=g.map(y=>{const m=b[(b.indexOf(y.edge)+d)%4],C=h(y.x,y.y);return m==="top"&&(C.y=k.min.y-28),m==="bottom"&&(C.y=k.max.y+28),m==="left"&&(C.x=k.min.x-28),m==="right"&&(C.x=k.max.x+28),{button:y.button,edge:m,...C,targetX:C.x,targetY:C.y}}),v=j.filter(y=>y.button!=="side"),p=d%2?"y":"x";v.sort((y,m)=>y[p]-m[p]);const S=d%2?"targetY":"targetX";if(v[1][p]-v[0][p]<44){const y=(v[0][p]+v[1][p])/2;v[0][S]=y-22,v[1][S]=y+22}return{bodyWidth:a,bodyHeight:s,screenWidth:l,screenHeight:x,scale:f,turns:d,buttons:g,guides:j,rect:k,iconSize:Math.min(Z(k),12*f)}}function Z(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function J(e,o,n){return[["top",n.min.y-o,e,n.min.x,n.max.x],["bottom",o-n.max.y,e,n.min.x,n.max.x],["left",n.min.x-e,o,n.min.y,n.max.y],["right",e-n.max.x,o,n.min.y,n.max.y]].filter(([,a,s,l,x])=>a>=-7&&a<=52&&s>=l-12&&s<=x+12).sort((a,s)=>Math.abs(a[1])-Math.abs(s[1]))[0]?.[0]}function V(e){if(!e||e.readyState<2||!e.videoWidth||!e.videoHeight)return;const o=Math.min(1,1024/Math.max(e.videoWidth,e.videoHeight)),n=document.createElement("canvas");try{const i=n.getContext("2d");return i?(n.width=Math.round(e.videoWidth*o),n.height=Math.round(e.videoHeight*o),i.drawImage(e,0,0,n.width,n.height),n):void 0}catch{return}}function oe(e,o){let n=!1,i;const a=f=>{n||(d(),o(f))},s=()=>{if(n)return;const f=V(e);f&&a(f)},l=()=>{i=void 0,s(),n||(i=e?.requestVideoFrameCallback?.(l))},x=setTimeout(()=>a(void 0),2500);i=e?.requestVideoFrameCallback?.(l),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function d(){n=!0,clearTimeout(x),i!==void 0&&e?.cancelVideoFrameCallback(i),e?.removeEventListener("loadeddata",s)}return d}function se(e,o,n,i,a=!0){const s=u.useRef(void 0),l=u.useRef(i),x=u.useRef({inner:o,frame:n});x.current={inner:o,frame:n};const[d,f]=u.useState(),h=u.useRef(void 0),N=u.useRef(void 0),D=u.useCallback(()=>{clearTimeout(N.current),h.current=void 0,f(void 0)},[]),k=g=>{if(!a||g===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||h.current)return;const b=V(e.current);if(!b)return;const j=x.current;h.current={from:j,to:j,before:b,ready:!1},f(h.current),N.current=setTimeout(D,5e3)};return u.useEffect(()=>()=>clearTimeout(N.current),[]),u.useLayoutEffect(()=>{const g=s.current,b={inner:o,frame:n};s.current=b;const j=l.current!==i;if(l.current=i,!g)return;const v=Math.abs(g.frame.rect.min.x+g.frame.rect.max.x-n.rect.min.x-n.rect.max.x)>.5||Math.abs(g.frame.rect.min.y+g.frame.rect.max.y-n.rect.min.y-n.rect.max.y)>.5;if(!a||v||j){D();return}if(g.inner===o||(f(void 0),!g.frame.scale||!n.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const p=h.current?.before??V(e.current),S=h.current?.from??g;clearTimeout(N.current),h.current=void 0,p&&f({from:S,to:b,before:p,ready:!1})},[o,n.scale,n.turns,n.rect.min.x,n.rect.min.y,i,a]),u.useEffect(()=>{if(!d||d.from.inner===o)return;const g=oe(e.current,v=>{v?f(p=>p&&{...p,to:x.current,after:v,ready:!0}):D()}),b=window.matchMedia?.("(prefers-reduced-motion: reduce)"),j=()=>{b?.matches&&f(void 0)};return b?.addEventListener("change",j),()=>{g(),b?.removeEventListener("change",j)}},[d?.from,o]),{motion:d,finish:D,prepare:k}}function ae({pose:e,image:o,scale:n}){const{bodyWidth:i,bodyHeight:a,screenWidth:s,screenHeight:l}=e.frame,x=s*n,d=l*n;return r.jsxs("div",{className:"rc-duo-fold-still",style:{width:i*n,height:a*n},children:[r.jsx(A,{inner:e.inner,width:i,height:a}),r.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:d,left:(i-s)*n/2,top:(a-l)*n/2,borderRadius:e.inner?5.3*n:[.8,6.6,6.6,.8].map(f=>f*n+"px").join(" ")},children:o&&r.jsx("canvas",{ref:f=>{f&&(f.width=o.width,f.height=o.height,f.getContext("2d")?.drawImage(o,0,0))},style:{width:e.inner?d:x,height:e.inner?x:d,transform:`translate(-50%, -50%) rotate(${e.inner?90:0}deg)`}})})]})}function ie({motion:e,onFinish:o}){const n=u.useRef(null),[i,a]=u.useState(!1);return u.useEffect(()=>{if(a(!1),!e.ready)return;let s=!1,l;return Promise.resolve().then(()=>require("./duo-fold-renderer-DdltAnF7.js")).then(({renderFold:x})=>{s||!n.current||(l=x(n.current,e,o),a(!0))}).catch(()=>{s||o()}),()=>{s=!0,l?.()}},[e.ready,e.from,o]),r.jsxs(r.Fragment,{children:[!i&&r.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:r.jsx(ae,{pose:e.from,image:e.before,scale:e.from.frame.scale})}),r.jsx("canvas",{ref:n,className:"rc-duo-fold-canvas","aria-hidden":"true",style:{visibility:i?"visible":"hidden"}})]})}const ce=u.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-B1NXSk6a.js")).then(e=>e.duoFrame));function ue(e){const[o,n]=u.useState("2d");return r.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o==="3d"?r.jsx(u.Suspense,{fallback:r.jsx(X,{...e}),children:r.jsx(ce,{...e})}):r.jsx(X,{...e}),e.showFrame!==!1&&r.jsxs("div",{className:"rc-duo-mode",role:"group","aria-label":"Device rendering",children:[r.jsx("button",{type:"button","aria-pressed":o==="2d",onClick:()=>n("2d"),children:"2D"}),r.jsx("button",{type:"button","aria-pressed":o==="3d",onClick:()=>n("3d"),children:"3D"})]})]})}function X(e){const o=e.showFrame!==!1,n=u.useRef(null),i=u.useRef(null),a=u.useRef(e);a.current=e;const[s,l]=u.useState({width:0,height:0}),[x,d]=u.useState(),[f,h]=u.useState(),[N,D]=u.useState(),[k,g]=u.useState(),b=u.useRef(void 0),j=u.useRef(null);j.current||(j.current=new E.DuoTouchController((...t)=>a.current.touch(...t)));const v=u.useRef(null),p=E.getDuoDisplay(e.state),S=p?.id==="inner"?e.inner:e.outer,y=E.duoDisplayTurns(p?.orientation),m=p?.id==="inner",C={portrait:0,pud:2,"landscape-left":3,"landscape-right":1}[e.state.orientation],H=o?(C+(m?1:0))%4:y,w=ne(m,H,s.width,s.height),W=o?w.screenWidth:(m?p?.height:p?.width)??1,I=o?w.screenHeight:(m?p?.width:p?.height)??1,R=o?w.bodyWidth:W,F=o?w.bodyHeight:I,M=o?w.scale:Math.max(0,Math.min(s.width/(w.turns%2?F:R),s.height/(w.turns%2?R:F))),U=W*M,L=I*M;u.useEffect(()=>{const t=new ResizeObserver(([c])=>{c&&l({width:c.contentRect.width,height:c.contentRect.height})});return n.current&&t.observe(n.current),()=>t.disconnect()},[]),u.useEffect(()=>{const t=i.current;if(!t||!S)return;const c=()=>{t.srcObject!==S.srcObject&&(t.srcObject=S.srcObject),t.play().catch(()=>{}),e.outer?.pause(),e.inner?.pause()};return c(),S.addEventListener("loadedmetadata",c),()=>{S.removeEventListener("loadedmetadata",c),t.pause(),t.srcObject=null;for(const z of[e.outer,e.inner])z?.play().catch(()=>{})}},[S,e.outer,e.inner]);const{motion:P,finish:_,prepare:Q}=se(i,m,w,e.state.orientation,o),{angle:ee,changeAngle:te,interacting:re}=Y(e.state.angleDegrees,async t=>{Q(t>=90);try{await e.setAngle(t)}catch(c){throw _(),c}},d),T=()=>{j.current?.release(),b.current=void 0};u.useEffect(()=>{v.current=new E.DuoButtonSender((c,z)=>a.current.button(c,z),c=>d(String(c)));const t=()=>{T(),v.current?.release(),g(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),u.useEffect(()=>{j.current?.setDisplay(p,H),j.current?.active||(b.current=void 0)},[p,H]);const O=()=>{v.current?.release(),g(void 0)},q=t=>({disabled:e.watchOnly,onPointerDown:c=>{e.watchOnly||P||c.button!==0||(c.currentTarget.setPointerCapture(c.pointerId),v.current?.press(t),g(t))},onPointerUp:O,onPointerCancel:O,onLostPointerCapture:O,onBlur:O,onPointerEnter:()=>D(t),onPointerLeave:()=>D(void 0),onFocus:()=>h(w.guides.find(c=>c.button===t)?.edge),onKeyDown:c=>{P||(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.repeat||(v.current?.press(t),g(t)))},onKeyUp:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),O())}}),K=t=>{const c=t.currentTarget.getBoundingClientRect();return{x:(t.clientX-c.left)/c.width,y:(t.clientY-c.top)/c.height}};return r.jsxs("div",{className:o?"rc-duo":"rc-duo rc-duo-frameless",children:[r.jsxs("div",{ref:n,className:"rc-duo-flat-stage","data-folding":!!P,"aria-busy":!!P,onPointerMove:t=>{if(!o)return;const c=t.currentTarget.getBoundingClientRect();h(J(t.clientX-c.left,t.clientY-c.top,w.rect))},onPointerLeave:()=>{h(void 0),D(void 0)},children:[r.jsxs("div",{className:"rc-duo-flat-device","data-display":m?"inner":"outer",style:{width:R*M,height:F*M,transform:"translate(-50%, -50%) rotate("+w.turns*90+"deg)"},children:[o&&r.jsx(A,{inner:m,width:R,height:F}),r.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(R-W)/2*M,top:(F-I)/2*M,borderRadius:o?m?5.3*M:[.8,6.6,6.6,.8].map(t=>t*M+"px").join(" "):0},onKeyDown:P?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(e.watchOnly||P||b.current!==void 0||t.button!==0||!p)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const c=K(t);b.current=t.pointerId,j.current?.touch("begin",c.x,c.y)},onPointerMove:t=>{if(b.current!==t.pointerId)return;const c=K(t);j.current?.touch("move",c.x,c.y)},onPointerUp:t=>{b.current===t.pointerId&&T()},onPointerCancel:T,onLostPointerCapture:T,children:r.jsx("video",{ref:i,autoPlay:!0,muted:!0,playsInline:!0,style:{width:m?L:U,height:m?U:L,transform:"translate(-50%, -50%) rotate("+(m?90:0)+"deg)"}})}),o&&w.buttons.map(t=>r.jsx("button",{type:"button",className:"rc-duo-physical","data-duo-button":t.button,"data-edge":t.edge,"data-highlighted":N===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*M,top:t.y*M,width:t.edge==="top"?Math.max(28,t.width*M):28,height:t.edge==="top"?28:Math.max(28,t.height*M)},...q(t.button),children:r.jsx("span",{style:{width:Math.max(2,t.width*M),height:Math.max(2,t.height*M)}})},t.button))]}),o&&w.guides.map(t=>r.jsx("button",{type:"button",className:"rc-duo-hardware","data-duo-button":t.button,"data-visible":f===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":`${w.iconSize}px`,"--duo-hardware-icon-x":`${t.x-t.targetX}px`,"--duo-hardware-icon-y":`${t.y-t.targetY}px`},...q(t.button),children:r.jsx(G,{button:t.button})},t.button)),P&&r.jsx(ie,{motion:P,onFinish:_})]}),o&&r.jsx($,{watchOnly:e.watchOnly,angle:ee,changeAngle:te,interacting:re,rotate:()=>{e.setOrientation(e.state.orientation==="portrait"?"landscape-left":"portrait").catch(t=>d(String(t)))},children:r.jsx("span",{className:"rc-duo-view-label",children:"Front view"})}),x&&r.jsx("div",{role:"alert",className:"rc-duo-error",children:x})]})}const de=Object.freeze(Object.defineProperty({__proto__:null,default:ue},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=$;exports.DuoHardwareIcon=G;exports.duoView=de;exports.flatHoverEdge=J;exports.hardwareIconSize=Z;exports.useDuoHinge=Y;
@@ -1 +0,0 @@
1
- "use strict";require('./index.css');const f=require("react/jsx-runtime"),n=require("./core-BCBQrYsk.js"),l=require("react"),Bt=require("react-dom"),qt=async p=>{if(!p)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(p),!0}catch{}try{const i=document.createElement("textarea");i.value=p,i.style.position="fixed",i.style.opacity="0",document.body.appendChild(i),i.select();const g=document.execCommand("copy");return document.body.removeChild(i),g}catch{return!1}},Gt=l.memo(function({element:i,screen:g,highlighted:m,selected:I,selectable:K,onClick:M}){const y=n.clampAxFrameForScreen(i.frame,g);if(!y)return null;const j=n.axElementSummary(i);return f.jsx("button",{type:"button",className:i.enabled?"rc-inspect-box":"rc-inspect-box rc-inspect-box-disabled","data-ax-id":i.id,"data-ax-path":i.path,"data-ax-label":i.label||void 0,"data-ax-role":i.role||void 0,"data-highlighted":m?"true":"false","data-selected":I?"true":"false","aria-label":j,onClick:E=>{K&&(E.preventDefault(),E.stopPropagation(),M(i,{x:E.clientX,y:E.clientY}))},style:{left:`${y.x/g.width*100}%`,top:`${y.y/g.height*100}%`,width:`${y.width/g.width*100}%`,height:`${y.height/g.height*100}%`}})},(p,i)=>p.highlighted===i.highlighted&&p.selected===i.selected&&p.selectable===i.selectable&&p.screen.width===i.screen.width&&p.screen.height===i.screen.height&&p.onClick===i.onClick&&n.axElementsEqual(p.element,i.element)),Jt=260,Qt=220,Zt=6,eo=8,to=l.memo(function({element:i,platform:g,anchor:m,cursorAnchored:I,showActions:K,onTap:M}){const[y,j]=l.useState(null);l.useEffect(()=>{if(!y)return;const O=window.setTimeout(()=>j(null),1100);return()=>window.clearTimeout(O)},[y]);const E=l.useMemo(()=>{const O=Jt,$=Qt,W=Zt,N=eo,B=typeof window<"u"?window.innerWidth:1024,Ie=typeof window<"u"?window.innerHeight:768,F=m.x+W+O<=B-N,J=m.y-W-$>=N;let oe=F?m.x+W:m.x-W,de=J?m.y-W:m.y+W;const Q=`translate(${F?"0":"-100%"}, ${J?"-100%":"0"})`;return oe=Math.max(N+(F?0:O),Math.min(B-N-(F?O:0),oe)),de=Math.max(N+(J?$:0),Math.min(Ie-N-(J?0:$),de)),{left:`${oe}px`,top:`${de}px`,transform:Q}},[m.x,m.y]),_=l.useMemo(()=>n.axElementSelectorExpression(i,g),[i,g]),R=g==="ios"?i.selectors.AXUniqueId:i.selectors.resourceId,Y=g==="ios"?"AXUniqueId":"resourceId",z=l.useCallback(async(O,$)=>{if(!O)return;await qt(O)&&j($)},[]),G=n.axElementRoleLabel(i),V=i.label||i.value||G,te=n.axElementSummary(i);return Bt.createPortal(f.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":I?"true":"false",style:E,onClick:O=>O.stopPropagation(),onMouseDown:O=>O.stopPropagation(),onMouseMove:O=>O.stopPropagation(),children:[f.jsxs("div",{className:"rc-inspect-card-header",children:[f.jsx("span",{className:"rc-inspect-card-role",children:G}),!i.enabled&&f.jsx("span",{className:"rc-inspect-card-tag",children:"disabled"}),i.focused&&f.jsx("span",{className:"rc-inspect-card-tag rc-inspect-card-tag-blue",children:"focused"})]}),f.jsx("p",{className:"rc-inspect-card-title",title:te,children:V}),R&&f.jsxs("div",{className:"rc-inspect-card-row",children:[f.jsxs("span",{className:"rc-inspect-card-row-label",children:[Y,":"]}),f.jsx("span",{className:"rc-inspect-card-row-value",children:R})]}),i.value&&i.value!==i.label&&f.jsxs("div",{className:"rc-inspect-card-row",children:[f.jsx("span",{className:"rc-inspect-card-row-label",children:"value:"}),f.jsx("span",{className:"rc-inspect-card-row-value",children:i.value})]}),f.jsxs("div",{className:"rc-inspect-card-row",children:[f.jsx("span",{className:"rc-inspect-card-row-label",children:"frame:"}),f.jsxs("span",{className:"rc-inspect-card-row-value",children:[Math.round(i.frame.width),"×",Math.round(i.frame.height)," @ ",Math.round(i.frame.x),",",Math.round(i.frame.y)]})]}),K&&f.jsxs("div",{className:"rc-inspect-card-actions",children:[f.jsx("button",{type:"button",className:"rc-inspect-card-btn rc-inspect-card-btn-primary",disabled:!M,onClick:()=>M?.(i,m),children:"Tap"}),f.jsx("button",{type:"button",className:y==="selector"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!_,title:_??"No usable selector for this element",onClick:()=>z(_??void 0,"selector"),children:y==="selector"?"Copied!":"Copy selector"}),f.jsx("button",{type:"button",className:y==="id"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!R,title:R??`No ${Y}`,onClick:()=>z(R,"id"),children:y==="id"?"Copied!":`Copy ${Y}`})]})]}),document.body)}),oo=l.memo(function({snapshot:i,geometry:g,highlightedId:m,selectedId:I,mode:K,cursorPosition:M,frozenCursorPosition:y,onSelectChange:j,onTapElement:E}){const _=K==="select",R=_?m!==null&&m!==I:m!==null,Y=_?m??I:m,z=l.useMemo(()=>{const N=new Map;if(!i)return N;for(const B of i.elements)N.set(B.id,B);return N},[i]),G=l.useMemo(()=>Y?z.get(Y)??null:null,[Y,z]);if(!(!!i&&!!g&&i.screen.width>0&&i.screen.height>0&&i.elements.length>0))return null;const te=R?M:y??M,O=R,$=_&&!R&&I!==null,W=N=>{_&&N.target===N.currentTarget&&j(null,null)};return f.jsxs(f.Fragment,{children:[f.jsx("div",{className:_?"rc-inspect-overlay rc-inspect-overlay-select":"rc-inspect-overlay",style:{left:`${g.left}px`,top:`${g.top}px`,width:`${g.width}px`,height:`${g.height}px`},onClick:W,children:i.elements.map(N=>f.jsx(Gt,{element:N,screen:i.screen,highlighted:N.id===m,selected:N.id===I,selectable:_,onClick:j},N.id))}),G&&te&&f.jsx(to,{element:G,platform:i.platform,anchor:te,cursorAnchored:O,showActions:$,onTap:E})]})});function no(p,i){if(!i.startsWith("lim_st_"))return!1;try{const g=new URL(p).pathname.split("/").map(decodeURIComponent).find(E=>/^(ios|android)_[a-z0-9_]+$/.test(E));if(!g)return!1;const m=g.split("_")[0],I=i.slice(7).split(".");if(I.length!==3||I.some(E=>!E))return!1;const K=atob(I[1].replace(/-/g,"+").replace(/_/g,"/")),M=JSON.parse(new TextDecoder().decode(Uint8Array.from(K,E=>E.charCodeAt(0))));if(!M||typeof M!="object"||!("scopes"in M))return!1;const y=M.scopes;if(!Array.isArray(y)||!y.every(E=>typeof E=="string"))return!1;let j=!1;for(const E of y){const[_,R,Y,z]=E.split(":");if(!(z!==void 0||_!==m&&_!=="*")&&!(R!==g&&R!=="*")){if(Y==="stream"||Y==="all")return!1;Y==="watch"&&(j=!0)}}return j}catch{return!1}}const ro=l.lazy(()=>Promise.resolve().then(()=>require("./duo-view-PsR5b045.js")).then(p=>p.duoView)),ke=p=>Object.entries(n.AMOTION_EVENT).find(([g,m])=>g.startsWith("ACTION_")&&m===p)?.[0]??String(p),mt=1920,yt=1200,io=(p,i)=>p===mt&&i===yt||p===yt&&i===mt,co={ios:{videoBorderRadiusMultiplier:.15,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:.9678},landscape:{widthMultiplier:.9678}}},android:{videoBorderRadiusMultiplier:.13,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:.967},landscape:{widthMultiplier:.962}}},macos:{videoBorderRadiusMultiplier:0,loadingLogoSize:"10%",videoPosition:{portrait:{heightMultiplier:1},landscape:{widthMultiplier:1}}}},so={"iphone-se":{videoBorderRadiusMultiplier:0,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:667/889},landscape:{widthMultiplier:667/889}},homeButton:{offset:389/889,diameter:64/889}},"iphone-17e":{videoBorderRadiusMultiplier:47.33/452,loadingLogoSize:"20%",videoPosition:{portrait:{heightMultiplier:844/888},landscape:{widthMultiplier:844/888}}}},ao={videoBorderRadiusMultiplier:32/1837,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:2560/2798},landscape:{widthMultiplier:2560/2798}}};function lo(p){const i=p.code,g=n.codeMap[i];if(!g)return n.debugWarn(`Unknown event.code: ${i}, key: ${p.key}`),null;let m=n.ANDROID_KEYS.META_NONE;const I=i>="KeyA"&&i<="KeyZ",K=p.getModifierState("CapsLock"),M=p.shiftKey;let y=M;return I&&(y=M!==K),y&&(m|=n.ANDROID_KEYS.META_SHIFT_ON),p.ctrlKey&&(m|=n.ANDROID_KEYS.META_CTRL_ON),p.altKey&&(m|=n.ANDROID_KEYS.META_ALT_ON),p.metaKey&&(m|=n.ANDROID_KEYS.META_META_ON),{keycode:g,metaState:m}}function vt(p,i){const g=Object.keys(p);return g.length===Object.keys(i).length&&g.every(m=>p[m]===i[m])}const uo=l.forwardRef(({className:p,url:i,token:g,sessionId:m,openUrl:I,watchOnly:K=!1,showFrame:M=!0,deviceModel:y,duoModelUrl:j,autoReconnect:E,jitterBufferTargetMs:_,onPlaybackStats:R,onTerminated:Y,assets:z,onConnectionStateChange:G,inspectMode:V,onAxSnapshotChange:te,onInspectSelectionChange:O,onAxStatusChange:$,axPollIntervalMs:W,axMaxBackoffMs:N,androidElementTreeOptions:B,onCameraDemandChange:Ie,onCameraStats:F,onTrace:J,microphoneEnabled:oe=!1,onMicrophoneStateChange:de},ze)=>{const Be=l.useMemo(()=>no(i,g),[i,g]),Q=K||Be,Me=l.useRef(null),C=l.useRef(null),qe=l.useRef(null),[Tt,Et]=l.useState(!1),U=y==="iphone-duo"||Tt,Re=y==="iphone-duo"?y:void 0,be=l.useRef(null),[Ge,Nt]=l.useState(null),[Je,At]=l.useState(),[wt,Ot]=l.useState(!1),[It,Mt]=l.useState(!1),[Rt,bt]=l.useState(!1),[We,Qe]=l.useState(!1),[Ze,et]=l.useState(!1),[_t,tt]=l.useState({}),[ot,nt]=l.useState(null),Xe=l.useRef(null),D=l.useRef(new Map),ne=l.useRef(!1),[Ct,St]=l.useState(!1),b=l.useRef(null),ue=l.useRef(null),Te=l.useRef({handle:()=>{},end:()=>{}}),[re,_e]=l.useState(null),[rt,He]=l.useState(null),[je,Ee]=l.useState(null),[Ve,Ce]=l.useState(null),[Dt,it]=l.useState(null),[xt,ct]=l.useState(null),Se=l.useRef(null),q=l.useRef(void 0),st=e=>{Se.current=e,q.current===void 0&&(q.current=window.requestAnimationFrame(()=>{q.current=void 0,ct(Se.current)}))},[Pt,he]=l.useState(null),ie=l.useRef(null);ie.current=rt;const fe=l.useRef(O);fe.current=O;const ce=V===!0||V==="hover-only",at=l.useRef(ce);at.current=ce;const Yt=V==="hover-only"?"hover-only":"select",x=l.useMemo(()=>n.detectPlatform(i),[i]),Lt=l.useMemo(()=>m||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[m]),Ne=x==="ios"&&y&&y!=="iphone-duo"?y:void 0,se=x==="android"&&Ze?ao:Ne?so[Ne]:co[x],pe=z?.[x],lt=Ne&&pe?.modelFrames?.[Ne],dt=x==="android"&&Ze?We?pe?.tabletFrameLandscape:pe?.tabletFrame:Ne?We?lt?.frameLandscape:lt?.frame:We?pe?.frameLandscape:pe?.frame,ut=pe?.loadingLogo,Ae=!U&&M&&!!dt,T=l.useRef(null),X=e=>T.current?.sendControl(e),De=l.useRef(new Set),xe=l.useCallback(()=>{for(const e of De.current)T.current?.sendControl(n.createMacKeyMessage(n.MAC_INPUT_ACTION.UP,e));De.current.clear()},[]),Ke=(e,o)=>T.current?.sendDuoControl(e,o)??Promise.reject(new Error("Simulator disconnected")),ht=-10,ft=(e,o)=>{const r=me();if(!r)return;const t=Z(r,e,o);if(!t)return;const{videoX:a,videoY:c,videoWidth:s,videoHeight:u}=t,d=n.createTouchControlMessage(n.AMOTION_EVENT.ACTION_DOWN,ht,s,u,a,c,1,n.AMOTION_EVENT.BUTTON_PRIMARY,n.AMOTION_EVENT.BUTTON_PRIMARY);d&&X(d),window.setTimeout(()=>{const h=n.createTouchControlMessage(n.AMOTION_EVENT.ACTION_UP,ht,s,u,a,c,0,n.AMOTION_EVENT.BUTTON_PRIMARY,n.AMOTION_EVENT.BUTTON_PRIMARY);h&&X(h)},60)},kt=(e,o)=>{const r=me();if(!r||o.screen.width<=0||o.screen.height<=0)return;const t=e.frame.x+e.frame.width/2,a=e.frame.y+e.frame.height/2,c=t/o.screen.width*r.actualWidth,s=a/o.screen.height*r.actualHeight,u=r.videoRect.left+r.offsetX+c,d=r.videoRect.top+r.offsetY+s;ft(u,d)},Pe=-1,Ye=-2,ae=-3,ge=(e,o,r,t,a,c)=>{const s=n.createTouchControlMessage(e,o,r,t,a,c,1,n.AMOTION_EVENT.BUTTON_PRIMARY,n.AMOTION_EVENT.BUTTON_PRIMARY);s&&(n.debugLog("[rc-touch] sendSingleTouch",{action:e,actionName:ke(e),pointerId:o,x:a,y:c,video:{width:r,height:t}}),X(s))},le=(e,o,r)=>{if(!r)return;const{videoX:t,videoY:a,videoWidth:c,videoHeight:s}=r;let u=null,d=null,h=1;const S=n.AMOTION_EVENT.BUTTON_PRIMARY;switch(o){case"down":e!==ae&&Te.current.end(),u=D.current.size===0?n.AMOTION_EVENT.ACTION_DOWN:n.AMOTION_EVENT.ACTION_POINTER_DOWN,d={x:t,y:a},D.current.set(e,d),e===-1&&C.current?.focus();break;case"move":D.current.has(e)&&(u=n.AMOTION_EVENT.ACTION_MOVE,d={x:t,y:a},D.current.set(e,d));break;case"up":case"cancel":D.current.has(e)&&(d=D.current.get(e),D.current.delete(e),o==="cancel"?u=n.AMOTION_EVENT.ACTION_CANCEL:u=D.current.size===0?n.AMOTION_EVENT.ACTION_UP:n.AMOTION_EVENT.ACTION_POINTER_UP);break}if(u!==null&&d!==null){n.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:o,action:u,actionName:ke(u),positionToSend:d,video:{width:c,height:s},altHeld:ne.current,activePointersAfter:Array.from(D.current.entries()).map(([P,w])=>({id:P,x:w.x,y:w.y}))});const A=n.createTouchControlMessage(u,e,c,s,d.x,d.y,h,S,S);A&&(n.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:ke(u),byteLength:A.byteLength}),X(A))}else(o==="up"||o==="cancel")&&D.current.delete(e)},Ue=e=>{if(ne.current!==e&&(ne.current=e,St(e),e||_e(null),n.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from(D.current.keys())}),x==="ios"&&T.current?.getState().controlReady)){const o=e?n.ANDROID_KEYS.ACTION_DOWN:n.ANDROID_KEYS.ACTION_UP,r=n.createInjectKeycodeMessage(o,n.ANDROID_KEYS.KEYCODE_ALT_LEFT,0,n.ANDROID_KEYS.META_NONE);n.debugLog("[rc-touch][alt] sending Indigo modifier keycode",{action:o,keycode:n.ANDROID_KEYS.KEYCODE_ALT_LEFT}),r&&X(r)}},me=()=>{const e=C.current,o=Me.current;if(!e||!o)return null;const r=e.videoWidth,t=e.videoHeight;if(!r||!t)return null;const a=e.getBoundingClientRect(),c=o.getBoundingClientRect(),s=a.width,u=a.height,d=r/t,h=s/u;let S=s,A=u;d>h?A=s/d:S=u*d;const P=(s-S)/2,w=(u-A)/2;return{videoWidth:r,videoHeight:t,videoRect:a,containerRect:c,actualWidth:S,actualHeight:A,offsetX:P,offsetY:w}},Z=(e,o,r)=>{const t=o-e.videoRect.left-e.offsetX,a=r-e.videoRect.top-e.offsetY,c=Math.max(0,Math.min(e.actualWidth,t)),s=Math.max(0,Math.min(e.actualHeight,a)),u=Math.max(0,Math.min(e.videoWidth,c/e.actualWidth*e.videoWidth)),d=Math.max(0,Math.min(e.videoHeight,s/e.actualHeight*e.videoHeight));return{videoX:u,videoY:d,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Wt=(e,o,r)=>{const t=o-e.videoRect.left-e.offsetX,a=r-e.videoRect.top-e.offsetY,c=Math.max(0,Math.min(e.actualWidth,t)),s=Math.max(0,Math.min(e.actualHeight,a)),u=Math.max(0,Math.min(e.videoWidth,c/e.actualWidth*e.videoWidth)),d=Math.max(0,Math.min(e.videoHeight,s/e.actualHeight*e.videoHeight)),h=e.videoWidth-u,S=e.videoHeight-d,A=e.videoRect.left+e.offsetX,P=e.videoRect.top+e.offsetY,w=A-e.containerRect.left+c,L=P-e.containerRect.top+s,k=A-e.containerRect.left+(e.actualWidth-c),v=P-e.containerRect.top+(e.actualHeight-s);return{containerX:w,containerY:L,mirrorContainerX:k,mirrorContainerY:v,videoX:u,videoY:d,mirrorVideoX:h,mirrorVideoY:S,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Xt=(e,o,r,t,a,c,s)=>{const u=n.createTwoFingerTouchControlMessage(e,o,r,t,a,c,s);n.debugLog("[rc-touch2] sendTwoFingerMessage (iOS)",{actionName:ke(e),video:{width:o,height:r},p0:{x:t,y:a},p1:{x:c,y:s},byteLength:u.byteLength}),X(u)},ye=(e,o,r,t,a,c,s,u,d)=>{if(n.debugLog("[rc-touch2] applyTwoFingerEvent",{platform:x,eventType:e,video:{width:o,height:r},p0:{x:t,y:a,id:u},p1:{x:c,y:s,id:d}}),e==="down"&&Te.current.end(),x==="ios"){const h=e==="down"?n.AMOTION_EVENT.ACTION_DOWN:e==="move"?n.AMOTION_EVENT.ACTION_MOVE:n.AMOTION_EVENT.ACTION_UP;Xt(h,o,r,t,a,c,s)}else e==="down"?(ge(n.AMOTION_EVENT.ACTION_DOWN,u,o,r,t,a),ge(n.AMOTION_EVENT.ACTION_POINTER_DOWN,d,o,r,c,s)):e==="move"?(ge(n.AMOTION_EVENT.ACTION_MOVE,u,o,r,t,a),ge(n.AMOTION_EVENT.ACTION_MOVE,d,o,r,c,s)):(ge(n.AMOTION_EVENT.ACTION_POINTER_UP,d,o,r,c,s),ge(n.AMOTION_EVENT.ACTION_UP,u,o,r,t,a))},Ht=(e,o,r)=>{if(!ne.current){re!==null&&_e(null);return}const t=Wt(e,o,r);_e(t)},jt=(e,o,r)=>{const t=ie.current;if(!t||t.screen.width<=0||t.screen.height<=0)return null;const a=o-e.videoRect.left-e.offsetX,c=r-e.videoRect.top-e.offsetY;if(a<0||c<0||a>e.actualWidth||c>e.actualHeight)return null;const s=a/e.actualWidth*t.screen.width,u=c/e.actualHeight*t.screen.height;return n.axElementAtPoint(t,s,u)},ee=e=>{if(U)return;e.preventDefault(),e.stopPropagation();const o=me();if((V===!0||V==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(st({x:e.clientX,y:e.clientY}),o){const t=jt(o,e.clientX,e.clientY);Ee(t?.id??null)}}else e.type==="mouseleave"&&(st(null),Ee(null));if(V!==!0){if(x==="macos"){if("touches"in e||!o||!T.current?.getState().controlReady)return;const t=Z(o,e.clientX,e.clientY);if(!t)return;const a=e.type==="mousedown"?n.MAC_INPUT_ACTION.DOWN:e.type==="mouseup"?n.MAC_INPUT_ACTION.UP:n.MAC_INPUT_ACTION.MOVE,c=e.type==="mouseleave"?0:e.buttons;e.type==="mousedown"&&C.current?.focus(),X(n.createMouseControlMessage(a,t.videoWidth,t.videoHeight,t.videoX,t.videoY,c));return}if(!("touches"in e)&&o&&(e.type==="mousemove"?Ht(o,e.clientX,e.clientY):e.type==="mouseleave"&&_e(null)),!(!T.current?.getState().controlReady||!C.current||!o))if("touches"in e){const t=e.touches,a=e.changedTouches;let c;switch(e.type){case"touchstart":c="down";break;case"touchmove":c="move";break;case"touchend":c="up";break;case"touchcancel":c="cancel";break;default:return}if(t.length===2){const s=t[0],u=t[1],d=Z(o,s.clientX,s.clientY),h=Z(o,u.clientX,u.clientY);if(!d||!h)return;b.current?b.current.source==="real-touch"&&(b.current.finger0={x:d.videoX,y:d.videoY},b.current.finger1={x:h.videoX,y:h.videoY},ye("move",d.videoWidth,d.videoHeight,d.videoX,d.videoY,h.videoX,h.videoY,b.current.pointerId0,b.current.pointerId1)):(b.current={finger0:{x:d.videoX,y:d.videoY},finger1:{x:h.videoX,y:h.videoY},videoSize:{width:d.videoWidth,height:d.videoHeight},source:"real-touch",pointerId0:s.identifier,pointerId1:u.identifier},ye("down",d.videoWidth,d.videoHeight,d.videoX,d.videoY,h.videoX,h.videoY,s.identifier,u.identifier))}else if(t.length<2&&b.current?.source==="real-touch"){const s=b.current;ye("up",s.videoSize.width,s.videoSize.height,s.finger0.x,s.finger0.y,s.finger1.x,s.finger1.y,s.pointerId0,s.pointerId1),b.current=null;return}else{if(t.length>2)return;{const s=a[0];if(s){const u=Z(o,s.clientX,s.clientY);le(s.identifier,c,u)}}}}else{let a=null;const c=b.current?.source==="alt-mouse";switch(e.type){case"mousedown":e.button===0&&(a="down");break;case"mousemove":(c||D.current.has(-1))&&(a="move");break;case"mouseup":e.button===0&&(a="up");break;case"mouseleave":(c||D.current.has(-1))&&(a="up");break}if(a){const s=Z(o,e.clientX,e.clientY);if(!s)return;n.debugLog("[rc-touch][mouse] event",{domType:e.type,eventType:a,button:e.button,buttons:e.buttons,client:{x:e.clientX,y:e.clientY},altHeldRef:ne.current,inTwoFingerMode:c,geometry:{videoX:s.videoX,videoY:s.videoY,videoWidth:s.videoWidth,videoHeight:s.videoHeight},activePointerIds:Array.from(D.current.keys())}),ne.current||c?Vt(a,s):le(-1,a,s)}}}},Vt=(e,o)=>{const{videoX:r,videoY:t,videoWidth:a,videoHeight:c}=o,s=a-r,u=c-t;if(e==="down"){b.current={finger0:{x:r,y:t},finger1:{x:s,y:u},videoSize:{width:a,height:c},source:"alt-mouse",pointerId0:Pe,pointerId1:Ye},C.current?.focus(),ye("down",a,c,r,t,s,u,Pe,Ye);return}if(e==="move"){b.current?.source==="alt-mouse"&&(b.current.finger0={x:r,y:t},b.current.finger1={x:s,y:u},ye("move",a,c,r,t,s,u,Pe,Ye));return}if(e==="up"||e==="cancel"){const d=b.current;if(d?.source==="alt-mouse"){const{finger0:h,finger1:S,videoSize:A}=d;ye("up",A.width,A.height,h.x,h.y,S.x,S.y,Pe,Ye),b.current=null}return}},Kt=150,pt=()=>{const e=ue.current;e&&(window.clearTimeout(e.endTimer),le(ae,"up",e.pos),ue.current=null)},Ut=e=>{if(!T.current?.getState().controlReady||e.ctrlKey)return;if(x==="macos"){const v=me();if(!v)return;const ve=e.clientX-v.videoRect.left-v.offsetX,we=e.clientY-v.videoRect.top-v.offsetY;if(ve<0||ve>v.actualWidth||we<0||we>v.actualHeight)return;const Oe=Z(v,e.clientX,e.clientY);if(!Oe)return;e.preventDefault();const gt=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?v.actualHeight:1;X(n.createMacScrollMessage(Oe.videoWidth,Oe.videoHeight,Oe.videoX,Oe.videoY,e.deltaX*gt,e.deltaY*gt));return}if(ne.current||b.current)return;const o=D.current.size;if(o>1||o===1&&!D.current.has(ae))return;const r=me();if(!r)return;const t=e.clientX-r.videoRect.left-r.offsetX,a=e.clientY-r.videoRect.top-r.offsetY;if(t<0||t>r.actualWidth||a<0||a>r.actualHeight)return;const c=Z(r,e.clientX,e.clientY);if(!c)return;e.preventDefault();const s=(e.deltaMode===1?16:e.deltaMode===2?r.actualWidth:1)*(r.videoWidth/r.actualWidth),u=(e.deltaMode===1?16:e.deltaMode===2?r.actualHeight:1)*(r.videoHeight/r.actualHeight),d=-e.deltaX*s,h=-e.deltaY*u,S=v=>{window.clearTimeout(v.endTimer),v.endTimer=window.setTimeout(pt,Kt)};if(d===0&&h===0){ue.current&&S(ue.current);return}const A=()=>({videoWidth:c.videoWidth,videoHeight:c.videoHeight,videoX:Math.abs(d)>Math.abs(h)?Math.min(Math.max(c.videoX,c.videoWidth*.2),c.videoWidth*.8):c.videoX,videoY:Math.abs(h)>=Math.abs(d)?Math.min(Math.max(c.videoY,c.videoHeight*.2),c.videoHeight*.8):c.videoY}),P=v=>({...v,videoX:Math.min(Math.max(v.videoX+d,0),v.videoWidth),videoY:Math.min(Math.max(v.videoY+h,0),v.videoHeight)});let w=ue.current;if(w)window.clearTimeout(w.endTimer);else{const v=A();le(ae,"down",v),w={pos:v,endTimer:0},ue.current=w}let L=w.pos,k=P(L);k.videoX===L.videoX&&k.videoY===L.videoY&&(le(ae,"up",L),L=A(),le(ae,"down",L),k=P(L)),le(ae,"move",k),w.pos=k,S(w)};l.useEffect(()=>{Te.current={handle:Ut,end:pt}}),l.useEffect(()=>{const e=Me.current;if(!e)return;const o=r=>Te.current.handle(r);return e.addEventListener("wheel",o,{passive:!1}),()=>{Te.current.end(),e.removeEventListener("wheel",o)}},[]),l.useEffect(()=>{const e=a=>{a.key==="Alt"&&Ue(!0)},o=a=>{a.key==="Alt"&&Ue(!1)},r=()=>{Ue(!1),xe()},t=()=>{document.hidden&&xe()};return window.addEventListener("keydown",e,!0),window.addEventListener("keyup",o,!0),window.addEventListener("blur",r),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("keydown",e,!0),window.removeEventListener("keyup",o,!0),window.removeEventListener("blur",r),document.removeEventListener("visibilitychange",t)}},[xe]);const Le=e=>{e.preventDefault(),e.stopPropagation();const o=document.activeElement===C.current||U&&document.activeElement===e.currentTarget;if(n.debugLog("Keyboard event:",{type:e.type,key:e.key,keyCode:e.keyCode,code:e.code,target:e.target.tagName,focused:o}),!o){n.debugWarn("Simulator input not focused, skipping keyboard event");return}if(!T.current?.getState().controlReady){n.debugWarn("Data channel not ready for keyboard event:",T.current?.getState().connection);return}if(x==="macos"){if(e.type==="keydown"&&e.repeat)return;const t=n.macKeyCodeFor(e.code);if(t===void 0){n.debugLog(`Ignoring unmapped key for macOS: code=${e.code}`);return}e.type==="keydown"?De.current.add(t):De.current.delete(t),X(n.createMacKeyMessage(e.type==="keydown"?n.MAC_INPUT_ACTION.DOWN:n.MAC_INPUT_ACTION.UP,t));return}if(e.type==="keydown"){if(e.key.toLowerCase()==="v"&&(e.metaKey||e.ctrlKey)){n.debugLog("Paste shortcut detected"),navigator.clipboard.readText().then(t=>{if(t){n.debugLog("Pasting text via SET_CLIPBOARD:",t.substring(0,20)+(t.length>20?"...":""));const a=n.createSetClipboardMessage(t,!0);X(a)}}).catch(t=>{console.error("Failed to read clipboard contents: ",t)});return}if(e.key.toLowerCase()==="m"&&(e.metaKey||e.ctrlKey)){n.debugLog("Menu shortcut detected");const t=n.createInjectKeycodeMessage(n.ANDROID_KEYS.ACTION_DOWN,n.ANDROID_KEYS.MENU,0,n.ANDROID_KEYS.META_NONE);X(t);const a=n.createInjectKeycodeMessage(n.ANDROID_KEYS.ACTION_UP,n.ANDROID_KEYS.MENU,0,n.ANDROID_KEYS.META_NONE);X(a);return}}const r=lo(e);if(r){const{keycode:t,metaState:a}=r,c=e.type==="keydown"?n.ANDROID_KEYS.ACTION_DOWN:n.ANDROID_KEYS.ACTION_UP;n.debugLog(`Sending Keycode: key=${e.key}, code=${t}, action=${c}, meta=${a}`);const s=n.createInjectKeycodeMessage(c,t,0,a);X(s)}else n.debugLog(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`)},$t=e=>{e.stopPropagation(),T.current?.reconnect()},H=l.useRef({onAxSnapshotChange:te,onAxStatusChange:$,onCameraDemandChange:Ie,onCameraStats:F,onMicrophoneStateChange:de,onTrace:J,onTerminated:Y,onConnectionStateChange:G,onPlaybackStats:R});H.current={onAxSnapshotChange:te,onAxStatusChange:$,onCameraDemandChange:Ie,onCameraStats:F,onMicrophoneStateChange:de,onTrace:J,onTerminated:Y,onConnectionStateChange:G,onPlaybackStats:R};const $e=!!J;l.useEffect(()=>{Xe.current=null,Qe(!1),et(!1),tt({}),nt(null)},[i,Re]),l.useEffect(()=>{let e=!0;ie.current!==null&&(ie.current=null,He(null),n.safeInvoke("onAxSnapshotChange",H.current.onAxSnapshotChange,null));const o=n.createDeviceStream({url:i,token:g,sessionId:Lt,watchOnly:Q,deviceModel:Re,autoReconnect:E,jitterBufferTargetMs:_,openUrl:I,inspectMode:V,axPollIntervalMs:W,axMaxBackoffMs:N,androidElementTreeOptions:B,microphoneEnabled:oe,onStateChange:t=>{(t.videoReady||t.connection==="idle"||t.connection==="connecting"||t.connection==="reconnecting")&&Ot(t.videoReady),Mt(t.connection==="failed"),bt(t.connection==="terminated"),Et(t.duo),Nt(t.duoState),At(t.duoError)},onAxSnapshotChange:t=>{e&&(He(a=>n.axSnapshotsEqual(a,t)?a:t),H.current.onAxSnapshotChange?.(t))},onAxStatusChange:(...t)=>H.current.onAxStatusChange?.(...t),onCameraDemandChange:(...t)=>H.current.onCameraDemandChange?.(...t),onCameraStats:F?(...t)=>H.current.onCameraStats?.(...t):void 0,onMicrophoneStateChange:(...t)=>H.current.onMicrophoneStateChange?.(...t),onTrace:$e?(...t)=>H.current.onTrace?.(...t):void 0,onTerminated:()=>H.current.onTerminated?.(),onConnectionStateChange:(...t)=>H.current.onConnectionStateChange?.(...t),onPlaybackStats:R?(...t)=>H.current.onPlaybackStats?.(...t):void 0});T.current=o;const r=C.current?o.attachVideo(C.current):void 0;return o.start(),()=>{e=!1,o.dispose(),r?.(),T.current=null}},[i,m,Re,$e,Q]),l.useEffect(()=>{if(U&&be.current)return T.current?.attachVideo(be.current,"inner")},[U,i,m,Re,$e,Q]),l.useEffect(()=>{T.current?.updateOptions({token:g,openUrl:I,axPollIntervalMs:W,axMaxBackoffMs:N,androidElementTreeOptions:B,autoReconnect:E,jitterBufferTargetMs:_,microphoneEnabled:oe,inspectMode:V,onPlaybackStats:R?(...e)=>H.current.onPlaybackStats?.(...e):void 0,onCameraStats:F?(...e)=>H.current.onCameraStats?.(...e):void 0})},[g,E,_,oe,V,!!R,!!F,I,W,N,B]);const Fe=()=>{if(!at.current)return;const e=me();if(!e){it(null);return}const o={left:e.videoRect.left-e.containerRect.left+e.offsetX,top:e.videoRect.top-e.containerRect.top+e.offsetY,width:e.actualWidth,height:e.actualHeight};it(r=>r&&r.left===o.left&&r.top===o.top&&r.width===o.width&&r.height===o.height?r:o)};l.useEffect(()=>{const e=C.current,o=qe.current,r=Me.current;if(!e)return;const t=d=>tt(h=>vt(h,d)?h:d),a=d=>nt(h=>h&&d&&vt(h,d)?h:d),c=()=>{const d=e.videoWidth>0&&e.videoHeight>0;d&&(Xe.current={width:e.videoWidth,height:e.videoHeight});const h=Xe.current,S=h?`${h.width} / ${h.height}`:void 0;if(!Ae||!o){t(!d&&h?{aspectRatio:S,contain:"size",containIntrinsicSize:`${h.width}px ${h.height}px`}:{}),a(null),Fe();return}const A=o.clientWidth,P=o.clientHeight;if(A===0||P===0)return;const w=h?h.width>h.height:!1;Qe(w),et(x==="android"&&!!h&&io(h.width,h.height));const L=w?se.videoPosition.landscape:se.videoPosition.portrait;let k={aspectRatio:S};L.heightMultiplier?(k.height=`${P*L.heightMultiplier}px`,k.width="auto"):L.widthMultiplier&&(k.width=`${A*L.widthMultiplier}px`,k.height="auto"),k.borderRadius=`${w?P*se.videoBorderRadiusMultiplier:A*se.videoBorderRadiusMultiplier}px`,t(k);const v=se.homeButton,ve=w?A:P,we=`calc(50% + ${ve*(v?.offset??0)}px)`;a(v?{width:`${ve*v.diameter}px`,height:`${ve*v.diameter}px`,left:w?we:"50%",top:w?"50%":we}:null),Fe()},s=new ResizeObserver(()=>{c()});o&&s.observe(o),s.observe(e),r&&s.observe(r),o&&o.addEventListener("load",c),e.addEventListener("loadedmetadata",c),e.addEventListener("resize",c);const u=()=>T.current?.bumpActivity();return e.addEventListener("resize",u),c(),()=>{s.disconnect(),e.removeEventListener("loadedmetadata",c),e.removeEventListener("resize",c),e.removeEventListener("resize",u),o&&o.removeEventListener("load",c)}},[se,Ae,i,y]),l.useEffect(()=>{ce?Fe():(He(null),Ee(null),Ce(null),ct(null),he(null),Se.current=null,q.current!==void 0&&(window.cancelAnimationFrame(q.current),q.current=void 0))},[ce]),l.useEffect(()=>()=>{q.current!==void 0&&(window.cancelAnimationFrame(q.current),q.current=void 0)},[]),l.useEffect(()=>{if(!ce)return;const e=o=>{o.key==="Escape"&&(Ve||je)&&(Ce(null),Ee(null),he(null),n.safeInvoke("onInspectSelectionChange",fe.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ce,Ve,je]);const Ft=()=>{C.current&&C.current.focus()};l.useImperativeHandle(ze,()=>({openUrl:e=>T.current?.openUrl(e),sendKeyEvent:e=>T.current?.sendKeyEvent(e),screenshot:e=>T.current?.screenshot(e)??Promise.reject(new Error("Simulator disconnected")),terminateApp:e=>T.current?.terminateApp(e)??Promise.reject(new Error("Simulator disconnected")),reconnect:()=>T.current?.reconnect(),refreshAxTree:()=>T.current?.refreshAxTree()??Promise.reject(new Error("Simulator disconnected")),getAxSnapshot:()=>T.current?.getAxSnapshot()??null,setInspectHighlight:e=>{Ee(e?.id??null)},setInspectSelection:e=>{Ce(e?.id??null),he(e?Se.current:null);const o=ie.current;e&&o?n.safeInvoke("onInspectSelectionChange",fe.current,{element:e,snapshot:o}):n.safeInvoke("onInspectSelectionChange",fe.current,null)},getAxStatus:()=>T.current?.getAxStatus()??"idle"}));const zt=Ct&&re!==null;return f.jsxs("div",{ref:Me,className:["rc-container",p].filter(Boolean).join(" "),style:{touchAction:"none"},onMouseDown:ee,onMouseMove:ee,onMouseUp:ee,onMouseLeave:ee,onTouchStart:ee,onTouchMove:ee,onTouchEnd:ee,onTouchCancel:ee,onContextMenu:x==="macos"?e=>e.preventDefault():void 0,children:[zt&&re&&f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"rc-touch-indicator",style:{left:`${re.containerX}px`,top:`${re.containerY}px`}}),f.jsx("div",{className:"rc-touch-indicator",style:{left:`${re.mirrorContainerX}px`,top:`${re.mirrorContainerY}px`}})]}),Ae&&f.jsx("img",{ref:qe,src:dt,alt:"",className:x==="ios"?"rc-phone-frame rc-phone-frame-ios":"rc-phone-frame",draggable:!1}),Ae&&ot&&!Q&&f.jsx("button",{type:"button",className:"rc-home-button","aria-label":"Home",title:"Home",style:ot,onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),onTouchEnd:e=>{e.stopPropagation(),e.preventDefault(),T.current?.pressButton("home")},onClick:e=>{e.stopPropagation(),T.current?.pressButton("home")}}),f.jsx("video",{ref:C,className:["rc-video",!Ae&&"rc-video-frameless",!wt&&(x==="macos"?"rc-video-loading-desktop":"rc-video-loading")].filter(Boolean).join(" "),style:{..._t,...U?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...ut?{backgroundImage:`url("${ut}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:se.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:U?-1:0,onKeyDown:Le,onKeyUp:Le,onClick:Ft,onFocus:()=>{C.current&&(C.current.style.outline="none")},onBlur:()=>{C.current&&(C.current.style.outline="none"),xe()}}),U&&f.jsx("video",{ref:be,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),U&&Ge&&f.jsx(l.Suspense,{fallback:f.jsx("div",{children:"Loading iPhone Duo…"}),children:f.jsx(ro,{watchOnly:Q,showFrame:M,modelUrl:j,outer:C.current,inner:be.current,state:Ge,setAngle:e=>Ke("setHingeAngle",{angleDegrees:e}),setOrientation:e=>Ke("setDuoOrientation",{orientation:e}),button:(e,o)=>Ke("performActions",{actions:[{type:o?"buttonDown":"buttonUp",button:e}]}),touch:(e,o,r,t)=>{T.current?.sendDisplayTouch(e,o,r,t)},onKeyDown:Le,onKeyUp:Le})}),U&&Je&&f.jsx("div",{role:"alert",className:"rc-duo-error",children:Je}),!U&&ce&&f.jsx(oo,{snapshot:rt,geometry:Dt,highlightedId:je,selectedId:Ve,mode:Yt,cursorPosition:xt,frozenCursorPosition:Pt,onSelectChange:(e,o)=>{Ce(e?.id??null),e&&o?he(o):e||he(null);const r=ie.current;e&&r?n.safeInvoke("onInspectSelectionChange",fe.current,{element:e,snapshot:r}):n.safeInvoke("onInspectSelectionChange",fe.current,null)},onTapElement:Q?void 0:((e,o)=>{if(o){ft(o.x,o.y);return}const r=ie.current;r&&kt(e,r)})}),Rt?f.jsxs("div",{className:"rc-terminated",role:"status",children:[f.jsx("div",{className:"rc-terminated-title",children:"Instance terminated"}),f.jsx("div",{className:"rc-terminated-message",children:"This instance no longer exists and can't be reconnected."})]}):It&&f.jsx("button",{type:"button",className:"rc-retry-button",onClick:$t,children:"Retry"})]})});exports.RemoteControl=uo;