@limrun/ui 0.22.5 → 0.22.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lite.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./remote-control-CEVcOPQZ.js"),e=require("./core-BCBQrYsk.js");exports.RemoteControl=r.RemoteControl;exports.AX_UNAVAILABLE_ERROR=e.AX_UNAVAILABLE_ERROR;exports.axElementAtPoint=e.axElementAtPoint;exports.axElementSelectorExpression=e.axElementSelectorExpression;exports.axElementSummary=e.axElementSummary;exports.axElementsEqual=e.axElementsEqual;exports.axSnapshotsEqual=e.axSnapshotsEqual;exports.clampAxFrameForScreen=e.clampAxFrameForScreen;exports.normalizeAndroidTree=e.normalizeAndroidTree;exports.normalizeIosTree=e.normalizeIosTree;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./remote-control-D_851mel.js"),e=require("./core-B3nWmNki.js");exports.RemoteControl=r.RemoteControl;exports.AX_UNAVAILABLE_ERROR=e.AX_UNAVAILABLE_ERROR;exports.axElementAtPoint=e.axElementAtPoint;exports.axElementSelectorExpression=e.axElementSelectorExpression;exports.axElementSummary=e.axElementSummary;exports.axElementsEqual=e.axElementsEqual;exports.axSnapshotsEqual=e.axSnapshotsEqual;exports.clampAxFrameForScreen=e.clampAxFrameForScreen;exports.normalizeAndroidTree=e.normalizeAndroidTree;exports.normalizeIosTree=e.normalizeIosTree;
package/dist/lite.js CHANGED
@@ -1,5 +1,5 @@
1
- import { R as o } from "./remote-control-BX6dzHtt.mjs";
2
- import { A as s, a as m, b as n, c as t, d as l, e as x, f as E, n as A, g as i } from "./core-nbvkIrvp.mjs";
1
+ import { R as o } from "./remote-control-cQIifCub.mjs";
2
+ import { A as s, a as m, b as n, c as t, d as l, e as x, f as E, n as A, g as i } from "./core-B7MkSLE_.mjs";
3
3
  export {
4
4
  s as AX_UNAVAILABLE_ERROR,
5
5
  o as RemoteControl,
@@ -1,6 +1,6 @@
1
1
  import { jsxs as _, jsx as M } from "react/jsx-runtime";
2
2
  import { useRef as E, useState as ne, useId as ze, useEffect as Pe } from "react";
3
- import { M as L, l as q, m as $e, a as Ze, b as qe, c as Je, s as Qe, d as et, e as Ce } from "./remote-control-BX6dzHtt.mjs";
3
+ import { M as L, l as q, m as $e, a as Ze, b as qe, c as Je, s as Qe, d as et, e as Ce } from "./remote-control-cQIifCub.mjs";
4
4
  import { u as tt, P as ot, c as rt, V as nt, S as st, L as Ie, M as it, D as Re, G as se, B as ct, I as at, a as ie, b as ce, d as Ne, l as lt, T as dt, R as ut, e as F, f as _e, g as ft, h as pt, i as R } from "./model-source-CN_i4mVy.mjs";
5
5
  const T = {
6
6
  front: { yaw: 0, pitch: 0.1, label: "Front" },
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),f=require("react"),c=require("./remote-control-CEVcOPQZ.js"),r=require("./model-source-D3_k9qRK.js"),N={front:{yaw:0,pitch:.1,label:"Front"},desk:{yaw:-.5,pitch:.42,label:"Desk"},side:{yaw:-1.15,pitch:.16,label:"Side"}},Oe=28,Ie={environment:.45,hemisphere:1,key:{intensity:2.2,position:[-120,220,260]},rim:{intensity:.7,position:[220,40,-220]}};function Ne(v,j){const n=r.DoubleSide;switch(v){case"screen":return j;case"shell":return new r.MeshStandardMaterial({color:3421498,metalness:.9,roughness:.34,side:n});case"glass":return new r.MeshPhysicalMaterial({color:328966,roughness:.06,clearcoat:1,side:n});case"camera":return new r.MeshStandardMaterial({color:790549,roughness:.2,side:n});case"well":return new r.MeshStandardMaterial({color:1052690,roughness:.9,side:n});case"keys":return new r.MeshStandardMaterial({color:723725,roughness:.7,side:n});case"trackpad":return new r.MeshPhysicalMaterial({color:2895153,metalness:.4,roughness:.3,clearcoat:.6,side:n});case"scoop":return new r.MeshStandardMaterial({color:1579035,metalness:.6,roughness:.5,side:n})}}const je={glass:1,camera:2,screen:2,well:1,keys:2,trackpad:1,scoop:1};function Ge(v){const j=f.useRef(null),n=f.useRef(v);n.current=v;const[te,z]=f.useState(),[xe,ke]=f.useState(!1),re=f.useRef(!1),{view:oe,viewRef:$,chooseView:Se,locked:x,lockedRef:De,setLocked:_e,orbit:ne,drag:Be}=r.useStageView("front"),P=f.useRef(()=>{}),k=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),m=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),[G,Z]=f.useState(c.MACBOOK_LID_OPEN_DEGREES),F=f.useRef(void 0),se=f.useId(),ie=o=>{const u=m.current;k.current=o,F.current={from:u,to:o,start:performance.now(),duration:c.MACBOOK_LID_OPENING_MS*Math.abs(o-u)/c.MACBOOK_LID_OPEN_DEGREES},P.current()};return f.useEffect(()=>P.current(),[oe,x]),f.useEffect(()=>{const o=j.current,u=v.video;if(!o||!u)return;const ce=()=>{ke(!0),n.current.onReady?.()};z(void 0);const S=new r.PerspectiveCamera(Oe,1,10,4e3);let J=1;const K=r.createDeviceStage({container:o,videos:[u],maxPixelRatio:2,lighting:Ie,resize:(e,t)=>{J=e/t,S.aspect=J,S.updateProjectionMatrix()},frame:(e,t)=>Ce(e,t)});if(!K){z("3D rendering is unavailable in this browser. Enable WebGL to use the 3D MacBook."),ce();return}const{renderer:T,scene:ae,invalidate:C}=K;let U=!1;const b=new r.VideoTexture(u);b.colorSpace=r.SRGBColorSpace,b.minFilter=r.LinearFilter,b.magFilter=r.LinearFilter,b.anisotropy=T.capabilities.getMaxAnisotropy();const D=new r.MeshBasicMaterial({map:b,toneMapped:!1,side:r.DoubleSide});D.onBeforeCompile=e=>{e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>",`#include <map_fragment>
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),f=require("react"),c=require("./remote-control-D_851mel.js"),r=require("./model-source-D3_k9qRK.js"),N={front:{yaw:0,pitch:.1,label:"Front"},desk:{yaw:-.5,pitch:.42,label:"Desk"},side:{yaw:-1.15,pitch:.16,label:"Side"}},Oe=28,Ie={environment:.45,hemisphere:1,key:{intensity:2.2,position:[-120,220,260]},rim:{intensity:.7,position:[220,40,-220]}};function Ne(v,j){const n=r.DoubleSide;switch(v){case"screen":return j;case"shell":return new r.MeshStandardMaterial({color:3421498,metalness:.9,roughness:.34,side:n});case"glass":return new r.MeshPhysicalMaterial({color:328966,roughness:.06,clearcoat:1,side:n});case"camera":return new r.MeshStandardMaterial({color:790549,roughness:.2,side:n});case"well":return new r.MeshStandardMaterial({color:1052690,roughness:.9,side:n});case"keys":return new r.MeshStandardMaterial({color:723725,roughness:.7,side:n});case"trackpad":return new r.MeshPhysicalMaterial({color:2895153,metalness:.4,roughness:.3,clearcoat:.6,side:n});case"scoop":return new r.MeshStandardMaterial({color:1579035,metalness:.6,roughness:.5,side:n})}}const je={glass:1,camera:2,screen:2,well:1,keys:2,trackpad:1,scoop:1};function Ge(v){const j=f.useRef(null),n=f.useRef(v);n.current=v;const[te,z]=f.useState(),[xe,ke]=f.useState(!1),re=f.useRef(!1),{view:oe,viewRef:$,chooseView:Se,locked:x,lockedRef:De,setLocked:_e,orbit:ne,drag:Be}=r.useStageView("front"),P=f.useRef(()=>{}),k=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),m=f.useRef(c.MACBOOK_LID_OPEN_DEGREES),[G,Z]=f.useState(c.MACBOOK_LID_OPEN_DEGREES),F=f.useRef(void 0),se=f.useId(),ie=o=>{const u=m.current;k.current=o,F.current={from:u,to:o,start:performance.now(),duration:c.MACBOOK_LID_OPENING_MS*Math.abs(o-u)/c.MACBOOK_LID_OPEN_DEGREES},P.current()};return f.useEffect(()=>P.current(),[oe,x]),f.useEffect(()=>{const o=j.current,u=v.video;if(!o||!u)return;const ce=()=>{ke(!0),n.current.onReady?.()};z(void 0);const S=new r.PerspectiveCamera(Oe,1,10,4e3);let J=1;const K=r.createDeviceStage({container:o,videos:[u],maxPixelRatio:2,lighting:Ie,resize:(e,t)=>{J=e/t,S.aspect=J,S.updateProjectionMatrix()},frame:(e,t)=>Ce(e,t)});if(!K){z("3D rendering is unavailable in this browser. Enable WebGL to use the 3D MacBook."),ce();return}const{renderer:T,scene:ae,invalidate:C}=K;let U=!1;const b=new r.VideoTexture(u);b.colorSpace=r.SRGBColorSpace,b.minFilter=r.LinearFilter,b.magFilter=r.LinearFilter,b.anisotropy=T.capabilities.getMaxAnisotropy();const D=new r.MeshBasicMaterial({map:b,toneMapped:!1,side:r.DoubleSide});D.onBeforeCompile=e=>{e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>",`#include <map_fragment>
2
2
  if (vMapUv.x < 0.0 || vMapUv.x > 1.0 || vMapUv.y < 0.0 || vMapUv.y > 1.0) diffuseColor.rgb = vec3(0.0);`)},D.customProgramCacheKey=()=>"macbook-fitted-screen";let I=n.current.aspect,le=0,_=c.streamFit(I,I);const Re=()=>{const e=u.videoWidth&&u.videoHeight?u.videoWidth/u.videoHeight:I;_=c.streamFit(e,I,le),b.repeat.set(_.repeat[0],_.repeat[1]),b.offset.set(_.offset[0],_.offset[1])},g=new r.Group,y=new r.Group,h=new r.Group;h.rotation.x=c.lidRotation(m.current),y.add(h),g.add(y),ae.add(g);const de=[D],Y=[];let X;for(const e of c.macbookMeshes(n.current.aspect)){const t=new r.BufferGeometry,a=new r.InterleavedBuffer(e.vertices,c.MACBOOK_VERTEX_FLOATS);t.setAttribute("position",new r.InterleavedBufferAttribute(a,3,0)),t.setAttribute("normal",new r.InterleavedBufferAttribute(a,3,3)),t.setAttribute("uv",new r.InterleavedBufferAttribute(a,2,6));const s=Ne(e.kind,D),d=je[e.kind];d&&(s.polygonOffset=!0,s.polygonOffsetFactor=-d,s.polygonOffsetUnits=-d);const w=new r.Mesh(t,s);e.kind==="screen"&&(X=w),(e.part==="lid"?h:y).add(w),Y.push(t),s!==D&&Y.push(s)}const ue=new r.Box3,fe=e=>{const t=h.rotation.x;return h.rotation.x=c.lidRotation(c.MACBOOK_LID_OPEN_DEGREES),e.updateMatrixWorld(!0),ue.setFromObject(e),h.rotation.x=t,ue},pe=()=>{g.rotation.set(0,0,0),y.position.set(0,0,0),y.position.copy(fe(g).getCenter(new r.Vector3)).negate()};pe();const Ae=!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;let Q=!1;const me=()=>{g.visible=!0,!re.current&&n.current.animateLid!==!1&&!Ae&&(m.current=0,h.rotation.x=c.lidRotation(0),Z(0),ie(c.MACBOOK_LID_OPEN_DEGREES)),re.current=!0,Q=!0,C()},Pe=async e=>{const{GLTFLoader:t}=await Promise.resolve().then(()=>require("./GLTFLoader-CfPNHfJQ.js")),{scene:a}=await r.loadModel(new t,e),s=[];if(a.traverse(l=>{if(l instanceof r.Mesh){s.push(l.geometry);for(const ge of Array.isArray(l.material)?l.material:[l.material]){s.push(ge);for(const Le of Object.values(ge))Le instanceof r.Texture&&s.push(Le)}}}),U){for(const l of s)l.dispose();return}de.push(...s);const d=a.getObjectByName("macbook-base"),w=a.getObjectByName("macbook-lid"),M=a.getObjectByName("macbook-screen");if(!d||!w||!(M instanceof r.Mesh))throw new Error("it has no macbook-base, macbook-lid or macbook-screen");for(const l of[...y.children])l!==h&&y.remove(l);h.clear(),y.add(d);for(const l of[...w.children])h.add(l);M.material=D,X=M;const A=M.userData.aspect;typeof A=="number"&&A>0&&(I=A);const E=M.userData.notch;typeof E=="number"&&E>=0&&E<.5&&(le=E);for(const l of Y.splice(0))l.dispose();pe()},ee=n.current.model;ee&&(g.visible=!1,Pe(ee).catch(e=>{U||z(`The MacBook model could not load: ${e instanceof Error?e.message:e}`)}).finally(()=>{U||me()}));const V=new r.Vector3;let O=0;const he=new r.Raycaster,ve=new r.Vector2;let i,B=N[$.current].yaw,R=N[$.current].pitch;P.current=C;const W=e=>{if(!X)return;const t=T.domElement.getBoundingClientRect();ve.set((e.clientX-t.left)/t.width*2-1,1-(e.clientY-t.top)/t.height*2),he.setFromCamera(ve,S);const a=he.intersectObject(y,!0)[0],s=a?.object===X?a.uv:void 0;return s&&c.streamPoint(s.x,s.y,_)},we=e=>{if(C(),i)return;const t=n.current.watchOnly||e.altKey?void 0:W(e);!t&&(De.current||e.button!==0)||(o.focus({preventScroll:!0}),o.setPointerCapture(e.pointerId),i={pointer:e.pointerId,kind:t?"screen":"orbit",clientX:e.clientX,clientY:e.clientY,x:t?.x??0,y:t?.y??0},t&&n.current.pointer("down",t.x,t.y,e.buttons))},Me=e=>{if(C(),!i){const t=n.current.watchOnly?void 0:W(e);T.domElement.style.cursor=t?"none":"",t&&n.current.pointer("move",t.x,t.y,0);return}if(i.pointer===e.pointerId){if(i.kind==="screen"){const t=W(e);t&&(i.x=t.x,i.y=t.y),n.current.pointer("move",i.x,i.y,e.buttons)}else Be(e.clientX-i.clientX,e.clientY-i.clientY,1.2);i.clientX=e.clientX,i.clientY=e.clientY}},L=e=>{C(),!(!i||e&&i.pointer!==e.pointerId)&&(i.kind==="screen"&&n.current.pointer("up",i.x,i.y,e?.buttons??0),i=void 0)},Ee=e=>{if(n.current.watchOnly||e.ctrlKey)return;const t=W(e);if(!t)return;e.preventDefault();const a=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?o.clientHeight:1;n.current.scroll(t.x,t.y,e.deltaX*a,e.deltaY*a)},q=e=>e.stopPropagation(),ye=["mousedown","mousemove","mouseup","touchstart","touchmove","touchend","touchcancel"];for(const e of ye)o.addEventListener(e,q);const be=e=>e.preventDefault(),H=()=>{L(),n.current.onBlur()};o.addEventListener("pointerdown",we),o.addEventListener("pointermove",Me),o.addEventListener("pointerup",L),o.addEventListener("pointercancel",L),o.addEventListener("lostpointercapture",L),o.addEventListener("wheel",Ee,{passive:!1}),o.addEventListener("wheel",q),o.addEventListener("contextmenu",be),o.addEventListener("focusout",H),window.addEventListener("blur",H);const Ce=(e,t)=>{const a=N[$.current];let s=!1;const d=F.current;if(d){const l=d.duration>0?(e-d.start)/d.duration:1;m.current=d.from+(d.to-d.from)*c.lidEase(l),l>=1?F.current=void 0:s=!0,Z(m.current)}else m.current!==k.current&&(m.current=r.MathUtils.damp(m.current,k.current,14,t),Math.abs(m.current-k.current)<.05?m.current=k.current:s=!0);h.rotation.x=c.lidRotation(m.current);const w=a.yaw+ne.yaw,M=a.pitch+ne.pitch;B=r.MathUtils.damp(B,w,10,t),R=r.MathUtils.damp(R,M,10,t),Math.abs(B-w)<5e-4&&(B=w),Math.abs(R-M)<5e-4&&(R=M),Re(),g.rotation.set(R,B,0,"XYZ"),fe(g).getSize(V);const A=Math.tan(r.MathUtils.degToRad(Oe/2)),E=Math.max(V.y/2/A,V.x/2/(A*J))*1.12+V.z/2;return O=O?r.MathUtils.damp(O,E,10,t):E,Math.abs(O-E)<.01&&(O=E),S.position.set(0,0,O),S.lookAt(0,0,0),T.render(ae,S),Q&&(Q=!1,ce()),s||B!==w||R!==M||O!==E};return K.start(),ee||me(),()=>{U=!0,P.current=()=>{},L();for(const e of ye)o.removeEventListener(e,q);o.removeEventListener("pointerdown",we),o.removeEventListener("pointermove",Me),o.removeEventListener("pointerup",L),o.removeEventListener("pointercancel",L),o.removeEventListener("lostpointercapture",L),o.removeEventListener("wheel",Ee),o.removeEventListener("wheel",q),o.removeEventListener("contextmenu",be),o.removeEventListener("focusout",H),window.removeEventListener("blur",H);for(const e of[...de,...Y])e.dispose();b.dispose(),K.dispose()}},[v.video,v.aspect,v.model]),p.jsxs("div",{className:"rc-duo rc-macbook-3d",style:xe?void 0:{visibility:"hidden"},children:[p.jsx("div",{ref:j,className:"rc-duo-stage","data-position-locked":x,tabIndex:0,role:"application","aria-label":"MacBook running macOS. Use the screen to control the guest. Drag around the MacBook to turn it when position is unlocked.",onKeyDown:v.onKeyDown,onKeyUp:v.onKeyUp}),p.jsxs("div",{className:"rc-duo-controls",onPointerDown:o=>o.stopPropagation(),children:[p.jsxs("div",{className:"rc-duo-hinge",children:[p.jsx("button",{type:"button",className:"rc-duo-fold",onClick:()=>ie(G<45?c.MACBOOK_LID_OPEN_DEGREES:0),children:G<45?"Open":"Close"}),p.jsx("label",{htmlFor:se,children:"Lid"}),p.jsx("input",{id:se,type:"range",min:0,max:c.MACBOOK_LID_MAX_DEGREES,step:1,value:Math.round(G),onChange:o=>{const u=Number(o.target.value);F.current=void 0,k.current=u,Z(u),P.current()}}),p.jsxs("output",{children:[Math.round(G),"°"]})]}),p.jsxs("div",{className:"rc-duo-views",children:[Object.keys(N).map(o=>p.jsx("button",{type:"button","aria-pressed":oe===o,onClick:()=>{Se(o)},children:N[o].label},o)),p.jsx("button",{type:"button",className:"rc-duo-lock","aria-pressed":x,title:x?"Position is locked. The screen still controls macOS.":"Drag around the MacBook to turn it. Alt-drag turns it from the screen.",onClick:()=>_e(!x),children:x?"Position locked":"Lock position"})]})]}),te&&p.jsx("div",{role:"alert",className:"rc-duo-error",children:te})]})}exports.default=Ge;
@@ -0,0 +1 @@
1
+ "use strict";require('./index.css');const p=require("react/jsx-runtime"),i=require("./core-B3nWmNki.js"),a=require("react"),Go=require("react-dom"),Q={sideBezel:1.7,topBezel:2.4,chin:2.4,baseHeight:2.2,baseOverhang:4,screenRadius:.9,lidThickness:.7},Dt=100+2*Q.sideBezel,et=Dt+2*Q.baseOverhang,Pt=Q.topBezel+Q.chin+Q.baseHeight,qo=(Pt-2*Q.topBezel)/2,Zo=8;function Jo(d){const t=100/d,c=t+Q.topBezel+Q.chin;return{screenHeight:t,lidHeight:c,depth:c}}const Qo=Math.PI/2,en=135,tn=100,on=2400;function nn(d){return Qo-d*Math.PI/180}function rn(d){const t=Math.max(0,Math.min(1,d));return 1-Math.pow(1-t,3)}function De(d,t,c,u=6){const v=[],E=[[d/2-c.top,t/2-c.top,c.top,0],[-d/2+c.top,t/2-c.top,c.top,Math.PI/2],[-d/2+c.bottom,-t/2+c.bottom,c.bottom,Math.PI],[d/2-c.bottom,-t/2+c.bottom,c.bottom,Math.PI*1.5]];for(const[y,A,N,C]of E)for(let x=0;x<=u;x++){const R=C+x*Math.PI/2/u;v.push({x:y+N*Math.cos(R),y:A+N*Math.sin(R),nx:Math.cos(R),ny:Math.sin(R)})}return v}function sn(d){const{screenHeight:t,lidHeight:c,depth:u}=Jo(d),v=[],E=(f,O,b)=>v.push({part:f,kind:O,vertices:new Float32Array(b)}),y=(f,O,b,L,D)=>{const H=b.map(G=>G.x),z=b.map(G=>G.y),[oe,K,ae,ye]=[Math.min(...H),Math.max(...H),Math.min(...z),Math.max(...z)],le=(oe+K)/2,B=(ae+ye)/2,de=(G,Oe)=>[...L(G,Oe),...D,(G-oe)/(K-oe||1),(Oe-ae)/(ye-ae||1)],P=[];for(let G=0;G<b.length;G++){const Oe=b[G],tt=b[(G+1)%b.length];for(const Z of[de(le,B),de(Oe.x,Oe.y),de(tt.x,tt.y)])P.push(...Z)}E(f,O,P)},A=(f,O,b,L,D,H,z)=>{const oe=[];for(let K=0;K<b.length;K++){const ae=b[K],ye=b[(K+1)%b.length],le=(B,de)=>[...L(B.x,B.y,de),...D(B.nx,B.ny),0,0];for(const B of[le(ae,H),le(ye,H),le(ye,z),le(ae,H),le(ye,z),le(ae,z)])oe.push(...B)}E(f,O,oe)},N=De(Dt,c,{top:2.2,bottom:.4}),C=f=>f+c/2,x=Q.lidThickness;A("lid","shell",N,(f,O,b)=>[f,C(O),b],(f,O)=>[f,O,0],-x,0),y("lid","shell",N,(f,O)=>[f,C(O),-x],[0,0,-1]),y("lid","glass",De(Dt-.5,c-.5,{top:1.95,bottom:.2}),(f,O)=>[f,C(O),.01],[0,0,1]);const R=Q.chin;y("lid","screen",De(100,t,{top:Q.screenRadius,bottom:0}),(f,O)=>[f,R+t/2+O,.02],[0,0,1]),y("lid","camera",De(.5,.5,{top:.25,bottom:.25},4),(f,O)=>[f,c-Q.topBezel/2+O,.02],[0,0,1]);const Y=De(et,u+x,{top:3,bottom:3}),j=f=>(u-x)/2-f;A("base","shell",Y,(f,O,b)=>[f,b,j(O)],(f,O)=>[f,0,-O],-2.2,0),y("base","shell",Y,(f,O)=>[f,0,j(O)],[0,1,0]),y("base","shell",Y,(f,O)=>[f,-2.2,j(O)],[0,-1,0]);const ee=(f,O,b,L,D,H,z)=>y("base",f,De(L,D,{top:z,bottom:z},3),(oe,K)=>[O+oe,H,b-K],[0,1,0]),ge=et*.72,ce=u*.08,_=[.55,1,1,1,1,1],te=u*.4/_.reduce((f,O)=>f+O,0);ee("well",0,ce+u*.4/2,ge+1.4,u*.4+1.4,.01,.8);let U=ce;for(const[f,O]of _.entries()){const b=O*te,L=ge/14;for(let D=0;D<14;D++){if(f===5&&D>4&&D<9)continue;const H=f===5&&D===4?5:1;ee("keys",-ge/2+L*(D+H/2),U+b/2,L*H-.5,b-.5,.03,.3)}U+=b}ee("trackpad",0,u*.72,et*.4,u*.36,.01,1.2),y("base","scoop",De(14,.9,{top:0,bottom:.45},3),(f,O)=>[f,-.45+O,u+.01],[0,0,1]);const k=new Map;for(const f of v){const O=`${f.part}:${f.kind}`;k.set(O,[...k.get(O)??[],f])}return[...k.values()].map(f=>{const O=new Float32Array(f.reduce((L,D)=>L+D.vertices.length,0));let b=0;for(const L of f)O.set(L.vertices,b),b+=L.vertices.length;return{part:f[0].part,kind:f[0].kind,vertices:O}})}function cn(d,t,c=0){const u=d>=t?1:d/t,v=d>=t?t/d:1,E=(1-u)/2,y=c>0?1-v:(1-v)/2;return{repeat:[1/u,1/v],offset:[(0-E)/u,(0-y)/v]}}function an(d,t,c){const u=d*c.repeat[0]+c.offset[0],v=t*c.repeat[1]+c.offset[1],E=1e-9;if(u<-E||u>1+E||v<-E||v>1+E)return;const y=A=>Math.max(0,Math.min(1,A));return{x:y(u),y:y(1-v)}}const ln=150,dn=8;class un{constructor(t,c=()=>!1){this.send=t,this.blocked=c}send;blocked;last;gesture;screen;pointer(t,c,u){const v=t===i.MAC_INPUT_ACTION.UP&&!!this.last?.buttons;this.blocked()&&!v||(this.last={...c,buttons:u},this.send(i.createMouseControlMessage(t,c.width,c.height,c.x,c.y,u)))}scroll(t,c,u){this.blocked()||this.send(i.createMacScrollMessage(t.width,t.height,t.x,t.y,c,u))}touch(t,c,u){const v=this.gesture;if(c.length>=2){const y={x:c.reduce((A,N)=>A+N.x,0)/c.length,y:c.reduce((A,N)=>A+N.y,0)/c.length};if(v?.mode==="scroll"){const A=u.map(y.x,y.y);A&&t==="touchmove"&&this.scroll(A,(v.x-y.x)*u.scale,(v.y-y.y)*u.scale)}else v?.mode==="press"?this.lift(v,u):v?.mode==="pending"&&clearTimeout(v.timer);return this.gesture={mode:"scroll",...y},!1}const E=c[0];if(E&&t==="touchstart"&&!v)return this.blocked()||!u.contains(E.x,E.y)?!1:(this.screen=u,this.gesture={mode:"pending",x:E.x,y:E.y,timer:setTimeout(()=>this.press(),ln)},!0);if(E&&v?.mode==="pending"){if(Math.hypot(E.x-v.x,E.y-v.y)<dn)return!1;this.press()}if(E&&this.gesture?.mode==="press"){this.gesture={mode:"press",x:E.x,y:E.y};const y=u.map(E.x,E.y);return y&&this.pointer(i.MAC_INPUT_ACTION.MOVE,y,1),!1}if(c.length===0){v?.mode==="pending"&&(t==="touchcancel"?clearTimeout(v.timer):this.press());const y=this.gesture;y?.mode==="press"&&this.lift(y,u),this.gesture=void 0}return!1}release(){clearTimeout(this.gesture?.timer),this.gesture=void 0;const t=this.last;t?.buttons&&this.pointer(i.MAC_INPUT_ACTION.UP,t,0)}press(){const t=this.gesture;if(t?.mode!=="pending")return;clearTimeout(t.timer),this.gesture={mode:"press",x:t.x,y:t.y};const c=this.screen?.map(t.x,t.y);c&&this.pointer(i.MAC_INPUT_ACTION.DOWN,c,1)}lift(t,c){const u=c.map(t.x,t.y);u&&this.pointer(i.MAC_INPUT_ACTION.UP,u,0)}}function hn(d,t){return t.type==="choose"?t.mode===d.mode?d:t.mode==="3d"?{...d,mode:"3d",selection:d.selection+1}:{...d,mode:"2d"}:d.mode!=="3d"||t.selection!==d.selection||d.ready===t.selection?d:{...d,ready:t.selection}}function ho(d){const[t,c]=a.useReducer(hn,{mode:"2d",selection:0,ready:0}),u=a.useRef(t);u.current=t;const v=a.useRef(d);v.current=d;const{mode:E,selection:y,ready:A}=t,N=a.useCallback(R=>c({type:"choose",mode:R}),[]),C=a.useCallback(()=>{const R=u.current;R.mode!=="3d"||R.selection!==y||R.ready===y||(v.current?.(),c({type:"ready",selection:y}))},[y]),x=E==="3d"&&A!==y;return{mode:E,shown:E==="3d"&&!x?"3d":"2d",loading:x,choose:N,onReady:C}}function fo({view:d,label:t}){return p.jsxs("div",{className:"rc-duo-mode",role:"group","aria-label":t,children:[p.jsx("button",{type:"button","aria-pressed":d.mode==="2d",onClick:()=>d.choose("2d"),children:"2D"}),p.jsx("button",{type:"button","aria-pressed":d.mode==="3d","aria-busy":d.loading,title:d.loading?"Loading 3D":void 0,onClick:()=>d.choose("3d"),children:"3D"})]})}const fn=async d=>{if(!d)return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(d),!0}catch{}try{const t=document.createElement("textarea");t.value=d,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const c=document.execCommand("copy");return document.body.removeChild(t),c}catch{return!1}},mn=a.memo(function({element:t,screen:c,highlighted:u,selected:v,selectable:E,onClick:y}){const A=i.clampAxFrameForScreen(t.frame,c);if(!A)return null;const N=i.axElementSummary(t);return p.jsx("button",{type:"button",className:t.enabled?"rc-inspect-box":"rc-inspect-box rc-inspect-box-disabled","data-ax-id":t.id,"data-ax-path":t.path,"data-ax-label":t.label||void 0,"data-ax-role":t.role||void 0,"data-highlighted":u?"true":"false","data-selected":v?"true":"false","aria-label":N,onClick:C=>{E&&(C.preventDefault(),C.stopPropagation(),y(t,{x:C.clientX,y:C.clientY}))},style:{left:`${A.x/c.width*100}%`,top:`${A.y/c.height*100}%`,width:`${A.width/c.width*100}%`,height:`${A.height/c.height*100}%`}})},(d,t)=>d.highlighted===t.highlighted&&d.selected===t.selected&&d.selectable===t.selectable&&d.screen.width===t.screen.width&&d.screen.height===t.screen.height&&d.onClick===t.onClick&&i.axElementsEqual(d.element,t.element)),pn=260,gn=220,yn=6,vn=8,Tn=a.memo(function({element:t,platform:c,anchor:u,cursorAnchored:v,showActions:E,onTap:y}){const[A,N]=a.useState(null);a.useEffect(()=>{if(!A)return;const _=window.setTimeout(()=>N(null),1100);return()=>window.clearTimeout(_)},[A]);const C=a.useMemo(()=>{const _=pn,te=gn,U=yn,k=vn,f=typeof window<"u"?window.innerWidth:1024,O=typeof window<"u"?window.innerHeight:768,b=u.x+U+_<=f-k,L=u.y-U-te>=k;let D=b?u.x+U:u.x-U,H=L?u.y-U:u.y+U;const K=`translate(${b?"0":"-100%"}, ${L?"-100%":"0"})`;return D=Math.max(k+(b?0:_),Math.min(f-k-(b?_:0),D)),H=Math.max(k+(L?te:0),Math.min(O-k-(L?0:te),H)),{left:`${D}px`,top:`${H}px`,transform:K}},[u.x,u.y]),x=a.useMemo(()=>i.axElementSelectorExpression(t,c),[t,c]),R=c==="ios"?t.selectors.AXUniqueId:t.selectors.resourceId,Y=c==="ios"?"AXUniqueId":"resourceId",j=a.useCallback(async(_,te)=>{if(!_)return;await fn(_)&&N(te)},[]),ee=i.axElementRoleLabel(t),ge=t.label||t.value||ee,ce=i.axElementSummary(t);return Go.createPortal(p.jsxs("div",{className:"rc-inspect-card","data-cursor-anchored":v?"true":"false",style:C,onClick:_=>_.stopPropagation(),onMouseDown:_=>_.stopPropagation(),onMouseMove:_=>_.stopPropagation(),children:[p.jsxs("div",{className:"rc-inspect-card-header",children:[p.jsx("span",{className:"rc-inspect-card-role",children:ee}),!t.enabled&&p.jsx("span",{className:"rc-inspect-card-tag",children:"disabled"}),t.focused&&p.jsx("span",{className:"rc-inspect-card-tag rc-inspect-card-tag-blue",children:"focused"})]}),p.jsx("p",{className:"rc-inspect-card-title",title:ce,children:ge}),R&&p.jsxs("div",{className:"rc-inspect-card-row",children:[p.jsxs("span",{className:"rc-inspect-card-row-label",children:[Y,":"]}),p.jsx("span",{className:"rc-inspect-card-row-value",children:R})]}),t.value&&t.value!==t.label&&p.jsxs("div",{className:"rc-inspect-card-row",children:[p.jsx("span",{className:"rc-inspect-card-row-label",children:"value:"}),p.jsx("span",{className:"rc-inspect-card-row-value",children:t.value})]}),p.jsxs("div",{className:"rc-inspect-card-row",children:[p.jsx("span",{className:"rc-inspect-card-row-label",children:"frame:"}),p.jsxs("span",{className:"rc-inspect-card-row-value",children:[Math.round(t.frame.width),"×",Math.round(t.frame.height)," @ ",Math.round(t.frame.x),",",Math.round(t.frame.y)]})]}),E&&p.jsxs("div",{className:"rc-inspect-card-actions",children:[p.jsx("button",{type:"button",className:"rc-inspect-card-btn rc-inspect-card-btn-primary",disabled:!y,onClick:()=>y?.(t,u),children:"Tap"}),p.jsx("button",{type:"button",className:A==="selector"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!x,title:x??"No usable selector for this element",onClick:()=>j(x??void 0,"selector"),children:A==="selector"?"Copied!":"Copy selector"}),p.jsx("button",{type:"button",className:A==="id"?"rc-inspect-card-btn rc-inspect-card-btn-copied":"rc-inspect-card-btn",disabled:!R,title:R??`No ${Y}`,onClick:()=>j(R,"id"),children:A==="id"?"Copied!":`Copy ${Y}`})]})]}),document.body)}),On=a.memo(function({snapshot:t,geometry:c,highlightedId:u,selectedId:v,mode:E,cursorPosition:y,frozenCursorPosition:A,onSelectChange:N,onTapElement:C}){const x=E==="select",R=x?u!==null&&u!==v:u!==null,Y=x?u??v:u,j=a.useMemo(()=>{const k=new Map;if(!t)return k;for(const f of t.elements)k.set(f.id,f);return k},[t]),ee=a.useMemo(()=>Y?j.get(Y)??null:null,[Y,j]);if(!(!!t&&!!c&&t.screen.width>0&&t.screen.height>0&&t.elements.length>0))return null;const ce=R?y:A??y,_=R,te=x&&!R&&v!==null,U=k=>{x&&k.target===k.currentTarget&&N(null,null)};return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:x?"rc-inspect-overlay rc-inspect-overlay-select":"rc-inspect-overlay",style:{left:`${c.left}px`,top:`${c.top}px`,width:`${c.width}px`,height:`${c.height}px`},onClick:U,children:t.elements.map(k=>p.jsx(mn,{element:k,screen:t.screen,highlighted:k.id===u,selected:k.id===v,selectable:x,onClick:N},k.id))}),ee&&ce&&p.jsx(Tn,{element:ee,platform:t.platform,anchor:ce,cursorAnchored:_,showActions:te,onTap:C})]})});function En(d,t){if(!t.startsWith("lim_st_"))return!1;try{const c=new URL(d).pathname.split("/").map(decodeURIComponent).find(C=>/^(ios|android)_[a-z0-9_]+$/.test(C));if(!c)return!1;const u=c.split("_")[0],v=t.slice(7).split(".");if(v.length!==3||v.some(C=>!C))return!1;const E=atob(v[1].replace(/-/g,"+").replace(/_/g,"/")),y=JSON.parse(new TextDecoder().decode(Uint8Array.from(E,C=>C.charCodeAt(0))));if(!y||typeof y!="object"||!("scopes"in y))return!1;const A=y.scopes;if(!Array.isArray(A)||!A.every(C=>typeof C=="string"))return!1;let N=!1;for(const C of A){const[x,R,Y,j]=C.split(":");if(!(j!==void 0||x!==u&&x!=="*")&&!(R!==c&&R!=="*")){if(Y==="stream"||Y==="all")return!1;Y==="watch"&&(N=!0)}}return N}catch{return!1}}const An=a.lazy(()=>Promise.resolve().then(()=>require("./duo-view-DbnkRRU-.js")).then(d=>d.duoView)),bn=a.lazy(()=>Promise.resolve().then(()=>require("./macbook-frame-DASJ960L.js"))),Tt=d=>Object.entries(i.AMOTION_EVENT).find(([c,u])=>c.startsWith("ACTION_")&&u===d)?.[0]??String(d),lo=1920,uo=1200,Mn=(d,t)=>d===lo&&t===uo||d===uo&&t===lo,Nn={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}}}},_n={"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}}}},kt=16/10,Ot=44,wn={videoBorderRadiusMultiplier:32/1837,loadingLogoSize:"40%",videoPosition:{portrait:{heightMultiplier:2560/2798},landscape:{widthMultiplier:2560/2798}}};function In(d){const t=d.code,c=i.codeMap[t];if(!c)return i.debugWarn(`Unknown event.code: ${t}, key: ${d.key}`),null;let u=i.ANDROID_KEYS.META_NONE;const v=t>="KeyA"&&t<="KeyZ",E=d.getModifierState("CapsLock"),y=d.shiftKey;let A=y;return v&&(A=y!==E),A&&(u|=i.ANDROID_KEYS.META_SHIFT_ON),d.ctrlKey&&(u|=i.ANDROID_KEYS.META_CTRL_ON),d.altKey&&(u|=i.ANDROID_KEYS.META_ALT_ON),d.metaKey&&(u|=i.ANDROID_KEYS.META_META_ON),{keycode:c,metaState:u}}function Et(d,t){const c=Object.keys(d);return c.length===Object.keys(t).length&&c.every(u=>d[u]===t[u])}const Rn=a.forwardRef(({className:d,url:t,token:c,sessionId:u,openUrl:v,watchOnly:E=!1,showFrame:y=!0,animateLid:A=!0,deviceModel:N,duoModelUrl:C,macbookModelUrl:x,autoReconnect:R,jitterBufferTargetMs:Y,onPlaybackStats:j,onTerminated:ee,assets:ge,onConnectionStateChange:ce,inspectMode:_,onAxSnapshotChange:te,onInspectSelectionChange:U,onAxStatusChange:k,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:b,onCameraDemandChange:L,onCameraStats:D,onTrace:H,microphoneEnabled:z=!1,onMicrophoneStateChange:oe,speakerMuted:K=!0,onSpeakerBlocked:ae},ye)=>{const le=a.useMemo(()=>En(t,c),[t,c]),B=E||le,de=a.useRef(null),P=a.useRef(null),G=a.useRef(null),[Oe,tt]=a.useState(!1),Z=N==="iphone-duo"||Oe,ot=N==="iphone-duo"?N:void 0,nt=a.useRef(null),rt=a.useRef(null),[Lt,mo]=a.useState(null),[Yt,po]=a.useState(),[go,yo]=a.useState(!1),[vo,To]=a.useState(!1),[Oo,Eo]=a.useState(!1),[At,Ht]=a.useState(!1),[Wt,Xt]=a.useState(!1),[Ao,jt]=a.useState({}),[Kt,Vt]=a.useState(null),[bt,bo]=a.useState(null),[Bt,Mo]=a.useState(null),[$t,Ut]=a.useState(null),Ue=ho(()=>dt.current?.release()),it=a.useRef(!1),Mt=a.useRef(null),$=a.useRef(new Map),Ee=a.useRef(!1),[No,_o]=a.useState(!1),W=a.useRef(null),Pe=a.useRef(null),Fe=a.useRef({handle:()=>{},end:()=>{}}),[Ae,st]=a.useState(null),[Ft,Nt]=a.useState(null),[_t,ze]=a.useState(null),[wt,ct]=a.useState(null),[wo,zt]=a.useState(null),[Io,Gt]=a.useState(null),at=a.useRef(null),fe=a.useRef(void 0),qt=e=>{at.current=e,fe.current===void 0&&(fe.current=window.requestAnimationFrame(()=>{fe.current=void 0,Gt(at.current)}))},[Ro,Le]=a.useState(null),be=a.useRef(null);be.current=Ft;const Ye=a.useRef(U);Ye.current=U;const Me=_===!0||_==="hover-only",Zt=a.useRef(Me);Zt.current=Me;const Co=_==="hover-only"?"hover-only":"select",V=a.useMemo(()=>i.detectPlatform(t),[t]),So=a.useMemo(()=>u||Array.from(crypto.getRandomValues(new Uint32Array(4)),e=>e.toString(36)).join(""),[u]),Ge=V==="ios"&&N&&N!=="iphone-duo"?N:void 0,Ne=V==="android"&&Wt?wn:Ge?_n[Ge]:Nn[V],ne=ge?.[V],Jt=Ge&&ne?.modelFrames?.[Ge],Qt=V==="android"&&Wt?At?ne?.tabletFrameLandscape:ne?.tabletFrame:Ge?At?Jt?.frameLandscape:Jt?.frame:At?ne?.frameLandscape:ne?.frame,eo=ne?.loadingLogo,qe=!Z&&V!=="macos"&&y&&!!Qt,ue=V==="macos"&&y,_e=ue&&ne?.frame&&ne.screen?{src:ne.frame,screen:ne.screen}:void 0,It=a.useRef(null),xo=ue&&Ue.mode==="3d",we=ue&&Ue.shown==="3d";it.current=we;const to=Ue.choose;a.useEffect(()=>{ue||to("2d")},[ue,to]);const w=a.useRef(null),ie=e=>w.current?.sendControl(e),lt=a.useRef(new Set),oo=a.useRef(!1);oo.current=_===!0;const dt=a.useRef(null);dt.current||(dt.current=new un(e=>w.current?.sendControl(e),()=>oo.current));const Ie=dt.current;a.useEffect(()=>()=>Ie.release(),[Ie]);const Ze=a.useCallback(()=>{for(const e of lt.current)w.current?.sendControl(i.createMacKeyMessage(i.MAC_INPUT_ACTION.UP,e));lt.current.clear()},[]),Rt=(e,o)=>w.current?.sendDuoControl(e,o)??Promise.reject(new Error("Simulator disconnected")),no=-10,ro=(e,o)=>{const n=We();if(!n)return;const s=me(n,e,o);if(!s)return;const{videoX:r,videoY:h,videoWidth:l,videoHeight:m}=s,g=i.createTouchControlMessage(i.AMOTION_EVENT.ACTION_DOWN,no,l,m,r,h,1,i.AMOTION_EVENT.BUTTON_PRIMARY,i.AMOTION_EVENT.BUTTON_PRIMARY);g&&ie(g),window.setTimeout(()=>{const M=i.createTouchControlMessage(i.AMOTION_EVENT.ACTION_UP,no,l,m,r,h,0,i.AMOTION_EVENT.BUTTON_PRIMARY,i.AMOTION_EVENT.BUTTON_PRIMARY);M&&ie(M)},60)},ko=(e,o)=>{const n=We();if(!n||o.screen.width<=0||o.screen.height<=0)return;const s=e.frame.x+e.frame.width/2,r=e.frame.y+e.frame.height/2,h=s/o.screen.width*n.actualWidth,l=r/o.screen.height*n.actualHeight,m=n.videoRect.left+n.offsetX+h,g=n.videoRect.top+n.offsetY+l;ro(m,g)},ut=-1,ht=-2,Re=-3,He=(e,o,n,s,r,h)=>{const l=i.createTouchControlMessage(e,o,n,s,r,h,1,i.AMOTION_EVENT.BUTTON_PRIMARY,i.AMOTION_EVENT.BUTTON_PRIMARY);l&&(i.debugLog("[rc-touch] sendSingleTouch",{action:e,actionName:Tt(e),pointerId:o,x:r,y:h,video:{width:n,height:s}}),ie(l))},Ce=(e,o,n)=>{if(!n)return;const{videoX:s,videoY:r,videoWidth:h,videoHeight:l}=n;let m=null,g=null,M=1;const S=i.AMOTION_EVENT.BUTTON_PRIMARY;switch(o){case"down":e!==Re&&Fe.current.end(),m=$.current.size===0?i.AMOTION_EVENT.ACTION_DOWN:i.AMOTION_EVENT.ACTION_POINTER_DOWN,g={x:s,y:r},$.current.set(e,g),e===-1&&P.current?.focus();break;case"move":$.current.has(e)&&(m=i.AMOTION_EVENT.ACTION_MOVE,g={x:s,y:r},$.current.set(e,g));break;case"up":case"cancel":$.current.has(e)&&(g=$.current.get(e),$.current.delete(e),o==="cancel"?m=i.AMOTION_EVENT.ACTION_CANCEL:m=$.current.size===0?i.AMOTION_EVENT.ACTION_UP:i.AMOTION_EVENT.ACTION_POINTER_UP);break}if(m!==null&&g!==null){i.debugLog("[rc-touch][mouse->touch] sending",{pointerId:e,eventType:o,action:m,actionName:Tt(m),positionToSend:g,video:{width:h,height:l},altHeld:Ee.current,activePointersAfter:Array.from($.current.entries()).map(([J,X])=>({id:J,x:X.x,y:X.y}))});const T=i.createTouchControlMessage(m,e,h,l,g.x,g.y,M,S,S);T&&(i.debugLog("[rc-touch][mouse->touch] buffer",{pointerId:e,actionName:Tt(m),byteLength:T.byteLength}),ie(T))}else(o==="up"||o==="cancel")&&$.current.delete(e)},Ct=e=>{if(Ee.current!==e&&(Ee.current=e,_o(e),e||st(null),i.debugLog("[rc-touch][alt] updateAltHeld",{nextHeld:e,activePointerIds:Array.from($.current.keys())}),V==="ios"&&w.current?.getState().controlReady)){const o=e?i.ANDROID_KEYS.ACTION_DOWN:i.ANDROID_KEYS.ACTION_UP,n=i.createInjectKeycodeMessage(o,i.ANDROID_KEYS.KEYCODE_ALT_LEFT,0,i.ANDROID_KEYS.META_NONE);i.debugLog("[rc-touch][alt] sending Indigo modifier keycode",{action:o,keycode:i.ANDROID_KEYS.KEYCODE_ALT_LEFT}),n&&ie(n)}},We=()=>{const e=P.current,o=de.current;if(!e||!o)return null;const n=e.videoWidth,s=e.videoHeight;if(!n||!s)return null;const r=e.getBoundingClientRect(),h=o.getBoundingClientRect(),l=r.width,m=r.height,g=n/s,M=l/m;let S=l,T=m;g>M?T=l/g:S=m*g;const J=(l-S)/2,X=(m-T)/2;return{videoWidth:n,videoHeight:s,videoRect:r,containerRect:h,actualWidth:S,actualHeight:T,offsetX:J,offsetY:X}},me=(e,o,n)=>{const s=o-e.videoRect.left-e.offsetX,r=n-e.videoRect.top-e.offsetY,h=Math.max(0,Math.min(e.actualWidth,s)),l=Math.max(0,Math.min(e.actualHeight,r)),m=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),g=Math.max(0,Math.min(e.videoHeight,l/e.actualHeight*e.videoHeight));return{videoX:m,videoY:g,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Do=(e,o,n)=>{const s=o-e.videoRect.left-e.offsetX,r=n-e.videoRect.top-e.offsetY,h=Math.max(0,Math.min(e.actualWidth,s)),l=Math.max(0,Math.min(e.actualHeight,r)),m=Math.max(0,Math.min(e.videoWidth,h/e.actualWidth*e.videoWidth)),g=Math.max(0,Math.min(e.videoHeight,l/e.actualHeight*e.videoHeight)),M=e.videoWidth-m,S=e.videoHeight-g,T=e.videoRect.left+e.offsetX,J=e.videoRect.top+e.offsetY,X=T-e.containerRect.left+h,q=J-e.containerRect.top+l,re=T-e.containerRect.left+(e.actualWidth-h),I=J-e.containerRect.top+(e.actualHeight-l);return{containerX:X,containerY:q,mirrorContainerX:re,mirrorContainerY:I,videoX:m,videoY:g,mirrorVideoX:M,mirrorVideoY:S,videoWidth:e.videoWidth,videoHeight:e.videoHeight}},Po=(e,o,n,s,r,h,l)=>{const m=i.createTwoFingerTouchControlMessage(e,o,n,s,r,h,l);i.debugLog("[rc-touch2] sendTwoFingerMessage (iOS)",{actionName:Tt(e),video:{width:o,height:n},p0:{x:s,y:r},p1:{x:h,y:l},byteLength:m.byteLength}),ie(m)},Xe=(e,o,n,s,r,h,l,m,g)=>{if(i.debugLog("[rc-touch2] applyTwoFingerEvent",{platform:V,eventType:e,video:{width:o,height:n},p0:{x:s,y:r,id:m},p1:{x:h,y:l,id:g}}),e==="down"&&Fe.current.end(),V==="ios"){const M=e==="down"?i.AMOTION_EVENT.ACTION_DOWN:e==="move"?i.AMOTION_EVENT.ACTION_MOVE:i.AMOTION_EVENT.ACTION_UP;Po(M,o,n,s,r,h,l)}else e==="down"?(He(i.AMOTION_EVENT.ACTION_DOWN,m,o,n,s,r),He(i.AMOTION_EVENT.ACTION_POINTER_DOWN,g,o,n,h,l)):e==="move"?(He(i.AMOTION_EVENT.ACTION_MOVE,m,o,n,s,r),He(i.AMOTION_EVENT.ACTION_MOVE,g,o,n,h,l)):(He(i.AMOTION_EVENT.ACTION_POINTER_UP,g,o,n,h,l),He(i.AMOTION_EVENT.ACTION_UP,m,o,n,s,r))},Lo=(e,o,n)=>{if(!Ee.current){Ae!==null&&st(null);return}const s=Do(e,o,n);st(s)},Yo=(e,o,n)=>{const s=be.current;if(!s||s.screen.width<=0||s.screen.height<=0)return null;const r=o-e.videoRect.left-e.offsetX,h=n-e.videoRect.top-e.offsetY;if(r<0||h<0||r>e.actualWidth||h>e.actualHeight)return null;const l=r/e.actualWidth*s.screen.width,m=h/e.actualHeight*s.screen.height;return i.axElementAtPoint(s,l,m)},Ho=e=>({map:(o,n)=>{const s=me(e,o,n);if(s)return{x:s.videoX,y:s.videoY,width:s.videoWidth,height:s.videoHeight}},contains:(o,n)=>{const s=o-e.videoRect.left-e.offsetX,r=n-e.videoRect.top-e.offsetY;return s>=0&&s<=e.actualWidth&&r>=0&&r<=e.actualHeight},scale:e.actualWidth>0?e.videoWidth/e.actualWidth:1}),ve=e=>{if(Z||it.current)return;e.preventDefault(),e.stopPropagation();const o=We();if((_===!0||_==="hover-only")&&!("touches"in e))if(e.type==="mousemove"){if(qt({x:e.clientX,y:e.clientY}),o){const s=Yo(o,e.clientX,e.clientY);ze(s?.id??null)}}else e.type==="mouseleave"&&(qt(null),ze(null));if(_!==!0){if(V==="macos"){if(!o||!w.current?.getState().controlReady)return;if("touches"in e){const l=Array.from(e.touches,m=>({x:m.clientX,y:m.clientY}));Ie.touch(e.type,l,Ho(o))&&P.current?.focus();return}const s=me(o,e.clientX,e.clientY);if(!s)return;const r=e.type==="mousedown"?i.MAC_INPUT_ACTION.DOWN:e.type==="mouseup"?i.MAC_INPUT_ACTION.UP:i.MAC_INPUT_ACTION.MOVE,h=e.type==="mouseleave"?0:e.buttons;e.type==="mousedown"&&P.current?.focus(),Ie.pointer(r,{x:s.videoX,y:s.videoY,width:s.videoWidth,height:s.videoHeight},h);return}if(!("touches"in e)&&o&&(e.type==="mousemove"?Lo(o,e.clientX,e.clientY):e.type==="mouseleave"&&st(null)),!(!w.current?.getState().controlReady||!P.current||!o))if("touches"in e){const s=e.touches,r=e.changedTouches;let h;switch(e.type){case"touchstart":h="down";break;case"touchmove":h="move";break;case"touchend":h="up";break;case"touchcancel":h="cancel";break;default:return}if(s.length===2){const l=s[0],m=s[1],g=me(o,l.clientX,l.clientY),M=me(o,m.clientX,m.clientY);if(!g||!M)return;W.current?W.current.source==="real-touch"&&(W.current.finger0={x:g.videoX,y:g.videoY},W.current.finger1={x:M.videoX,y:M.videoY},Xe("move",g.videoWidth,g.videoHeight,g.videoX,g.videoY,M.videoX,M.videoY,W.current.pointerId0,W.current.pointerId1)):(W.current={finger0:{x:g.videoX,y:g.videoY},finger1:{x:M.videoX,y:M.videoY},videoSize:{width:g.videoWidth,height:g.videoHeight},source:"real-touch",pointerId0:l.identifier,pointerId1:m.identifier},Xe("down",g.videoWidth,g.videoHeight,g.videoX,g.videoY,M.videoX,M.videoY,l.identifier,m.identifier))}else if(s.length<2&&W.current?.source==="real-touch"){const l=W.current;Xe("up",l.videoSize.width,l.videoSize.height,l.finger0.x,l.finger0.y,l.finger1.x,l.finger1.y,l.pointerId0,l.pointerId1),W.current=null;return}else{if(s.length>2)return;{const l=r[0];if(l){const m=me(o,l.clientX,l.clientY);Ce(l.identifier,h,m)}}}}else{let r=null;const h=W.current?.source==="alt-mouse";switch(e.type){case"mousedown":e.button===0&&(r="down");break;case"mousemove":(h||$.current.has(-1))&&(r="move");break;case"mouseup":e.button===0&&(r="up");break;case"mouseleave":(h||$.current.has(-1))&&(r="up");break}if(r){const l=me(o,e.clientX,e.clientY);if(!l)return;i.debugLog("[rc-touch][mouse] event",{domType:e.type,eventType:r,button:e.button,buttons:e.buttons,client:{x:e.clientX,y:e.clientY},altHeldRef:Ee.current,inTwoFingerMode:h,geometry:{videoX:l.videoX,videoY:l.videoY,videoWidth:l.videoWidth,videoHeight:l.videoHeight},activePointerIds:Array.from($.current.keys())}),Ee.current||h?Wo(r,l):Ce(-1,r,l)}}}},Wo=(e,o)=>{const{videoX:n,videoY:s,videoWidth:r,videoHeight:h}=o,l=r-n,m=h-s;if(e==="down"){W.current={finger0:{x:n,y:s},finger1:{x:l,y:m},videoSize:{width:r,height:h},source:"alt-mouse",pointerId0:ut,pointerId1:ht},P.current?.focus(),Xe("down",r,h,n,s,l,m,ut,ht);return}if(e==="move"){W.current?.source==="alt-mouse"&&(W.current.finger0={x:n,y:s},W.current.finger1={x:l,y:m},Xe("move",r,h,n,s,l,m,ut,ht));return}if(e==="up"||e==="cancel"){const g=W.current;if(g?.source==="alt-mouse"){const{finger0:M,finger1:S,videoSize:T}=g;Xe("up",T.width,T.height,M.x,M.y,S.x,S.y,ut,ht),W.current=null}return}},Xo=150,io=()=>{const e=Pe.current;e&&(window.clearTimeout(e.endTimer),Ce(Re,"up",e.pos),Pe.current=null)},jo=e=>{if(!w.current?.getState().controlReady||e.ctrlKey)return;if(V==="macos"){if(it.current)return;const I=We();if(!I)return;const Se=e.clientX-I.videoRect.left-I.offsetX,pe=e.clientY-I.videoRect.top-I.offsetY;if(Se<0||Se>I.actualWidth||pe<0||pe>I.actualHeight)return;const he=me(I,e.clientX,e.clientY);if(!he)return;e.preventDefault();const Ke=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?I.actualHeight:1;Ie.scroll({x:he.videoX,y:he.videoY,width:he.videoWidth,height:he.videoHeight},e.deltaX*Ke,e.deltaY*Ke);return}if(Ee.current||W.current)return;const o=$.current.size;if(o>1||o===1&&!$.current.has(Re))return;const n=We();if(!n)return;const s=e.clientX-n.videoRect.left-n.offsetX,r=e.clientY-n.videoRect.top-n.offsetY;if(s<0||s>n.actualWidth||r<0||r>n.actualHeight)return;const h=me(n,e.clientX,e.clientY);if(!h)return;e.preventDefault();const l=(e.deltaMode===1?16:e.deltaMode===2?n.actualWidth:1)*(n.videoWidth/n.actualWidth),m=(e.deltaMode===1?16:e.deltaMode===2?n.actualHeight:1)*(n.videoHeight/n.actualHeight),g=-e.deltaX*l,M=-e.deltaY*m,S=I=>{window.clearTimeout(I.endTimer),I.endTimer=window.setTimeout(io,Xo)};if(g===0&&M===0){Pe.current&&S(Pe.current);return}const T=()=>({videoWidth:h.videoWidth,videoHeight:h.videoHeight,videoX:Math.abs(g)>Math.abs(M)?Math.min(Math.max(h.videoX,h.videoWidth*.2),h.videoWidth*.8):h.videoX,videoY:Math.abs(M)>=Math.abs(g)?Math.min(Math.max(h.videoY,h.videoHeight*.2),h.videoHeight*.8):h.videoY}),J=I=>({...I,videoX:Math.min(Math.max(I.videoX+g,0),I.videoWidth),videoY:Math.min(Math.max(I.videoY+M,0),I.videoHeight)});let X=Pe.current;if(X)window.clearTimeout(X.endTimer);else{const I=T();Ce(Re,"down",I),X={pos:I,endTimer:0},Pe.current=X}let q=X.pos,re=J(q);re.videoX===q.videoX&&re.videoY===q.videoY&&(Ce(Re,"up",q),q=T(),Ce(Re,"down",q),re=J(q)),Ce(Re,"move",re),X.pos=re,S(X)};a.useEffect(()=>{Fe.current={handle:jo,end:io}}),a.useEffect(()=>{const e=de.current;if(!e)return;const o=n=>Fe.current.handle(n);return e.addEventListener("wheel",o,{passive:!1}),()=>{Fe.current.end(),e.removeEventListener("wheel",o)}},[]),a.useEffect(()=>{const e=r=>{r.key==="Alt"&&Ct(!0)},o=r=>{r.key==="Alt"&&Ct(!1)},n=()=>{Ct(!1),Ze()},s=()=>{document.hidden&&Ze()};return window.addEventListener("keydown",e,!0),window.addEventListener("keyup",o,!0),window.addEventListener("blur",n),document.addEventListener("visibilitychange",s),()=>{window.removeEventListener("keydown",e,!0),window.removeEventListener("keyup",o,!0),window.removeEventListener("blur",n),document.removeEventListener("visibilitychange",s)}},[Ze]);const je=e=>{e.preventDefault(),e.stopPropagation();const o=document.activeElement===P.current||(Z||it.current)&&document.activeElement===e.currentTarget;if(i.debugLog("Keyboard event:",{type:e.type,key:e.key,keyCode:e.keyCode,code:e.code,target:e.target.tagName,focused:o}),!o){i.debugWarn("Simulator input not focused, skipping keyboard event");return}if(!w.current?.getState().controlReady){i.debugWarn("Data channel not ready for keyboard event:",w.current?.getState().connection);return}if(V==="macos"){if(e.type==="keydown"&&e.repeat)return;const s=i.macKeyCodeFor(e.code);if(s===void 0){i.debugLog(`Ignoring unmapped key for macOS: code=${e.code}`);return}e.type==="keydown"?lt.current.add(s):lt.current.delete(s),ie(i.createMacKeyMessage(e.type==="keydown"?i.MAC_INPUT_ACTION.DOWN:i.MAC_INPUT_ACTION.UP,s));return}if(e.type==="keydown"){if(e.key.toLowerCase()==="v"&&(e.metaKey||e.ctrlKey)){i.debugLog("Paste shortcut detected"),navigator.clipboard.readText().then(s=>{if(s){i.debugLog("Pasting text via SET_CLIPBOARD:",s.substring(0,20)+(s.length>20?"...":""));const r=i.createSetClipboardMessage(s,!0);ie(r)}}).catch(s=>{console.error("Failed to read clipboard contents: ",s)});return}if(e.key.toLowerCase()==="m"&&(e.metaKey||e.ctrlKey)){i.debugLog("Menu shortcut detected");const s=i.createInjectKeycodeMessage(i.ANDROID_KEYS.ACTION_DOWN,i.ANDROID_KEYS.MENU,0,i.ANDROID_KEYS.META_NONE);ie(s);const r=i.createInjectKeycodeMessage(i.ANDROID_KEYS.ACTION_UP,i.ANDROID_KEYS.MENU,0,i.ANDROID_KEYS.META_NONE);ie(r);return}}const n=In(e);if(n){const{keycode:s,metaState:r}=n,h=e.type==="keydown"?i.ANDROID_KEYS.ACTION_DOWN:i.ANDROID_KEYS.ACTION_UP;i.debugLog(`Sending Keycode: key=${e.key}, code=${s}, action=${h}, meta=${r}`);const l=i.createInjectKeycodeMessage(h,s,0,r);ie(l)}else i.debugLog(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`)},Ko=e=>{e.stopPropagation(),w.current?.reconnect()},F=a.useRef({onSpeakerBlocked:ae,onAxSnapshotChange:te,onAxStatusChange:k,onCameraDemandChange:L,onCameraStats:D,onMicrophoneStateChange:oe,onTrace:H,onTerminated:ee,onConnectionStateChange:ce,onPlaybackStats:j});F.current={onSpeakerBlocked:ae,onAxSnapshotChange:te,onAxStatusChange:k,onCameraDemandChange:L,onCameraStats:D,onMicrophoneStateChange:oe,onTrace:H,onTerminated:ee,onConnectionStateChange:ce,onPlaybackStats:j};const St=!!H;a.useEffect(()=>{Mt.current=null,Ht(!1),Xt(!1),jt({}),Vt(null)},[t,ot]),a.useEffect(()=>{let e=!0;be.current!==null&&(be.current=null,Nt(null),i.safeInvoke("onAxSnapshotChange",F.current.onAxSnapshotChange,null));const o=i.createDeviceStream({url:t,token:c,sessionId:So,watchOnly:B,deviceModel:ot,autoReconnect:R,jitterBufferTargetMs:Y,openUrl:v,inspectMode:_,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:b,microphoneEnabled:z,speakerMuted:K,onStateChange:r=>{(r.videoReady||r.connection==="idle"||r.connection==="connecting"||r.connection==="reconnecting")&&yo(r.videoReady),To(r.connection==="failed"),Eo(r.connection==="terminated"),tt(r.duo),mo(r.duoState),po(r.duoError)},onAxSnapshotChange:r=>{e&&(Nt(h=>i.axSnapshotsEqual(h,r)?h:r),F.current.onAxSnapshotChange?.(r))},onAxStatusChange:(...r)=>F.current.onAxStatusChange?.(...r),onCameraDemandChange:(...r)=>F.current.onCameraDemandChange?.(...r),onCameraStats:D?(...r)=>F.current.onCameraStats?.(...r):void 0,onMicrophoneStateChange:(...r)=>F.current.onMicrophoneStateChange?.(...r),onSpeakerBlocked:()=>F.current.onSpeakerBlocked?.(),onTrace:St?(...r)=>F.current.onTrace?.(...r):void 0,onTerminated:()=>F.current.onTerminated?.(),onConnectionStateChange:(...r)=>F.current.onConnectionStateChange?.(...r),onPlaybackStats:j?(...r)=>F.current.onPlaybackStats?.(...r):void 0});w.current=o;const n=P.current?o.attachVideo(P.current):void 0,s=rt.current?o.attachAudio(rt.current):void 0;return o.start(),()=>{e=!1,o.dispose(),n?.(),s?.(),w.current=null}},[t,u,ot,St,B]),a.useLayoutEffect(()=>{w.current?.updateOptions({speakerMuted:K});const e=rt.current;e&&(i.cancelSpeakerRetry(e),e.muted=K,!K&&e.srcObject&&i.playSpeaker(e,()=>i.safeInvoke("onSpeakerBlocked",F.current.onSpeakerBlocked)))},[K]),a.useEffect(()=>{if(Z&&nt.current)return w.current?.attachVideo(nt.current,"inner")},[Z,t,u,ot,St,B]),a.useEffect(()=>{w.current?.updateOptions({token:c,openUrl:v,axPollIntervalMs:f,axMaxBackoffMs:O,androidElementTreeOptions:b,autoReconnect:R,jitterBufferTargetMs:Y,microphoneEnabled:z,inspectMode:_,onPlaybackStats:j?(...e)=>F.current.onPlaybackStats?.(...e):void 0,onCameraStats:D?(...e)=>F.current.onCameraStats?.(...e):void 0})},[c,R,Y,z,_,!!j,!!D,v,f,O,b]);const Je=()=>{if(!Zt.current)return;const e=We();if(!e){zt(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};zt(n=>n&&n.left===o.left&&n.top===o.top&&n.width===o.width&&n.height===o.height?n:o)};a.useEffect(()=>{const e=P.current,o=G.current,n=de.current;if(!e)return;const s=S=>jt(T=>Et(T,S)?T:S),r=S=>Vt(T=>T&&S&&Et(T,S)?T:S),h=S=>bo(T=>T&&S&&Et(T,S)?T:S),l=()=>{const S=e.videoWidth>0&&e.videoHeight>0;S&&(Mt.current={width:e.videoWidth,height:e.videoHeight});const T=Mt.current,J=T?`${T.width} / ${T.height}`:void 0,X=It.current;if(_e&&n){if(Ut(T?T.width/T.height:kt),!X?.naturalWidth)return;const xe=X.naturalWidth/X.naturalHeight,ft=n.clientHeight-Ot,ke=n.clientHeight>0?Math.min(n.clientWidth,ft*xe):n.clientWidth;if(ke<=0)return;const Ve=ke/xe,Te=n.clientHeight>0?Ot/2:0,{screen:se}=_e,mt=se.notch??0,Be=se.left*ke,$e=se.top*Ve,pt=se.width*ke,gt=se.height*Ve,co=T?T.width/T.height:kt,yt=Math.min(pt,gt*co),xt=yt/co,$o=Be+(pt-yt)/2,Uo=mt>0?$e:$e+(gt-xt)/2,ao=(Qe,vt,Fo,zo)=>`translate(calc(-50% + ${Qe+Fo/2-ke/2}px), calc(-50% + ${vt+zo/2-Ve/2+Te}px))`;s({width:`${yt}px`,height:`${xt}px`,transform:ao($o,Uo,yt,xt)}),Mo(Qe=>{const vt={width:`${pt}px`,height:`${gt}px`,transform:ao(Be,$e,pt,gt)};return Qe&&Et(Qe,vt)?Qe:vt}),h({width:`${ke}px`,height:`${Ve}px`,transform:Te?`translateY(${Te}px)`:void 0}),r(null),Je();return}if(ue&&n){const xe=T?T.width/T.height:kt,ft=n.clientWidth*100/et,Ve=(n.clientHeight-Ot)/(1/xe+Pt/100),Te=n.clientHeight>0?Math.min(ft,Ve):ft;if(Te<=0)return;const se=Te/100,mt=Te/xe,Be=n.clientHeight>0?Ot/2:0,$e=`${se*Q.screenRadius}px`;s({aspectRatio:`${xe}`,width:`${Te}px`,height:`${mt}px`,borderRadius:`${$e} ${$e} 0 0`,transform:`translate(-50%, calc(-50% - ${se*qo-Be}px))`}),h({width:`${se*et}px`,height:`${mt+se*Pt}px`,transform:Be?`translateY(${Be}px)`:void 0,"--rc-macbook-unit":`${se}px`}),Ut(xe),r(null),Je();return}if(h(null),!qe||!o){s(!S&&T?{aspectRatio:J,contain:"size",containIntrinsicSize:`${T.width}px ${T.height}px`}:{}),r(null),Je();return}const q=o.clientWidth,re=o.clientHeight;if(q===0||re===0)return;const I=T?T.width>T.height:!1;Ht(I),Xt(V==="android"&&!!T&&Mn(T.width,T.height));const Se=I?Ne.videoPosition.landscape:Ne.videoPosition.portrait;let pe={aspectRatio:J};Se.heightMultiplier?(pe.height=`${re*Se.heightMultiplier}px`,pe.width="auto"):Se.widthMultiplier&&(pe.width=`${q*Se.widthMultiplier}px`,pe.height="auto"),pe.borderRadius=`${I?re*Ne.videoBorderRadiusMultiplier:q*Ne.videoBorderRadiusMultiplier}px`,s(pe);const he=Ne.homeButton,Ke=I?q:re,so=`calc(50% + ${Ke*(he?.offset??0)}px)`;r(he?{width:`${Ke*he.diameter}px`,height:`${Ke*he.diameter}px`,left:I?so:"50%",top:I?"50%":so}:null),Je()},m=new ResizeObserver(()=>{l()});o&&m.observe(o),m.observe(e),n&&m.observe(n),o&&o.addEventListener("load",l);const g=It.current;g?.addEventListener("load",l),e.addEventListener("loadedmetadata",l),e.addEventListener("resize",l);const M=()=>w.current?.bumpActivity();return e.addEventListener("resize",M),l(),()=>{m.disconnect(),e.removeEventListener("loadedmetadata",l),e.removeEventListener("resize",l),e.removeEventListener("resize",M),o&&o.removeEventListener("load",l),g?.removeEventListener("load",l)}},[Ne,qe,ue,_e?.src,we,t,N]),a.useEffect(()=>{Me?Je():(Nt(null),ze(null),ct(null),Gt(null),Le(null),at.current=null,fe.current!==void 0&&(window.cancelAnimationFrame(fe.current),fe.current=void 0))},[Me]),a.useEffect(()=>()=>{fe.current!==void 0&&(window.cancelAnimationFrame(fe.current),fe.current=void 0)},[]),a.useEffect(()=>{if(!Me)return;const e=o=>{o.key==="Escape"&&(wt||_t)&&(ct(null),ze(null),Le(null),i.safeInvoke("onInspectSelectionChange",Ye.current,null))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Me,wt,_t]);const Vo=()=>{P.current&&P.current.focus()};a.useImperativeHandle(ye,()=>({openUrl:e=>w.current?.openUrl(e),sendKeyEvent:e=>w.current?.sendKeyEvent(e),screenshot:e=>w.current?.screenshot(e)??Promise.reject(new Error("Simulator disconnected")),terminateApp:e=>w.current?.terminateApp(e)??Promise.reject(new Error("Simulator disconnected")),reconnect:()=>w.current?.reconnect(),refreshAxTree:()=>w.current?.refreshAxTree()??Promise.reject(new Error("Simulator disconnected")),getAxSnapshot:()=>w.current?.getAxSnapshot()??null,setInspectHighlight:e=>{ze(e?.id??null)},setInspectSelection:e=>{ct(e?.id??null),Le(e?at.current:null);const o=be.current;e&&o?i.safeInvoke("onInspectSelectionChange",Ye.current,{element:e,snapshot:o}):i.safeInvoke("onInspectSelectionChange",Ye.current,null)},getAxStatus:()=>w.current?.getAxStatus()??"idle"}));const Bo=No&&Ae!==null;return p.jsxs("div",{ref:de,className:["rc-container",d].filter(Boolean).join(" "),style:{touchAction:"none"},onMouseDown:ve,onMouseMove:ve,onMouseUp:ve,onMouseLeave:ve,onTouchStart:ve,onTouchMove:ve,onTouchEnd:ve,onTouchCancel:ve,onContextMenu:V==="macos"?e=>e.preventDefault():void 0,children:[Bo&&Ae&&p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"rc-touch-indicator",style:{left:`${Ae.containerX}px`,top:`${Ae.containerY}px`}}),p.jsx("div",{className:"rc-touch-indicator",style:{left:`${Ae.mirrorContainerX}px`,top:`${Ae.mirrorContainerY}px`}})]}),qe&&p.jsx("img",{ref:G,src:Qt,alt:"",className:V==="ios"?"rc-phone-frame rc-phone-frame-ios":"rc-phone-frame",draggable:!1}),_e&&!we&&Bt&&p.jsx("div",{className:"rc-macbook-screen",style:Bt,"aria-hidden":"true"}),_e&&!we&&p.jsx("img",{ref:It,src:_e.src,alt:"",className:"rc-macbook-image",style:bt??{visibility:"hidden"},draggable:!1}),ue&&!_e&&bt&&!we&&p.jsxs("div",{className:"rc-macbook",style:bt,"aria-hidden":"true",children:[p.jsx("div",{className:"rc-macbook-lid",children:p.jsx("div",{className:"rc-macbook-camera"})}),p.jsx("div",{className:"rc-macbook-base"})]}),qe&&Kt&&!B&&p.jsx("button",{type:"button",className:"rc-home-button","aria-label":"Home",title:"Home",style:Kt,onMouseDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation(),onTouchEnd:e=>{e.stopPropagation(),e.preventDefault(),w.current?.pressButton("home")},onClick:e=>{e.stopPropagation(),w.current?.pressButton("home")}}),p.jsx("video",{ref:P,className:["rc-video",!qe&&!ue&&"rc-video-frameless",!go&&(V==="macos"?"rc-video-loading-desktop":"rc-video-loading")].filter(Boolean).join(" "),style:{...Ao,...Z||we?{opacity:0,width:1,height:1,pointerEvents:"none"}:{},...eo?{backgroundImage:`url("${eo}")`,backgroundRepeat:"no-repeat",backgroundPosition:"center",backgroundSize:Ne.loadingLogoSize}:{}},autoPlay:!0,playsInline:!0,muted:!0,tabIndex:Z||we?-1:0,onKeyDown:je,onKeyUp:je,onClick:Vo,onFocus:()=>{P.current&&(P.current.style.outline="none")},onBlur:()=>{P.current&&(P.current.style.outline="none"),Ze()}}),xo&&$t&&p.jsx(a.Suspense,{fallback:null,children:p.jsx(bn,{video:P.current,aspect:$t,model:x??ne?.model,animateLid:A,watchOnly:B,onReady:Ue.onReady,pointer:(e,o,n,s)=>{const r=P.current;!r?.videoWidth||!w.current?.getState().controlReady||Ie.pointer(e==="down"?i.MAC_INPUT_ACTION.DOWN:e==="up"?i.MAC_INPUT_ACTION.UP:i.MAC_INPUT_ACTION.MOVE,{x:o*r.videoWidth,y:n*r.videoHeight,width:r.videoWidth,height:r.videoHeight},s)},scroll:(e,o,n,s)=>{const r=P.current;!r?.videoWidth||!w.current?.getState().controlReady||Ie.scroll({x:e*r.videoWidth,y:o*r.videoHeight,width:r.videoWidth,height:r.videoHeight},n,s)},onKeyDown:je,onKeyUp:je,onBlur:Ze})}),ue&&p.jsx(fo,{view:Ue,label:"MacBook rendering"}),p.jsx("audio",{ref:rt,muted:!0,hidden:!0}),Z&&p.jsx("video",{ref:nt,autoPlay:!0,playsInline:!0,muted:!0,style:{position:"absolute",width:1,height:1,opacity:0,pointerEvents:"none"}}),Z&&Lt&&p.jsx(a.Suspense,{fallback:p.jsx("div",{children:"Loading iPhone Duo…"}),children:p.jsx(An,{watchOnly:B,showFrame:y,model:C??ne?.model,outer:P.current,inner:nt.current,state:Lt,setAngle:e=>Rt("setHingeAngle",{angleDegrees:e}),setOrientation:e=>Rt("setDuoOrientation",{orientation:e}),button:(e,o)=>Rt("performActions",{actions:[{type:o?"buttonDown":"buttonUp",button:e}]}),touch:(e,o,n,s)=>{w.current?.sendDisplayTouch(e,o,n,s)},onKeyDown:je,onKeyUp:je})}),Z&&Yt&&p.jsx("div",{role:"alert",className:"rc-duo-error",children:Yt}),!Z&&Me&&p.jsx(On,{snapshot:Ft,geometry:wo,highlightedId:_t,selectedId:wt,mode:Co,cursorPosition:Io,frozenCursorPosition:Ro,onSelectChange:(e,o)=>{ct(e?.id??null),e&&o?Le(o):e||Le(null);const n=be.current;e&&n?i.safeInvoke("onInspectSelectionChange",Ye.current,{element:e,snapshot:n}):i.safeInvoke("onInspectSelectionChange",Ye.current,null)},onTapElement:B?void 0:((e,o)=>{if(o){ro(o.x,o.y);return}const n=be.current;n&&ko(e,n)})}),Oo?p.jsxs("div",{className:"rc-terminated",role:"status",children:[p.jsx("div",{className:"rc-terminated-title",children:"Instance terminated"}),p.jsx("div",{className:"rc-terminated-message",children:"This instance no longer exists and can't be reconnected."})]}):vo&&p.jsx("button",{type:"button",className:"rc-retry-button",onClick:Ko,children:"Retry"})]})});exports.DeviceModeToggle=fo;exports.MACBOOK_LID_MAX_DEGREES=en;exports.MACBOOK_LID_OPENING_MS=on;exports.MACBOOK_LID_OPEN_DEGREES=tn;exports.MACBOOK_VERTEX_FLOATS=Zo;exports.RemoteControl=Rn;exports.lidEase=rn;exports.lidRotation=nn;exports.macbookMeshes=sn;exports.streamFit=cn;exports.streamPoint=an;exports.useDeviceView=ho;