@limrun/ui 0.22.4 → 0.22.6
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/README.md +3 -3
- package/dist/components/remote-control.d.ts +15 -0
- package/dist/core/device-stream.d.ts +1 -0
- package/dist/core/stream-options.d.ts +10 -0
- package/dist/core/stream-utils.d.ts +10 -0
- package/dist/{core-nbvkIrvp.mjs → core-BPDihn1M.mjs} +907 -856
- package/dist/core-_qwksEry.js +2 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +4 -4
- package/dist/{duo-frame-Bm0hprn9.js → duo-frame-d3lnF2F7.js} +1 -1
- package/dist/{duo-frame-BCmB9_5p.mjs → duo-frame-s8ZpiZc-.mjs} +2 -2
- package/dist/{duo-view-C07GD_5E.mjs → duo-view-B2i1POpD.mjs} +3 -3
- package/dist/{duo-view-tUJbbWoS.js → duo-view-CKlDgO_u.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +26 -26
- package/dist/lite.cjs +1 -1
- package/dist/lite.js +2 -2
- package/dist/{macbook-frame-Dm6ko0j9.mjs → macbook-frame-BZhBYM9R.mjs} +1 -1
- package/dist/{macbook-frame-BxJfxUcU.js → macbook-frame-g3h4xP5G.js} +1 -1
- package/dist/remote-control-DmPKov-i.mjs +1723 -0
- package/dist/remote-control-y8mgo_2E.js +1 -0
- package/package.json +1 -1
- package/dist/core-BCBQrYsk.js +0 -2
- package/dist/remote-control-BX6dzHtt.mjs +0 -1712
- package/dist/remote-control-CEVcOPQZ.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const Z={INJECT_KEYCODE:0,INJECT_TEXT:1,INJECT_TOUCH_EVENT:2,INJECT_TWO_FINGER_TOUCH_EVENT:18,INJECT_SCROLL_EVENT:3,BACK_OR_SCREEN_ON:4,EXPAND_NOTIFICATION_PANEL:5,EXPAND_SETTINGS_PANEL:6,COLLAPSE_PANELS:7,GET_CLIPBOARD:8,SET_CLIPBOARD:9,SET_DISPLAY_POWER:10,ROTATE_DEVICE:11,INJECT_MOUSE_EVENT:40,INJECT_MAC_KEY:41,INJECT_MAC_SCROLL:42},Pe={DOWN:0,UP:1,MOVE:2},Le={ACTION_DOWN:0,ACTION_UP:1,ACTION_MOVE:2,ACTION_CANCEL:3,ACTION_POINTER_DOWN:5,ACTION_POINTER_UP:6,BUTTON_PRIMARY:1,BUTTON_SECONDARY:2,BUTTON_TERTIARY:4},a={ACTION_DOWN:0,ACTION_UP:1,META_NONE:0,META_SHIFT_ON:1,META_ALT_ON:2,META_CTRL_ON:4096,META_META_ON:65536,KEYCODE_UNKNOWN:0,KEYCODE_SOFT_LEFT:1,KEYCODE_SOFT_RIGHT:2,KEYCODE_HOME:3,KEYCODE_BACK:4,KEYCODE_CALL:5,KEYCODE_ENDCALL:6,KEYCODE_0:7,KEYCODE_1:8,KEYCODE_2:9,KEYCODE_3:10,KEYCODE_4:11,KEYCODE_5:12,KEYCODE_6:13,KEYCODE_7:14,KEYCODE_8:15,KEYCODE_9:16,KEYCODE_STAR:17,KEYCODE_POUND:18,DPAD_UP:19,DPAD_DOWN:20,DPAD_LEFT:21,DPAD_RIGHT:22,KEYCODE_DPAD_CENTER:23,KEYCODE_VOLUME_UP:24,KEYCODE_VOLUME_DOWN:25,KEYCODE_POWER:26,KEYCODE_CAMERA:27,KEYCODE_CLEAR:28,KEYCODE_A:29,KEYCODE_B:30,KEYCODE_C:31,KEYCODE_D:32,KEYCODE_E:33,KEYCODE_F:34,KEYCODE_G:35,KEYCODE_H:36,KEYCODE_I:37,KEYCODE_J:38,KEYCODE_K:39,KEYCODE_L:40,KEYCODE_M:41,KEYCODE_N:42,KEYCODE_O:43,KEYCODE_P:44,KEYCODE_Q:45,KEYCODE_R:46,KEYCODE_S:47,KEYCODE_T:48,KEYCODE_U:49,KEYCODE_V:50,KEYCODE_W:51,KEYCODE_X:52,KEYCODE_Y:53,KEYCODE_Z:54,KEYCODE_COMMA:55,KEYCODE_PERIOD:56,KEYCODE_ALT_LEFT:57,KEYCODE_ALT_RIGHT:58,KEYCODE_SHIFT_LEFT:59,KEYCODE_SHIFT_RIGHT:60,KEYCODE_TAB:61,KEYCODE_SPACE:62,KEYCODE_SYM:63,KEYCODE_EXPLORER:64,KEYCODE_ENVELOPE:65,ENTER:66,DEL:67,KEYCODE_GRAVE:68,KEYCODE_MINUS:69,KEYCODE_EQUALS:70,KEYCODE_LEFT_BRACKET:71,KEYCODE_RIGHT_BRACKET:72,KEYCODE_BACKSLASH:73,KEYCODE_SEMICOLON:74,KEYCODE_APOSTROPHE:75,KEYCODE_SLASH:76,KEYCODE_AT:77,KEYCODE_NUM:78,KEYCODE_HEADSETHOOK:79,KEYCODE_FOCUS:80,KEYCODE_PLUS:81,MENU:82,KEYCODE_NOTIFICATION:83,KEYCODE_SEARCH:84,KEYCODE_MEDIA_PLAY_PAUSE:85,KEYCODE_MEDIA_STOP:86,KEYCODE_MEDIA_NEXT:87,KEYCODE_MEDIA_PREVIOUS:88,KEYCODE_MEDIA_REWIND:89,KEYCODE_MEDIA_FAST_FORWARD:90,KEYCODE_MUTE:91,KEYCODE_PAGE_UP:92,KEYCODE_PAGE_DOWN:93,KEYCODE_PICTSYMBOLS:94,KEYCODE_SWITCH_CHARSET:95,KEYCODE_BUTTON_A:96,KEYCODE_BUTTON_B:97,KEYCODE_BUTTON_C:98,KEYCODE_BUTTON_X:99,KEYCODE_BUTTON_Y:100,KEYCODE_BUTTON_Z:101,KEYCODE_BUTTON_L1:102,KEYCODE_BUTTON_R1:103,KEYCODE_BUTTON_L2:104,KEYCODE_BUTTON_R2:105,KEYCODE_BUTTON_THUMBL:106,KEYCODE_BUTTON_THUMBR:107,KEYCODE_BUTTON_START:108,KEYCODE_BUTTON_SELECT:109,KEYCODE_BUTTON_MODE:110,KEYCODE_ESCAPE:111,FORWARD_DEL:112,KEYCODE_CTRL_LEFT:113,KEYCODE_CTRL_RIGHT:114,KEYCODE_CAPS_LOCK:115,KEYCODE_SCROLL_LOCK:116,KEYCODE_META_LEFT:117,KEYCODE_META_RIGHT:118,KEYCODE_FUNCTION:119,KEYCODE_SYSRQ:120,KEYCODE_BREAK:121,KEYCODE_MOVE_HOME:122,KEYCODE_MOVE_END:123,KEYCODE_INSERT:124,KEYCODE_FORWARD:125,KEYCODE_MEDIA_PLAY:126,KEYCODE_MEDIA_PAUSE:127,KEYCODE_MEDIA_CLOSE:128,KEYCODE_MEDIA_EJECT:129,KEYCODE_MEDIA_RECORD:130,KEYCODE_F1:131,KEYCODE_F2:132,KEYCODE_F3:133,KEYCODE_F4:134,KEYCODE_F5:135,KEYCODE_F6:136,KEYCODE_F7:137,KEYCODE_F8:138,KEYCODE_F9:139,KEYCODE_F10:140,KEYCODE_F11:141,KEYCODE_F12:142,KEYCODE_NUM_LOCK:143,KEYCODE_NUMPAD_0:144,KEYCODE_NUMPAD_1:145,KEYCODE_NUMPAD_2:146,KEYCODE_NUMPAD_3:147,KEYCODE_NUMPAD_4:148,KEYCODE_NUMPAD_5:149,KEYCODE_NUMPAD_6:150,KEYCODE_NUMPAD_7:151,KEYCODE_NUMPAD_8:152,KEYCODE_NUMPAD_9:153,KEYCODE_NUMPAD_DIVIDE:154,KEYCODE_NUMPAD_MULTIPLY:155,KEYCODE_NUMPAD_SUBTRACT:156,KEYCODE_NUMPAD_ADD:157,KEYCODE_NUMPAD_DOT:158,KEYCODE_NUMPAD_COMMA:159,KEYCODE_NUMPAD_ENTER:160,KEYCODE_NUMPAD_EQUALS:161,KEYCODE_NUMPAD_LEFT_PAREN:162,KEYCODE_NUMPAD_RIGHT_PAREN:163,KEYCODE_VOLUME_MUTE:164,KEYCODE_INFO:165,KEYCODE_CHANNEL_UP:166,KEYCODE_CHANNEL_DOWN:167,KEYCODE_ZOOM_IN:168,KEYCODE_ZOOM_OUT:169,KEYCODE_TV:170,KEYCODE_WINDOW:171,KEYCODE_GUIDE:172,KEYCODE_DVR:173,KEYCODE_BOOKMARK:174,KEYCODE_CAPTIONS:175,KEYCODE_SETTINGS:176,KEYCODE_TV_POWER:177,KEYCODE_TV_INPUT:178,KEYCODE_STB_POWER:179,KEYCODE_STB_INPUT:180,KEYCODE_AVR_POWER:181,KEYCODE_AVR_INPUT:182,KEYCODE_PROG_RED:183,KEYCODE_PROG_GREEN:184,KEYCODE_PROG_YELLOW:185,KEYCODE_PROG_BLUE:186,KEYCODE_APP_SWITCH:187,KEYCODE_LANGUAGE_SWITCH:204,KEYCODE_ASSIST:219,KEYCODE_BRIGHTNESS_DOWN:220,KEYCODE_BRIGHTNESS_UP:221,KEYCODE_SLEEP:223,KEYCODE_WAKEUP:224,KEYCODE_SOFT_SLEEP:276},Lt={KeyA:a.KEYCODE_A,KeyB:a.KEYCODE_B,KeyC:a.KEYCODE_C,KeyD:a.KEYCODE_D,KeyE:a.KEYCODE_E,KeyF:a.KEYCODE_F,KeyG:a.KEYCODE_G,KeyH:a.KEYCODE_H,KeyI:a.KEYCODE_I,KeyJ:a.KEYCODE_J,KeyK:a.KEYCODE_K,KeyL:a.KEYCODE_L,KeyM:a.KEYCODE_M,KeyN:a.KEYCODE_N,KeyO:a.KEYCODE_O,KeyP:a.KEYCODE_P,KeyQ:a.KEYCODE_Q,KeyR:a.KEYCODE_R,KeyS:a.KEYCODE_S,KeyT:a.KEYCODE_T,KeyU:a.KEYCODE_U,KeyV:a.KEYCODE_V,KeyW:a.KEYCODE_W,KeyX:a.KEYCODE_X,KeyY:a.KEYCODE_Y,KeyZ:a.KEYCODE_Z,Digit0:a.KEYCODE_0,Digit1:a.KEYCODE_1,Digit2:a.KEYCODE_2,Digit3:a.KEYCODE_3,Digit4:a.KEYCODE_4,Digit5:a.KEYCODE_5,Digit6:a.KEYCODE_6,Digit7:a.KEYCODE_7,Digit8:a.KEYCODE_8,Digit9:a.KEYCODE_9,Backquote:a.KEYCODE_GRAVE,Minus:a.KEYCODE_MINUS,Equal:a.KEYCODE_EQUALS,BracketLeft:a.KEYCODE_LEFT_BRACKET,BracketRight:a.KEYCODE_RIGHT_BRACKET,Backslash:a.KEYCODE_BACKSLASH,Semicolon:a.KEYCODE_SEMICOLON,Quote:a.KEYCODE_APOSTROPHE,Comma:a.KEYCODE_COMMA,Period:a.KEYCODE_PERIOD,Slash:a.KEYCODE_SLASH,Space:a.KEYCODE_SPACE,Tab:a.KEYCODE_TAB,Escape:a.KEYCODE_ESCAPE,ArrowUp:a.DPAD_UP,ArrowDown:a.DPAD_DOWN,ArrowLeft:a.DPAD_LEFT,ArrowRight:a.DPAD_RIGHT,Enter:a.ENTER,Backspace:a.DEL,Delete:a.FORWARD_DEL,Home:a.KEYCODE_MOVE_HOME,End:a.KEYCODE_MOVE_END,PageUp:a.KEYCODE_PAGE_UP,PageDown:a.KEYCODE_PAGE_DOWN,Insert:a.KEYCODE_INSERT,F1:a.KEYCODE_F1,F2:a.KEYCODE_F2,F3:a.KEYCODE_F3,F4:a.KEYCODE_F4,F5:a.KEYCODE_F5,F6:a.KEYCODE_F6,F7:a.KEYCODE_F7,F8:a.KEYCODE_F8,F9:a.KEYCODE_F9,F10:a.KEYCODE_F10,F11:a.KEYCODE_F11,F12:a.KEYCODE_F12,ShiftLeft:a.KEYCODE_SHIFT_LEFT,ShiftRight:a.KEYCODE_SHIFT_RIGHT,ControlLeft:a.KEYCODE_CTRL_LEFT,ControlRight:a.KEYCODE_CTRL_RIGHT,AltLeft:a.KEYCODE_ALT_LEFT,AltRight:a.KEYCODE_ALT_RIGHT,MetaLeft:a.KEYCODE_META_LEFT,MetaRight:a.KEYCODE_META_RIGHT,ContextMenu:a.MENU,Numpad0:a.KEYCODE_NUMPAD_0,Numpad1:a.KEYCODE_NUMPAD_1,Numpad2:a.KEYCODE_NUMPAD_2,Numpad3:a.KEYCODE_NUMPAD_3,Numpad4:a.KEYCODE_NUMPAD_4,Numpad5:a.KEYCODE_NUMPAD_5,Numpad6:a.KEYCODE_NUMPAD_6,Numpad7:a.KEYCODE_NUMPAD_7,Numpad8:a.KEYCODE_NUMPAD_8,Numpad9:a.KEYCODE_NUMPAD_9,NumpadDivide:a.KEYCODE_NUMPAD_DIVIDE,NumpadMultiply:a.KEYCODE_NUMPAD_MULTIPLY,NumpadSubtract:a.KEYCODE_NUMPAD_SUBTRACT,NumpadAdd:a.KEYCODE_NUMPAD_ADD,NumpadDecimal:a.KEYCODE_NUMPAD_DOT,NumpadComma:a.KEYCODE_NUMPAD_COMMA,NumpadEnter:a.KEYCODE_NUMPAD_ENTER,NumpadEqual:a.KEYCODE_NUMPAD_EQUALS},mr={KeyA:0,KeyS:1,KeyD:2,KeyF:3,KeyH:4,KeyG:5,KeyZ:6,KeyX:7,KeyC:8,KeyV:9,IntlBackslash:10,KeyB:11,KeyQ:12,KeyW:13,KeyE:14,KeyR:15,KeyY:16,KeyT:17,Digit1:18,Digit2:19,Digit3:20,Digit4:21,Digit6:22,Digit5:23,Equal:24,Digit9:25,Digit7:26,Minus:27,Digit8:28,Digit0:29,BracketRight:30,KeyO:31,KeyU:32,BracketLeft:33,KeyI:34,KeyP:35,Enter:36,KeyL:37,KeyJ:38,Quote:39,KeyK:40,Semicolon:41,Backslash:42,Comma:43,Slash:44,KeyN:45,KeyM:46,Period:47,Tab:48,Space:49,Backquote:50,Backspace:51,Escape:53,MetaRight:54,MetaLeft:55,ShiftLeft:56,CapsLock:57,AltLeft:58,ControlLeft:59,ShiftRight:60,AltRight:61,ControlRight:62,Fn:63,F17:64,NumpadDecimal:65,NumpadMultiply:67,NumpadAdd:69,NumLock:71,NumpadDivide:75,NumpadEnter:76,NumpadSubtract:78,F18:79,F19:80,NumpadEqual:81,Numpad0:82,Numpad1:83,Numpad2:84,Numpad3:85,Numpad4:86,Numpad5:87,Numpad6:88,Numpad7:89,F20:90,Numpad8:91,Numpad9:92,F5:96,F6:97,F7:98,F3:99,F8:100,F9:101,F11:103,F13:105,F16:106,F14:107,F10:109,ContextMenu:110,F12:111,F15:113,Help:114,Insert:114,Home:115,PageUp:116,Delete:117,F4:118,End:119,F2:120,PageDown:121,F1:122,ArrowLeft:123,ArrowRight:124,ArrowDown:125,ArrowUp:126};function Et(t){return mr[t]}function Ft(t,e,r,o,u,l,i=1,E=0,D=0){const p=new ArrayBuffer(32),S=new DataView(p);let w=0;S.setUint8(w,Z.INJECT_TOUCH_EVENT),w+=1;const N=t===Le.ACTION_POINTER_DOWN?Le.ACTION_DOWN:t===Le.ACTION_POINTER_UP?Le.ACTION_UP:t;return S.setUint8(w,N),w+=1,S.setBigInt64(w,BigInt(e),!0),w+=8,S.setInt32(w,Math.round(u),!0),w+=4,S.setInt32(w,Math.round(l),!0),w+=4,S.setUint16(w,r,!0),w+=2,S.setUint16(w,o,!0),w+=2,S.setInt16(w,Math.round(i*65535),!0),w+=2,S.setInt32(w,E,!0),w+=4,S.setInt32(w,D,!0),p}function Cr(t,e,r,o,u,l,i){const E=new ArrayBuffer(24),D=new DataView(E);let p=0;return D.setUint8(p,Z.INJECT_TWO_FINGER_TOUCH_EVENT),p+=1,D.setUint8(p,t),p+=1,D.setInt32(p,Math.round(o),!0),p+=4,D.setInt32(p,Math.round(u),!0),p+=4,D.setInt32(p,Math.round(l),!0),p+=4,D.setInt32(p,Math.round(i),!0),p+=4,D.setUint16(p,e,!0),p+=2,D.setUint16(p,r,!0),p+=2,D.setUint16(p,0,!0),E}function Bt(t,e=!0){const o=new TextEncoder().encode(t),u=new ArrayBuffer(14+o.length),l=new DataView(u);let i=0;return l.setUint8(i,Z.SET_CLIPBOARD),i+=1,l.setBigInt64(i,BigInt(0),!1),i+=8,l.setUint8(i,e?1:0),i+=1,l.setUint32(i,o.length,!1),i+=4,new Uint8Array(u,i).set(o),u}function Ze(t,e,r=0,o=0){const u=new ArrayBuffer(14),l=new DataView(u);let i=0;return l.setUint8(i,Z.INJECT_KEYCODE),i+=1,l.setUint8(i,t),i+=1,l.setInt32(i,e,!0),i+=4,l.setInt32(i,r,!0),i+=4,l.setInt32(i,o,!0),u}function Or(t,e,r,o,u,l){const i=new ArrayBuffer(18),E=new DataView(i);return E.setUint8(0,Z.INJECT_MOUSE_EVENT),E.setUint8(1,t),E.setInt32(2,Math.round(o),!0),E.setInt32(6,Math.round(u),!0),E.setUint16(10,e,!0),E.setUint16(12,r,!0),E.setInt32(14,l,!0),i}function xt(t,e){const r=new ArrayBuffer(4),o=new DataView(r);return o.setUint8(0,Z.INJECT_MAC_KEY),o.setUint8(1,t),o.setUint16(2,e,!0),r}function Dr(t,e,r,o,u,l){const i=new ArrayBuffer(21),E=new DataView(i);return E.setUint8(0,Z.INJECT_MAC_SCROLL),E.setInt32(1,Math.round(r),!0),E.setInt32(5,Math.round(o),!0),E.setUint16(9,t,!0),E.setUint16(11,e,!0),E.setFloat32(13,u,!0),E.setFloat32(17,l,!0),i}function _r(t){return t?.displays.find(e=>e.id===(t.angleDegrees<90?"outer":"inner"))}function Wt(t){return t===2?2:t===3?1:t===4?3:0}class gr{constructor(e){this.send=e}send;screenId;turns=0;held;get active(){return this.held!==void 0}setDisplay(e,r=Wt(e?.orientation)){(this.screenId!==e?.screenId||this.turns!==r)&&this.release(),this.screenId=e?.screenId,this.turns=r}touch(e,r,o,u=!1){if(this.screenId===void 0)return;const l=qt(r,o,u?0:this.turns);e==="begin"&&(this.release(),this.held={screenId:this.screenId,...l}),this.held&&(Object.assign(this.held,l),e==="end"?this.release():this.send(e==="begin"?0:2,this.held.screenId,l.x,l.y))}release(){if(!this.held)return;const{screenId:e,x:r,y:o}=this.held;this.held=void 0,this.send(1,e,r,o)}}const Tr={width:164.6,height:117.8,depth:5.2};function qt(t,e,r){return t=Math.max(0,Math.min(1,t)),e=Math.max(0,Math.min(1,e)),r===1?{x:e,y:1-t}:r===2?{x:1-t,y:1-e}:r===3?{x:1-e,y:t}:{x:t,y:e}}function yr(t){return Number.isFinite(t)&&t>=0&&t<=180}function Sr(t,e){return{x:Math.max(0,Math.min(1,t)),y:Math.max(0,Math.min(1,1-e))}}function Kr(t,e,r){return e&&(t||!r)?"touch":t?"ignore":"orbit"}function Vt(t,e,r,o){if(!Number.isInteger(t)||t<0||t>3||!Number.isInteger(e)||e<1||e>255||!Number.isFinite(r)||!Number.isFinite(o)||r<0||r>1||o<0||o>1)throw new RangeError("Invalid display touch coordinates");const u=new ArrayBuffer(12),l=new DataView(u);return l.setUint8(0,19),l.setUint8(1,t),l.setUint8(2,e),l.setFloat32(4,r,!0),l.setFloat32(8,o,!0),u}class Ar{constructor(e,r){this.send=e,this.failed=r}send;failed;latest;running=!1;stopped=!1;set(e){this.stopped||!yr(e)||(this.latest=e,this.flush())}stop(){this.stopped=!0,this.latest=void 0}async flush(){if(!(this.running||this.stopped)){this.running=!0;try{for(;this.latest!==void 0&&!this.stopped;){const e=this.latest;this.latest=void 0,await this.send(e)}}catch(e){this.latest=void 0,this.stopped||this.failed(e)}finally{this.running=!1}}}}const Mr={side:"Sleep/Wake",volumeUp:"Volume Up",volumeDown:"Volume Down"};class vr{constructor(e,r){this.send=e,this.failed=r}send;failed;held;tail=Promise.resolve();timeout;press(e){this.held||(this.held=e,this.enqueue(e,!0),this.timeout=setTimeout(()=>this.release(),1e4))}release(){if(!this.held)return;clearTimeout(this.timeout);const e=this.held;this.held=void 0,this.enqueue(e,!1)}enqueue(e,r){this.tail=this.tail.then(()=>this.send(e,r)).catch(this.failed)}}const et="Accessibility unavailable on this device.",tt=500,$t=(t,e)=>Math.abs(t.x-e.x)<.5&&Math.abs(t.y-e.y)<.5&&Math.abs(t.width-e.width)<.5&&Math.abs(t.height-e.height)<.5,wr=t=>Math.max(0,t.width)*Math.max(0,t.height),Nr=t=>{const e=t.find(r=>r.frame&&r.frame.width>0&&r.frame.height>0);return e?.frame?((Math.abs(e.frame.x)>.5||Math.abs(e.frame.y)>.5)&&console.warn(`[ax-tree] iOS root frame is not anchored at (0,0): (${e.frame.x},${e.frame.y}). Element positions may be slightly off from the rendered video.`),{x:0,y:0,width:e.frame.width,height:e.frame.height}):{x:0,y:0,width:1,height:1}},br=t=>{const e={};return typeof t.AXUniqueId=="string"&&t.AXUniqueId.length>0&&(e.AXUniqueId=t.AXUniqueId),typeof t.AXLabel=="string"&&t.AXLabel.length>0&&(e.AXLabel=t.AXLabel),typeof t.type=="string"&&t.type.length>0&&(e.className=t.type),e},Yr=t=>{const e={};for(const[r,o]of Object.entries(t))r!=="children"&&(e[r]=o);return e};function Ht(t){const e=Array.isArray(t)?t:[t],r=Nr(e),o=[],u=(l,i)=>{if(o.length>=tt)return;const E=l.frame;if(E&&E.width>0&&E.height>0&&!$t(E,r)){const p=l.role_description||l.role||"",S=(typeof l.AXLabel=="string"?l.AXLabel:"")||(typeof l.title=="string"?l.title:"")||"";o.push({id:typeof l.AXUniqueId=="string"&&l.AXUniqueId.length>0?l.AXUniqueId:i,path:i,label:S,value:typeof l.AXValue=="string"?l.AXValue:"",role:p,type:typeof l.type=="string"?l.type:"",enabled:l.enabled!==!1,focused:l.focused===!0,frame:{x:E.x,y:E.y,width:E.width,height:E.height},selectors:br(l),raw:Yr(l)})}const D=Array.isArray(l.children)?l.children:[];for(let p=0;p<D.length&&o.length<tt;p++)u(D[p],`${i}.${p}`)};for(let l=0;l<e.length&&o.length<tt;l++)u(e[l],String(l));return{platform:"ios",screen:{width:r.width,height:r.height},elements:o,capturedAt:Date.now()}}const Ir=t=>{let e={x:0,y:0,width:1,height:1},r=0;for(const o of t){const u=o.parsedBounds;if(!u)continue;const l=u.right-u.left,i=u.bottom-u.top,E=Math.max(0,l)*Math.max(0,i);E>r&&(r=E,e={x:0,y:0,width:l,height:i})}return e},Rr=t=>{const e={};return typeof t.resourceId=="string"&&t.resourceId.length>0&&(e.resourceId=t.resourceId),typeof t.contentDesc=="string"&&t.contentDesc.length>0&&(e.contentDesc=t.contentDesc),typeof t.text=="string"&&t.text.length>0&&(e.text=t.text),typeof t.className=="string"&&t.className.length>0&&(e.className=t.className),e};function Jt(t){const e=Ir(t),r=[];for(let o=0;o<t.length&&r.length<tt;o++){const u=t[o],l=u.parsedBounds;if(!l)continue;const i=Math.max(0,l.right-l.left),E=Math.max(0,l.bottom-l.top);if(i<=0||E<=0)continue;const D={x:l.left,y:l.top,width:i,height:E};if($t(D,{x:0,y:0,width:e.width,height:e.height}))continue;const p=u.contentDesc||u.text||"",S=u.className||"";r.push({id:u.resourceId&&u.resourceId.length>0?u.resourceId:u.contentDesc&&u.contentDesc.length>0?`cd:${u.contentDesc}`:String(o),path:String(o),label:p,value:typeof u.text=="string"?u.text:"",role:S,type:S,enabled:u.enabled!==!1,focused:u.focused===!0,frame:D,selectors:Rr(u),raw:{...u}})}return{platform:"android",screen:{width:e.width,height:e.height},elements:r,capturedAt:Date.now()}}function kr(t,e){const r=Math.max(0,t.x),o=Math.max(0,t.y),u=Math.min(e.width,t.x+t.width),l=Math.min(e.height,t.y+t.height),i=Math.max(0,u-r),E=Math.max(0,l-o);return i>0&&E>0?{x:r,y:o,width:i,height:E}:null}function Gt(t,e){if(t===e)return!0;if(t.id!==e.id||t.path!==e.path||t.label!==e.label||t.value!==e.value||t.role!==e.role||t.type!==e.type||t.enabled!==e.enabled||t.focused!==e.focused)return!1;const r=t.frame,o=e.frame;return r.x===o.x&&r.y===o.y&&r.width===o.width&&r.height===o.height}function jt(t,e){if(t===e)return!0;if(!t||!e||t.platform!==e.platform||t.screen.width!==e.screen.width||t.screen.height!==e.screen.height||t.elements.length!==e.elements.length)return!1;for(let r=0;r<t.elements.length;r++)if(!Gt(t.elements[r],e.elements[r]))return!1;return!0}function Ur(t,e,r){let o=null,u=1/0;for(const l of t.elements){const i=l.frame;if(e<i.x||r<i.y||e>i.x+i.width||r>i.y+i.height)continue;const E=wr(i);E<u&&(u=E,o=l)}return o}function Pr(t,e){if(e==="ios"){if(t.selectors.AXUniqueId)return`client.tapElement({ AXUniqueId: ${JSON.stringify(t.selectors.AXUniqueId)} })`;if(t.selectors.AXLabel){const r=t.selectors.className?`, type: ${JSON.stringify(t.selectors.className)}`:"";return`client.tapElement({ AXLabel: ${JSON.stringify(t.selectors.AXLabel)}${r} })`}return null}return t.selectors.resourceId?`client.tap({ selector: { resourceId: ${JSON.stringify(t.selectors.resourceId)} } })`:t.selectors.contentDesc?`client.tap({ selector: { contentDesc: ${JSON.stringify(t.selectors.contentDesc)} } })`:t.selectors.text?`client.tap({ selector: { text: ${JSON.stringify(t.selectors.text)} } })`:null}function Xt(t){const e=t.role||t.type||"";if(!e)return"element";let r=e.replace(/^AX/,"");return r.includes(".")&&(r=r.split(".").pop()),r==="GenericElement"?"Element":(r=r.replace(/([a-z])([A-Z])/g,"$1 $2"),r)}const bt=80;function Lr(t){const e=Xt(t),r=t.label||t.value||"";if(!r)return e;const o=r.length>bt?r.slice(0,bt).trimEnd()+"…":r;return`${e} · ${o}`}const Fr=500,Br=2e3,Yt=5e3,xr=8e3,Wr=1200,qr=250,Vr=()=>`ax-rc-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;class $r{platform;send;onSnapshot;onStatusChange;baseIntervalMs;maxBackoffMs;androidElementTreeOptions;pending=new Map;running=!1;timer;currentInterval;lastSnapshot=null;inflight=!1;lastBumpAtMs=0;boostUntilMs=0;status="idle";constructor(e){this.platform=e.platform,this.send=e.send,this.onSnapshot=e.onSnapshot,this.onStatusChange=e.onStatusChange,this.baseIntervalMs=e.baseIntervalMs??Fr,this.maxBackoffMs=e.maxBackoffMs??Br,this.androidElementTreeOptions=e.androidElementTreeOptions,this.currentInterval=this.baseIntervalMs}start(){this.running||(this.running=!0,this.currentInterval=this.baseIntervalMs,this.boostUntilMs=0,this.setStatus("starting"),this.runOnce())}stop(){this.running&&(this.running=!1,this.timer!==void 0&&(window.clearTimeout(this.timer),this.timer=void 0),this.failAllPending("Inspector stopped"),this.lastSnapshot=null,this.setStatus("idle"),this.onSnapshot(null))}getStatus(){return this.status}setStatus(e,r){if(this.status!==e&&(this.status=e,!!this.onStatusChange))try{this.onStatusChange(e,r)}catch(o){console.error("[AxFetcher] onStatusChange threw:",o)}}bumpActivity(){if(!this.running)return;const e=Date.now();this.boostUntilMs=e+Wr;const r=Math.max(150,Math.floor(this.baseIntervalMs/2));if(e-this.lastBumpAtMs<r){this.currentInterval=this.baseIntervalMs;return}this.lastBumpAtMs=e,this.currentInterval=this.baseIntervalMs,this.timer!==void 0&&(window.clearTimeout(this.timer),this.timer=void 0),this.inflight||this.runOnce()}async refresh(){const e=await this.requestOnce();return this.running&&this.deliver(e),e}getLatest(){return this.lastSnapshot}handleMessage(e){if(!e||typeof e.id!="string")return!1;const r=e.id;if(!this.pending.get(r))return!1;if(this.platform==="ios"){if(e.type!=="elementTreeResult")return!1;const E=typeof e.error=="string"?e.error:null;if(E)return this.settleReject(r,new Error(E)),!0;const D=typeof e.json=="string"?e.json:"";try{const p=JSON.parse(D),S=Ht(p);this.settleResolve(r,S)}catch(p){this.settleReject(r,p instanceof Error?p:new Error(String(p)))}return!0}if(e.type!=="getElementTreeResult")return!1;const u=e.error;if(u&&typeof u=="object"){const E=typeof u.message=="string"?u.message:"getElementTree failed";return this.settleReject(r,new Error(E)),!0}const l=e.payload,i=Array.isArray(l?.nodes)?l.nodes:[];try{const E=Jt(i);this.settleResolve(r,E)}catch(E){this.settleReject(r,E instanceof Error?E:new Error(String(E)))}return!0}buildRequest(e){return this.platform==="ios"?{type:"elementTree",id:e}:{type:"getElementTree",id:e,...this.androidElementTreeOptions}}async requestOnce(){const e=Vr();return new Promise((r,o)=>{const u=window.setTimeout(()=>{this.pending.delete(e),o(new Error("elementTree request timed out"))},xr+(this.androidElementTreeOptions?.waitForIdleTimeoutMs??0));this.pending.set(e,{resolve:r,reject:o,timer:u}),this.send(this.buildRequest(e))||(window.clearTimeout(u),this.pending.delete(e),o(new Error("elementTree send failed (WebSocket not open)")))})}async runOnce(){if(this.running&&!this.inflight){this.inflight=!0;try{const e=await this.requestOnce();if(!this.running)return;this.deliver(e)}catch(e){if(!this.running)return;const r=e instanceof Error?e.message:String(e),o=/unavailable|not (yet )?running|failed|timeout/i.test(r);this.currentInterval=o?Yt:Math.min(this.currentInterval*2,this.maxBackoffMs),this.setStatus(o?"unavailable":"error",r)}finally{this.inflight=!1,this.scheduleNext()}}}deliver(e){const r=this.lastSnapshot;if(jt(r,e)){this.currentInterval=Math.min(this.currentInterval*2,this.maxBackoffMs),this.lastSnapshot=e,e.errors?.includes(et)||this.setStatus("ready");return}this.lastSnapshot=e,this.currentInterval=this.baseIntervalMs,e.errors?.includes(et)?(this.currentInterval=Yt,this.setStatus("unavailable",et)):this.setStatus("ready"),this.onSnapshot(e)}scheduleNext(){if(!this.running)return;this.timer!==void 0&&window.clearTimeout(this.timer);const e=Date.now()<this.boostUntilMs?Math.min(qr,this.currentInterval):this.currentInterval;this.timer=window.setTimeout(()=>{this.timer=void 0,this.runOnce()},e)}settleResolve(e,r){const o=this.pending.get(e);o&&(window.clearTimeout(o.timer),this.pending.delete(e),o.resolve(r))}settleReject(e,r){const o=this.pending.get(e);o&&(window.clearTimeout(o.timer),this.pending.delete(e),o.reject(r))}failAllPending(e){for(const[r,o]of this.pending.entries())window.clearTimeout(o.timer),o.reject(new Error(e)),this.pending.delete(r)}}function It(t,e){if(e!=null&&(!Number.isFinite(e)||e<0||e>4e3)){console.warn("RemoteControl: jitterBufferTargetMs must be a finite number between 0 and 4000.");return}if(!("jitterBufferTarget"in t))return;const r=e??null;try{t.jitterBufferTarget!==r&&(t.jitterBufferTarget=r)}catch(o){console.warn("RemoteControl: could not set the jitter buffer target.",o)}}const Qt=`(function(){"use strict";let e,t;self.onmessage=async({data:s})=>{s.type==="start"?(e=new AbortController,t=s.readable.pipeTo(s.writable,{signal:e.signal}).catch(o=>{e?.signal.aborted||self.postMessage({type:"error",message:String(o)})})):s.type==="stop"&&(e?.abort(),await t,self.postMessage({type:"stopped"}),self.close())}})();
|
|
2
|
+
`,Rt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Qt],{type:"text/javascript;charset=utf-8"});function Hr(t){let e;try{if(e=Rt&&(self.URL||self.webkitURL).createObjectURL(Rt),!e)throw"";const r=new Worker(e,{name:t?.name});return r.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),r}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Qt),{name:t?.name})}}function Jr(t,e,r){const{MediaStreamTrackProcessor:o,MediaStreamTrackGenerator:u}=globalThis,l=e.getVideoTracks()[0];let i,E,D,p,S=!1;const w=()=>{S||(S=!0,i?.stop(),E?.stop(),D&&(D.postMessage({type:"stop"}),p=setTimeout(()=>D?.terminate(),1e3)))},N=_=>{t.srcObject=_,t.play().catch(()=>{})},V=_=>{S||(w(),r(_),N(e))};try{if(l&&o&&u){i=l.clone();const _=new o({track:i,maxBufferSize:1}),H=new u({kind:"video"});E=H,D=new Hr,D.onmessage=({data:F})=>{F.type==="error"?V(new Error(F.message)):F.type==="stopped"&&(clearTimeout(p),D?.terminate())},D.onerror=F=>V(new Error(F.message)),D.postMessage({type:"start",readable:_.readable,writable:H.writable},[_.readable,H.writable]),N(new MediaStream(e.getTracks().map(F=>F===l?H:F)))}else N(e)}catch(_){V(_)}return w}function Fe(t){return typeof t=="number"&&Number.isFinite(t)}function Se(t,e){if(!(!Fe(t)||!Fe(e)||t<e||e<0))return t-e}class Gr{previous=new Map;reset(){this.previous.clear()}read(e,r,o){const u={timestamp:0,video:[],audio:[]};o==null?u.requestedTargetMs=null:Fe(o)&&o>=0&&o<=4e3&&(u.requestedTargetMs=o);const l=new Map;return e.forEach(i=>{if(i.type!=="inbound-rtp"||!Fe(i.timestamp))return;const E=i.kind??i.mediaType;if(E!=="video"&&E!=="audio")return;const D=r.filter(P=>P.kind===E),p=i.trackIdentifier?D.find(P=>P.trackId===i.trackIdentifier):i.mid!=null?D.find(P=>P.mid===i.mid):D.length===1?D[0]:void 0;if(!p)return;const S=this.previous.get(i.id),N=S?.trackId===p.trackId&&S.stats.ssrc===i.ssrc?S.stats:void 0,V=N?i.timestamp-N.timestamp:void 0,_={id:i.id,trackId:p.trackId,timestamp:i.timestamp};if(V!==void 0&&V>0){_.intervalMs=V;const P=Se(i.jitterBufferEmittedCount,N?.jitterBufferEmittedCount),B=Se(i.jitterBufferDelay,N?.jitterBufferDelay);P!==void 0&&P>0&&B!==void 0&&(_.bufferDelayMs=B/P*1e3);const x=Se(i.bytesReceived,N?.bytesReceived);x!==void 0&&(_.bitrateBps=x*8e3/V)}if(E==="video"){const P={..._,display:p.display??"primary"};if(_.intervalMs!==void 0){const B=Se(i.framesDecoded,N?.framesDecoded);B!==void 0&&(P.fps=B*1e3/_.intervalMs),P.droppedFrames=Se(i.framesDropped,N?.framesDropped),P.freezes=Se(i.freezeCount,N?.freezeCount)}u.video.push(P)}else u.audio.push(_);u.timestamp=Math.max(u.timestamp,i.timestamp),l.set(i.id,N&&i.timestamp<=N.timestamp?S:{stats:i,trackId:p.trackId});const H=i.transportId?e.get(i.transportId):void 0,F=H?.selectedCandidatePairId?e.get(H.selectedCandidatePairId):void 0;F?.state==="succeeded"&&Fe(F.currentRoundTripTime)&&F.currentRoundTripTime>=0&&(u.rttMs=F.currentRoundTripTime*1e3)}),this.previous=l,u.video.length||u.audio.length?u:null}}const ut=new WeakSet;function jr(t,e,r){const{peer:o,displays:u}=t,l=new Gr;let i,E=!1,D=!1,p=!1,S=0,w=!1,N=!1;const V=()=>!E&&!document.hidden&&o.connectionState==="connected",_=B=>{if(!(!B&&!w)){w=B!==null;try{e()?.(B)}catch(x){console.error('[RemoteControl] customer callback "onPlaybackStats" threw:',x)}}},H=()=>{D=!1,S++,clearTimeout(i),l.reset(),_(null)},F=async()=>{if(p||!V())return;if(ut.has(o)){i=setTimeout(()=>{F()},2e3);return}p=!0,ut.add(o);const B=S;try{const x=await o.getStats();if(B!==S||!V())return;const ce=o.getTransceivers().filter(I=>(I.currentDirection==="recvonly"||I.currentDirection==="sendrecv")&&I.receiver.track.readyState!=="ended").map(I=>({trackId:I.receiver.track.id,kind:I.receiver.track.kind,mid:I.mid,display:u.get(I.receiver)}));_(l.read(x,ce,r())),N=!1}catch(x){if(B!==S||!V())return;N||console.warn("[RemoteControl] could not read playback stats:",x),N=!0,l.reset(),_(null)}finally{p=!1,ut.delete(o),D&&V()&&(i=setTimeout(()=>{F()},B===S?2e3:0))}},P=()=>{if(!V()){H();return}D||(D=!0,F())};return document.addEventListener("visibilitychange",P),o.addEventListener("connectionstatechange",P),P(),()=>{E=!0,document.removeEventListener("visibilitychange",P),o.removeEventListener("connectionstatechange",P),H()}}function Xr(t,e){const r=t.createDataChannel("latency-trace-v1",{ordered:!0,negotiated:!0,id:2});let o=!1,u=!1,l=0;return r.onmessage=i=>{if(u)return;let E;try{E=JSON.parse(i.data)}catch(D){console.warn("Invalid latency trace message",D);return}E&&typeof E=="object"&&!Array.isArray(E)&&e(E)},r.onclose=()=>{u=!0,o=!1},{accept(i){o=!u&&i===1},wrap(i){if(!o||i.byteLength===0)return i;const E=new DataView(i),D=E.getUint8(0),p=D===Z.INJECT_MOUSE_EVENT||D===Z.INJECT_MAC_KEY||D===Z.INJECT_MAC_SCROLL,S=i.byteLength===32&&D===Z.INJECT_TOUCH_EVENT&&E.getUint8(1)<=2;if(!p&&!S)return i;const w=new ArrayBuffer(6+i.byteLength),N=new DataView(w);return N.setUint8(0,240),N.setUint8(1,1),N.setUint32(2,++l,!0),new Uint8Array(w,6).set(new Uint8Array(i)),w},close(){u=!0,o=!1,r.onmessage=null,r.onclose=null,r.close()}}}class Qr{generation=0;tail=Promise.resolve();get currentGeneration(){return this.generation}enqueue(e){const r=++this.generation;return this.append(r,e)}enqueueCurrent(e){return this.append(this.generation,e)}append(e,r){const o={generation:e,isCurrent:()=>e===this.generation},u=this.tail.then(()=>r(o));return this.tail=u.catch(()=>{}),u}invalidate(){++this.generation}}function zr(t){if(!t||typeof t!="object")return null;const e=t;if(e.type!=="cameraRequest"||typeof e.active!="boolean")return null;const r={active:e.active};return(e.facingMode==="user"||e.facingMode==="environment")&&(r.facingMode=e.facingMode),r}function Zr(t){const e={frameRate:{ideal:30,max:30}};return t?.facingMode&&(e.facingMode={ideal:t.facingMode}),e}function en(t,e){return!t||t.facingMode!==e.facingMode}function tn(t){const e=t.getSettings();return{width:e.width,height:e.height,frameRate:e.frameRate,deviceId:e.deviceId,label:t.label||void 0,facingMode:e.facingMode}}function rn(t){return{type:"cameraResult",granted:!0,camera:tn(t)}}const se=(...t)=>{window.debugRemoteControl&&console.log(...t)},y=(...t)=>{window.debugRemoteControl&&console.warn(...t)},kt=["click","keydown"],rt=new WeakMap,zt=t=>{rt.get(t)?.()},ht=(t,e)=>{if(rt.has(t)){Promise.resolve(t.play()).catch(()=>{});return}Promise.resolve(t.play()).catch(r=>{if(r?.name!=="NotAllowedError"||t.muted)return;t.muted=!0,Promise.resolve(t.play()).catch(()=>{});const o=t.ownerDocument,u=()=>{l(),t.muted=!1,ht(t,e)},l=()=>{for(const i of kt)o.removeEventListener(i,u,!0);rt.delete(t)};for(const i of kt)o.addEventListener(i,u,!0);rt.set(t,l),e()})},L=(t,e,...r)=>{if(e)try{e(...r)}catch(o){console.error(`[RemoteControl] customer callback "${t}" threw:`,o)}},Zt=t=>t.includes("/android_")?"android":t.includes("/macos_")?"macos":"ios",Ut=(t,e)=>{const r=new URL(t);return r.searchParams.set("token",e),r.toString()},ft=3,nn=1e3,on=15e3,an=3e3,sn=4e3;function Pt(){const t=crypto.getRandomValues(new Uint8Array(16));t[6]=t[6]&15|64,t[8]=t[8]&63|128;const e=Array.from(t,r=>r.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function cn(t){let e={...t};const{url:r,deviceModel:o}=e;let u=e.token;const l=e.watchOnly??!1,i=e.sessionId??Pt(),E=e.platform??Zt(r??"");let D={connection:"idle",videoReady:!1,controlReady:!1,duo:!1,duoState:null};const p=n=>{D={...D,...n},L("onStateChange",e.onStateChange,D)},S=n=>p({videoReady:n}),w=n=>p({duoState:n}),N=n=>p({duoError:n}),V=n=>p({duo:n}),_=n=>se(n);let H=null,F;const P=()=>{F?.(),F=H&&e.onPlaybackStats?jr(H,()=>e.onPlaybackStats,()=>e.jitterBufferTargetMs):void 0},B=new Map,x=new Set,ce=new Set,I=new Map;let Ee=!1;const Be=new Map,pt=(n,f,c)=>{f.stop?.(),f.stop=Jr(n,c,d=>y("Video playback fallback:",d))},Ke=new Set;let Ae=null;const mt=n=>{n.srcObject=Ae,Ae&&ht(n,()=>L("onSpeakerBlocked",e.onSpeakerBlocked))},er=()=>{Be.clear(),Ae=null;for(const n of Ke)n.srcObject=null;for(const[n,f]of B)f.clear?.(),f.stop?.(),f.stop=void 0,n.srcObject=null};let he=!1,Me=!1,xe=0,g=null,pe=null;const Ct=()=>{E!=="ios"||!pe||pe!==g||pe.readyState===WebSocket.OPEN&&pe.send(JSON.stringify({type:"speakerAudio",sessionId:i,enabled:!(e.speakerMuted??!0)}))};let R=null,W=null,We=null,me,ve,we,qe,Ce,de=0,Ve=0,re=!1,ue=null,Q=null,fe;const nt=new Qr;let Ne=null,$e=null,it=!l&&(e.microphoneEnabled??!1),ot=!1,be=null,te=null,He=0,Ot=Promise.resolve(),Oe=null,Ye=!1,ne=new Map,ee=new Map,le=new Map,ie=new Map,$=null,Ie=null,Dt=0;const Je=n=>{if(n===null&&Ie===null)return;Ie=n;const f=++Dt;queueMicrotask(()=>{f===Dt&&L("onAxSnapshotChange",e.onAxSnapshotChange,n)})};let De=null,_e=new Map;const tr=(n,f)=>new Promise((c,d)=>{if(l){d(new Error("Device is watch-only"));return}const K=g;if(!K||K.readyState!==WebSocket.OPEN){d(new Error("Simulator disconnected"));return}const m=Pt(),C=setTimeout(()=>{_e.delete(m),d(new Error("Device control timed out"))},5e3);_e.set(m,{resolve:c,reject:d,timer:C}),K.send(JSON.stringify({type:n,id:m,...f}))}),ge=n=>{De!==n&&(De=n,p({connection:n}),L("onConnectionStateChange",e.onConnectionStateChange,n))},oe=n=>{l||!W||W.readyState!=="open"||(W.send(We?.wrap(n)??n),$?.bumpActivity())},rr=()=>{g&&g.readyState===WebSocket.OPEN&&g.send(JSON.stringify({type:"keepAlive",sessionId:i}))},_t=()=>{me&&window.clearInterval(me),me=window.setInterval(rr,1e4)},Re=()=>{me&&(window.clearInterval(me),me=void 0)},Ge=()=>{ve&&(window.clearTimeout(ve),ve=void 0)},je=()=>{we&&(window.clearTimeout(we),we=void 0)},ke=()=>{qe&&(window.clearInterval(qe),qe=void 0)},Ue=()=>{Ce!==void 0&&(window.clearTimeout(Ce),Ce=void 0)},nr=()=>{Ye||(Ye=!0,ke(),S(!0),ge("connected"))},J=n=>{for(const f of n.getTracks())try{f.stop()}catch(c){y("track.stop() failed:",c)}},ir=()=>{const n=Q;n&&(Q=null,J(n))},gt=n=>{const f=Ot.then(n).catch(c=>{y("microphone operation failed:",c)});return Ot=f,f},at=()=>it||ot,Tt=n=>{const f=`ui-mic-${Date.now()}-${Math.random().toString(36).substring(2,9)}`;Oe=f,n.send(JSON.stringify({type:"microphoneStart",id:f}))},st=()=>gt(()=>or()),or=async()=>{const n=He,f=()=>n===He&&at(),c=h=>{L("onMicrophoneStateChange",e.onMicrophoneStateChange,{active:!1,error:h})};if(!f())return;const d=g,K=be;if(!d||d.readyState!==WebSocket.OPEN||!K||te)return;if(!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!="function"){console.warn("[RemoteControl] navigator.mediaDevices.getUserMedia unavailable. getUserMedia requires a secure context (https or http://localhost)."),c("Microphone capture requires a secure context (https)");return}let m=null;try{m=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}catch(h){console.warn("[RemoteControl] microphone getUserMedia denied/failed:",h)}if(!f()){m&&J(m);return}if(!m){c("Microphone permission denied or no device available");return}const C=m.getAudioTracks()[0]??null;if(!C){J(m),c("Captured stream has no audio track");return}try{await K.replaceTrack(C)}catch(h){y("replaceTrack(audioTrack) failed:",h),J(m),c("Failed to attach the microphone track to the connection");return}if(!f()){try{await K.replaceTrack(null)}catch(h){y("replaceTrack(null) on stale mic attach failed:",h)}J(m);return}te=m,C.onended=()=>{te===m&&Xe("microphone capture ended by the browser")},Tt(d),L("onMicrophoneStateChange",e.onMicrophoneStateChange,{active:!0,label:C.label||void 0})},Xe=n=>(++He,Oe=null,gt(async()=>{const f=be,c=te;if(te=null,f&&c)try{await f.replaceTrack(null)}catch(K){y("replaceTrack(null) on mic detach failed:",K)}c&&J(c);const d=g;if(c&&d&&d.readyState===WebSocket.OPEN){const K=`ui-mic-${Date.now()}-${Math.random().toString(36).substring(2,9)}`;d.send(JSON.stringify({type:"microphoneStop",id:K}))}(c||n)&&L("onMicrophoneStateChange",e.onMicrophoneStateChange,{active:!1,...n!==void 0&&{error:n}})})),yt=(n,f)=>{let c;try{c=rn(f),console.info(`[RemoteControl] camera capture: ${c.camera?.width}x${c.camera?.height} @ ${c.camera?.frameRate??"?"}fps`+(c.camera?.label?` — ${c.camera.label}`:""))}catch(d){y("getSettings() on outbound camera track failed:",d),c={type:"cameraResult",granted:!0,camera:{label:f.label||void 0}}}n.send(JSON.stringify(c)),L("onCameraDemandChange",e.onCameraDemandChange,!0,!0,c.camera)},ar=n=>{if(!n)return;const f=n.indexOf("/"),d=(f>=0?n.slice(f+1):n).toUpperCase();return d==="HEVC"?"H265":d},sr=async()=>{const n=ue,f=e.onCameraStats;if(!n||!f)return;let c;try{c=await n.getStats()}catch{return}let d,K,m;if(c.forEach(U=>{U.type==="outbound-rtp"&&U.kind==="video"?d=U:U.type==="remote-inbound-rtp"&&U.kind==="video"&&(m=U)}),d?.codecId){const U=c.get(d.codecId);U&&(K=U.mimeType)}if(!d)return;const C=d.timestamp??Date.now(),h=$e;let k,b,G;if(h&&C>h.timestamp){const U=(C-h.timestamp)/1e3;if(typeof d.framesEncoded=="number"&&typeof h.framesEncoded=="number"&&(k=Math.max(0,(d.framesEncoded-h.framesEncoded)/U)),typeof d.bytesSent=="number"&&typeof h.bytesSent=="number"&&(b=Math.max(0,(d.bytesSent-h.bytesSent)*8/U)),typeof d.packetsSent=="number"&&typeof h.packetsSent=="number"&&m&&typeof m.packetsLost=="number"&&typeof h.packetsLost=="number"){const A=d.packetsSent-h.packetsSent,ze=m.packetsLost-h.packetsLost;A>0&&(G=Math.max(0,Math.min(100,ze/A*100)))}}$e={timestamp:C,framesEncoded:d.framesEncoded,bytesSent:d.bytesSent,packetsSent:d.packetsSent,packetsLost:m?.packetsLost};const v={codec:ar(K),encoderImplementation:d.encoderImplementation,hardwareAccelerated:typeof d.powerEfficientEncoder=="boolean"?d.powerEfficientEncoder:void 0,framesPerSecond:k,framesEncoded:d.framesEncoded,bitrateBps:b,width:d.frameWidth,height:d.frameHeight,qualityLimitationReason:d.qualityLimitationReason,rttMs:typeof m?.roundTripTime=="number"?m.roundTripTime*1e3:void 0,packetsLostPct:G};L("onCameraStats",e.onCameraStats,v)},St=()=>{Ne===null&&($e=null,Ne=setInterval(()=>{sr()},1e3))},Qe=()=>{Ne!==null&&(clearInterval(Ne),Ne=null),$e=null,L("onCameraStats",e.onCameraStats,null)},cr=(n,f,c,d)=>nt.enqueue(async({isCurrent:K})=>{const m=()=>K()&&d()&&g===f&&ue===c;if(!m())return;if(!n.active){const v=Q;try{await c.replaceTrack(null)}catch(U){y("replaceTrack(null) on camera detach failed:",U)}if(Q===v&&(Q=null,fe=void 0,v&&J(v)),Qe(),!m())return;L("onCameraDemandChange",e.onCameraDemandChange,!1);return}L("onCameraDemandChange",e.onCameraDemandChange,!0);const C=Q,h=C?.getVideoTracks()[0],k=fe;if(h?.readyState==="live"&&k&&!en(k,n)){fe=n,yt(f,h),St();return}if(C){try{await c.replaceTrack(null)}catch(v){y("replaceTrack(null) before camera switch failed:",v)}if(Q===C&&(Q=null,fe=void 0,J(C)),Qe(),!m())return}if(!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!="function"){if(console.warn("[RemoteControl] navigator.mediaDevices.getUserMedia unavailable. getUserMedia requires a secure context (https or http://localhost). Replying cameraResult granted=false so limulator falls back to black frames."),!m())return;f.send(JSON.stringify({type:"cameraResult",granted:!1})),L("onCameraDemandChange",e.onCameraDemandChange,!0,!1);return}let b=null;try{b=await navigator.mediaDevices.getUserMedia({video:Zr(n),audio:!1})}catch(v){console.warn("[RemoteControl] getUserMedia denied/failed:",v)}if(!m()){b&&J(b);return}if(!b){f.send(JSON.stringify({type:"cameraResult",granted:!1})),L("onCameraDemandChange",e.onCameraDemandChange,!0,!1);return}const G=b.getVideoTracks()[0]??null;if(!G){if(J(b),!m())return;f.send(JSON.stringify({type:"cameraResult",granted:!1})),L("onCameraDemandChange",e.onCameraDemandChange,!0,!1);return}try{G.contentHint="motion"}catch{}try{await c.replaceTrack(G)}catch(v){if(y("replaceTrack(videoTrack) failed:",v),J(b),!m())return;f.send(JSON.stringify({type:"cameraResult",granted:!1})),L("onCameraDemandChange",e.onCameraDemandChange,!0,!1);return}if(!m()){try{await c.replaceTrack(null)}catch(v){y("replaceTrack(null) for stale camera attach failed:",v)}J(b);return}try{const v=c.getParameters();(!v.encodings||v.encodings.length===0)&&(v.encodings=[{}]),v.encodings[0].maxBitrate=8e6,v.encodings[0].maxFramerate=30,v.degradationPreference="maintain-framerate",await c.setParameters(v)}catch(v){y("setParameters on outbound camera failed:",v)}if(!m()){try{await c.replaceTrack(null)}catch(v){y("replaceTrack(null) for stale camera finalize failed:",v)}J(b);return}Q=b,fe=n,G.onended=()=>{Q===b&&nt.enqueueCurrent(async({isCurrent:v})=>{if(!(!v()||Q!==b||!d()||g!==f||ue!==c)){try{await c.replaceTrack(null)}catch(U){y("replaceTrack(null) after camera ended failed:",U)}!v()||Q!==b||!d()||g!==f||ue!==c||(Q=null,fe=void 0,J(b),Qe(),f.send(JSON.stringify({type:"cameraResult",granted:!1})),L("onCameraDemandChange",e.onCameraDemandChange,!0,!1))}}).catch(v=>y("camera ended cleanup failed:",v))},m()&&(yt(f,G),St())}),Te=()=>{for(const n of ce)n();ce.clear();for(const n of I.values())clearTimeout(n);I.clear();for(const n of ee.values())n(new Error("Simulator disconnected"));for(const n of ie.values())n(new Error("Simulator disconnected"));ee.clear(),ne.clear(),ie.clear(),le.clear(),F?.(),F=void 0,er(),H=null;for(const n of _e.values())clearTimeout(n.timer),n.reject(new Error("Simulator disconnected"));_e.clear(),w(null),p({controlReady:!1,videoReady:!1}),je(),Ue(),ke(),$&&($.stop(),$=null),Ie!==null&&Je(null),nt.invalidate(),Qe(),ir(),fe=void 0,ue=null,++He,ot=!1,Oe=null,te&&(J(te),te=null,L("onMicrophoneStateChange",e.onMicrophoneStateChange,{active:!1})),be=null,pe=null,g&&(g.onopen=null,g.onmessage=null,g.onerror=null,g.onclose=null,g.close(),g=null),We?.close(),We=null,R&&(R.onconnectionstatechange=null,R.oniceconnectionstatechange=null,R.ontrack=null,R.onicecandidate=null,R.close(),R=null),W&&(W.onopen=null,W.onclose=null,W.onerror=null,W.close(),W=null)},Kt=()=>{document.hidden?Re():_t()},lr=async()=>{if(e.transport)return e.transport.isTerminated?.()??!1;if(typeof navigator<"u"&&navigator.onLine===!1)return!1;let n;try{const d=new URL(r);d.protocol=d.protocol==="wss:"?"https:":d.protocol==="ws:"?"http:":d.protocol,n=Ut(d.toString(),u)}catch{return!1}const f=new AbortController,c=window.setTimeout(()=>f.abort(),sn);try{return(await fetch(n,{method:"GET",cache:"no-store",signal:f.signal})).status===404}catch{return!1}finally{window.clearTimeout(c)}},dr=()=>{he||(he=!0,de+=1,Ge(),je(),Ue(),Te(),_("Instance terminated"),Re(),ge("terminated"),L("onTerminated",e.onTerminated))},ur=()=>{if(he||Me)return;Me=!0;const n=xe;lr().catch(()=>!1).then(f=>{n===xe&&(Me=!1,f&&dr())})},ye=(n,f)=>{if(he||f!==de)return;if(ur(),re){if(e.autoReconnect===!1){_(`Connection failed after it was established: ${n}`),Re(),ge("failed"),Te();return}_(`Reconnecting after established session dropped: ${n}`),re=!1,Ve=-1}Ge();const c=Ve+1;if(c>=ft){_(`Connection failed after ${ft} attempts: ${n}`),Re(),ge("failed"),Te();return}_(`Retrying connection (${c+1}/${ft})`),ge("reconnecting"),Te(),ve=window.setTimeout(()=>{ve=void 0,f===de&&At(c)},nn)},At=async(n=0)=>{const{openUrl:f,axPollIntervalMs:c,axMaxBackoffMs:d,androidElementTreeOptions:K}=e;if(he)return;const m=de+1;de=m,Ve=n,re=!1,n===0&&De!=="reconnecting"&&ge("connecting"),Ge(),je(),ke(),Ye=!1,S(!1),Te();const C=()=>m===de;we=window.setTimeout(()=>{we=void 0,!(!C()||re)&&ye("Connection did not succeed within 15 seconds",m)},on);try{const h=e.transport?await e.transport.connect():new WebSocket(Ut(r,u));if(!C()){h.close();return}if(g=h,await new Promise((O,s)=>{let Y=!1;const q=()=>M(()=>s(new Error("Connection stopped")));ce.add(q);const T=window.setTimeout(()=>M(()=>s(new Error("WebSocket connection timeout"))),3e4),M=z=>{Y||(Y=!0,ce.delete(q),window.clearTimeout(T),z())};h.onopen=()=>{!C()||g!==h||M(O)},h.onerror=z=>{!C()||g!==h||(_("WebSocket error: "+z),M(()=>s(new Error("WebSocket connection failed"))))},h.onclose=()=>{!C()||g!==h||(_("WebSocket closed"),M(()=>s(new Error("WebSocket closed before connection was established"))))},h.readyState===WebSocket.OPEN?M(O):h.readyState!==WebSocket.CONNECTING&&M(()=>s(new Error("WebSocket is closed")))}),!C()||g!==h)return;h.onerror=O=>{!C()||g!==h||_("WebSocket error: "+O)},h.onclose=()=>{!C()||g!==h||_("WebSocket closed")};const k=new Promise((O,s)=>{let Y=!1;const q=()=>T(()=>s(new Error("Connection stopped")));ce.add(q);const T=j=>{Y||(Y=!0,ce.delete(q),window.clearTimeout(M),h.removeEventListener("message",z),j())},M=window.setTimeout(()=>T(()=>s(new Error("RTCConfiguration timeout"))),3e4),z=j=>{if(!(!C()||g!==h))try{const X=JSON.parse(j.data);if(X.type==="signalingError"&&X.requestType==="requestRtcConfiguration"&&X.sessionId===i){const pr=typeof X.error=="string"?X.error:"Unable to load streaming configuration";T(()=>s(new Error(pr)))}else X.type==="rtcConfiguration"&&T(()=>O({rtcConfiguration:X.rtcConfiguration,cameraSupported:X.cameraSupported===!0,foldSupported:X.foldSupported===!0}))}catch(X){console.error("Error handling RTC configuration:",X),T(()=>s(X))}};h.addEventListener("message",z),h.send(JSON.stringify({type:"requestRtcConfiguration",sessionId:i}))}),{rtcConfiguration:b,cameraSupported:G,foldSupported:v}=await k;if(!C()||g!==h)return;const U=o==="iphone-duo"||v;V(U);const A=new RTCPeerConnection({...b,iceTransportPolicy:"relay"});R=A;const ze={peer:A,displays:new Map};H=ze,P(),A.addTransceiver("audio",{direction:"recvonly"});const ct=E==="ios",Er=A.addTransceiver("video",{direction:"recvonly"}),hr=U?A.addTransceiver("video",{direction:"recvonly"}):null,Nt=!l&&(E==="ios"||G),lt=Nt?A.addTransceiver("video",{direction:"sendonly"}):null;if(ue=lt?.sender??null,be=(Nt?A.addTransceiver("audio",{direction:"sendonly"}):null)?.sender??null,RTCRtpReceiver.getCapabilities){const O=RTCRtpReceiver.getCapabilities("video");if(O&&O.codecs){const Y=O.codecs.sort((q,T)=>{const M=z=>{const j=z.mimeType.toLowerCase();return j.includes("h265")||j.includes("hevc")?1:j.includes("h264")||j.includes("avc")?2:3};return M(q)-M(T)});Er.setCodecPreferences(Y),hr?.setCodecPreferences(Y),se("Set codec preferences:",Y.map(q=>q.mimeType).join(", "))}}if(lt&&RTCRtpSender.getCapabilities){const O=RTCRtpSender.getCapabilities("video");if(O&&O.codecs){const s=new Set(["42e01f","42e028","640c1f"]),Y=T=>{const M=T.mimeType.toLowerCase(),j=(T.sdpFmtpLine||"").toLowerCase().match(/profile-level-id=([0-9a-f]{6})/),X=j?j[1]:"";return M==="video/h265"||M==="video/hevc"?1:M==="video/h264"&&s.has(X)?2:M==="video/h264"?3:M==="video/vp9"?4:M==="video/vp8"?5:M==="video/rtx"||M==="video/red"||M==="video/ulpfec"?0:6},q=[...O.codecs].sort((T,M)=>Y(T)-Y(M));try{lt.setCodecPreferences(q),se("Outbound camera codec preferences:",q.map(T=>`${T.mimeType}${T.sdpFmtpLine?`[${T.sdpFmtpLine}]`:""}`).join(", "))}catch(T){y("Failed to set outbound camera codec preferences:",T)}}}const ae=A.createDataChannel("control",{ordered:!0,negotiated:!0,id:1});W=ae;const dt=!l&&!U&&e.onTrace?Xr(A,O=>{C()&&R===A&&L("onTrace",e.onTrace,O)}):null;if(We=dt,ae.onopen=()=>{if(!C()||W!==ae||g!==h)return;re=!0,p({controlReady:!l}),je(),_("Control channel opened"),U&&h.send(JSON.stringify({type:"getFoldState",id:"duo-capabilities"})),!$&&E!=="macos"&&($=new $r({platform:E,baseIntervalMs:c,maxBackoffMs:d,androidElementTreeOptions:K,send:s=>{if(!g||g.readyState!==WebSocket.OPEN)return!1;try{return g.send(JSON.stringify(s)),!0}catch{return!1}},onSnapshot:Je,onStatusChange:(s,Y)=>{L("onAxStatusChange",e.onAxStatusChange,s,Y)}}),(e.inspectMode===!0||e.inspectMode==="hover-only")&&$.start());const O=()=>{!C()||Ye||W!==ae||g!==h||h.readyState!==WebSocket.OPEN||h.send(JSON.stringify({type:"requestFrame",sessionId:i}))};if(O(),ke(),qe=window.setInterval(()=>{if(!C()||Ye||W!==ae||g!==h||h.readyState!==WebSocket.OPEN){ke();return}O()},250),!l&&f){try{const s=decodeURIComponent(f);_("Opening URL"),h.send(JSON.stringify({type:"openUrl",url:s,sessionId:i}))}catch(s){console.error({error:s},"Error decoding URL, falling back to the original URL"),h.send(JSON.stringify({type:"openUrl",url:f,sessionId:i}))}$?.bumpActivity()}},ae.onclose=()=>{!C()||W!==ae||(p({controlReady:!1}),_("Control channel closed"))},ae.onerror=O=>{!C()||W!==ae||(console.error("Control channel error:",O),_("Control channel error: "+O))},A.onconnectionstatechange=()=>{!C()||R!==A||(_("Connection state: "+A.connectionState),A.connectionState==="failed"&&re&&ye("WebRTC connection entered failed state",m))},A.oniceconnectionstatechange=()=>{if(!C()||R!==A)return;const O=A.iceConnectionState;if(_("ICE state: "+O),O==="connected"||O==="completed"){Ue(),at()&&!te&&st();return}if(O==="failed"){Ue(),re&&ye("ICE connection entered failed state",m);return}O==="disconnected"&&re&&e.autoReconnect!==!1&&Ce===void 0&&(Ce=window.setTimeout(()=>{Ce=void 0,!(!C()||R!==A)&&A.iceConnectionState==="disconnected"&&ye("ICE stayed disconnected past grace period",m)},an))},A.ontrack=O=>{if(!C()||R!==A)return;It(O.receiver,e.jitterBufferTargetMs);const s=O.track.id==="duo-inner"||O.streams.some(Y=>Y.id==="duo-inner");if(O.track.kind==="video"&&ze.displays.set(O.receiver,s?"inner":"primary"),_("Received remote track: "+O.track.kind),O.track.kind==="video"){const Y=s?"inner":"primary",q=U?new MediaStream([O.track]):O.streams[0]??new MediaStream([O.track]);Be.set(Y,q);for(const[T,M]of B)M.display===Y&&pt(T,M,q)}if(O.track.kind==="audio"&&ct){Ae=new MediaStream([O.track]);for(const Y of Ke)mt(Y)}},A.onicecandidate=O=>{if(!(!C()||R!==A||g!==h))if(O.candidate&&h.readyState===WebSocket.OPEN){const s={type:"candidate",candidate:O.candidate.candidate,sdpMid:O.candidate.sdpMid,sdpMLineIndex:O.candidate.sdpMLineIndex,sessionId:i};h.send(JSON.stringify(s)),_("Sent ICE candidate")}else _("ICE candidate gathering completed")},h.onmessage=async O=>{if(!C()||g!==h)return;let s;try{s=JSON.parse(O.data)}catch(Y){y("Error parsing message:",Y);return}if(!$?.handleMessage(s))switch(_("Received: "+s.type),s.type){case"performActionsResult":case"foldStateResult":case"foldStateChanged":{if(!U)break;s.state?(w(s.state),N(void 0)):s.id==="duo-capabilities"&&N(s.error||"This instance does not support native iPhone Duo displays.");const T=_e.get(s.id);T&&(clearTimeout(T.timer),_e.delete(s.id),s.error?T.reject(new Error(s.error)):T.resolve());break}case"signalingError":{if(s.requestType!=="offer"||s.sessionId!==i)break;const T=typeof s.error=="string"?s.error:"Unable to establish the streaming connection";_("Error: "+T),ye(T,m);break}case"answer":if(!R||R!==A){_("No peer connection, skipping answer");break}if(dt?.accept(s.latencyTraceVersion),await A.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:s.sdp})),!C()||R!==A)return;_("Set remote description"),pe=h,(e.speakerMuted??!0)||Ct();break;case"candidate":if(!R||R!==A){_("No peer connection, skipping candidate");break}if(await A.addIceCandidate(new RTCIceCandidate({candidate:s.candidate,sdpMid:s.sdpMid,sdpMLineIndex:s.sdpMLineIndex})),!C()||R!==A)return;_("Added ICE candidate");break;case"screenshot":case"screenshotResult":{if(typeof s.id!="string"){y("Received invalid screenshot success message:",s);break}const T=ln(s);if(T){const j=ee.get(s.id);if(typeof j!="function"){y(`Received screenshot error for unknown or handled id: ${s.id}`);break}y(`Received screenshot error for id ${s.id}: ${T}`),j(new Error(T)),ne.delete(s.id),ee.delete(s.id),clearTimeout(I.get(s.id)),I.delete(s.id);break}const M=dn(s);if(!M){y("Received screenshot message without image data:",s);break}const z=ne.get(s.id);if(typeof z!="function"){y(`Received screenshot data for unknown or handled id: ${s.id}`);break}se(`Received screenshot data for id ${s.id}`),z(M),ne.delete(s.id),ee.delete(s.id),clearTimeout(I.get(s.id)),I.delete(s.id);break}case"screenshotError":if(typeof s.id!="string"||typeof s.message!="string"){y("Received invalid screenshot error message:",s);break}const Y=ee.get(s.id);if(typeof Y!="function"){y(`Received screenshot error for unknown or handled id: ${s.id}`);break}y(`Received screenshot error for id ${s.id}: ${s.message}`),Y(new Error(s.message)),ne.delete(s.id),ee.delete(s.id),clearTimeout(I.get(s.id)),I.delete(s.id);break;case"cameraRequest":{const T=ue;if(!T)break;const M=zr(s);if(!M){y("Received invalid cameraRequest:",s);break}console.info("[RemoteControl] cameraRequest received:",M.active,M.facingMode),await cr(M,h,T,C);break}case"microphoneRequest":{if(!be)break;const T=s.active===!0;if(ot=T,console.info("[RemoteControl] microphoneRequest received, active=",T),!T){it||await Xe();break}if(te){Tt(h);break}await st();break}case"microphoneStartResult":{if(Oe===null||s.id!==Oe)break;Oe=null,typeof s.error=="string"&&(console.warn("[RemoteControl] microphoneStart rejected by host:",s.error),Xe(s.error));break}case"terminateAppResult":if(typeof s.id!="string"){y("Received invalid terminateApp result message:",s);break}if(typeof s.error=="string"){const T=ie.get(s.id);if(typeof T!="function"){y(`Received terminateApp error for unknown or handled id: ${s.id}`);break}y(`Received terminateApp error for id ${s.id}: ${s.error}`),T(new Error(s.error)),le.delete(s.id),ie.delete(s.id),clearTimeout(I.get(s.id)),I.delete(s.id);break}const q=le.get(s.id);if(typeof q!="function"){y(`Received terminateApp result for unknown or handled id: ${s.id}`);break}se(`Received terminateApp success for id ${s.id}`),q(),le.delete(s.id),ie.delete(s.id),clearTimeout(I.get(s.id)),I.delete(s.id);break;default:y(`Received unhandled message type: ${s.type}`,s);break}},R===A){const O=await A.createOffer({offerToReceiveVideo:!0,offerToReceiveAudio:ct});if(!C()||R!==A||(await A.setLocalDescription(O),!C()||R!==A))return;C()&&g===h&&h.readyState===WebSocket.OPEN&&h.send(JSON.stringify({type:"offer",...U?{displayStreams:!0}:{},...ct?{speakerAudio:!0}:{},...dt?{latencyTraceVersion:1}:{},sdp:O.sdp,sessionId:i})),_("Sent offer")}}catch(h){if(!C()||h instanceof Error&&h.message==="Connection stopped")return;const k=h instanceof Error?h.message:String(h);_("Error: "+k),ye(k,m)}},Mt=()=>{if(Ee)throw new Error("Device stream is disposed");xe++,Me=!1,Je(null),De!=="reconnecting"&&(De=null),document.addEventListener("visibilitychange",Kt),document.hidden||_t(),he=!1,At(0)},vt=()=>{xe++,Me=!1,Re(),document.removeEventListener("visibilitychange",Kt),de+=1,Ve=0,re=!1,Ge(),Ue(),Te(),De=null,p({connection:"idle",videoReady:!1,controlReady:!1}),_("Stopped")},fr=n=>{if(Ee)throw new Error("Device stream is disposed");if(Ke.has(n))throw new Error("Audio element is already attached");Ke.add(n),Ae&&mt(n);let f=!1;const c=()=>{f||(f=!0,x.delete(c),Ke.delete(n),zt(n),n.srcObject=null)};return x.add(c),c},wt=(n,f="primary")=>{if(Ee)throw new Error("Device stream is disposed");if(B.has(n))throw new Error("Video element is already attached");const c={display:f};B.set(n,c);const d=()=>{f==="primary"&&Be.has(f)&&nr()};n.addEventListener("loadeddata",d);const K=Be.get(f);K&&pt(n,c,K);let m=!1;const C=()=>{m||(m=!0,x.delete(C),n.removeEventListener("loadeddata",d),c.stop?.(),B.delete(n),n.srcObject=null)};return x.add(C),C};return{start:Mt,stop:vt,attachVideo:wt,attachAudio:fr,attachFrameSink:(n,f="primary")=>{const c=document.createElement("video");c.muted=!0,c.playsInline=!0,c.autoplay=!0;const d=wt(c,f);let K=!1,m=0,C=0;const h=()=>{c.cancelVideoFrameCallback?.(m),cancelAnimationFrame(C)},k=()=>{K||!c.srcObject||(c.readyState>=2&&c.videoWidth>0&&L("present",(...v)=>n.present(...v),c,c.videoWidth,c.videoHeight,f),!(K||!c.srcObject)&&(c.requestVideoFrameCallback?m=c.requestVideoFrameCallback(k):C=requestAnimationFrame(k)))},b=()=>{h(),k()};B.get(c).clear=h,c.addEventListener("loadeddata",b);const G=()=>{K||(K=!0,x.delete(G),h(),c.removeEventListener("loadeddata",b),d(),c.remove())};return x.delete(d),x.add(G),c.readyState>=2&&b(),G},dispose:()=>{if(!Ee){Ee=!0,vt();for(const n of x)n();x.clear()}},getState:()=>D,updateOptions:({token:n,...f})=>{if(Ee)throw new Error("Device stream is disposed");n!==void 0&&!e.transport&&(u=n);const c=e;if(e={...e,...f},c.jitterBufferTargetMs!==e.jitterBufferTargetMs)for(const d of R?.getTransceivers()??[])(d.currentDirection==="recvonly"||d.currentDirection==="sendrecv")&&It(d.receiver,e.jitterBufferTargetMs);!!c.onPlaybackStats!=!!e.onPlaybackStats&&P(),!!c.microphoneEnabled!=!!e.microphoneEnabled&&(it=!l&&(e.microphoneEnabled??!1),at()?st():Xe()),(c.speakerMuted??!0)!==(e.speakerMuted??!0)&&Ct(),!!c.inspectMode!=!!e.inspectMode&&(e.inspectMode?$?.start():($?.stop(),Ie!==null&&Je(null)))},sendControl:oe,sendTouch:(n,f,c,d,K,m=0)=>oe(Ft(n==="begin"?0:n==="end"?1:2,m,d,K,f,c,n==="end"?0:1)),sendText:n=>oe(Bt(n)),sendDisplayTouch:(n,f,c,d)=>oe(Vt(n,f,c,d)),sendDuoControl:tr,pressButton:n=>{const f={home:3,back:4,recents:187,power:26}[n];oe(Ze(0,f,0,0)),oe(Ze(1,f,0,0))},rotate:()=>oe(new Uint8Array([11]).buffer),bumpActivity:()=>$?.bumpActivity(),getAxStatus:()=>$?.getStatus()??"idle",openUrl:n=>{if(!l){if(!g||g.readyState!==WebSocket.OPEN){y("WebSocket not open, cannot send open_url command.");return}try{const f=decodeURIComponent(n);_("Opening URL"),g.send(JSON.stringify({type:"openUrl",url:f,sessionId:i}))}catch(f){y("Error decoding or sending URL :",{error:f,url:n}),g.send(JSON.stringify({type:"openUrl",url:n,sessionId:i}))}$?.bumpActivity()}},sendKeyEvent:n=>{if(!W||W.readyState!=="open"){y("Data channel not ready for imperative key command:",W?.readyState);return}if(E==="macos"){const m=Et(n.code);if(m===void 0){y(`Unknown event.code for imperative command: ${n.code}`);return}const C=[[n.metaKey,"Meta"],[n.ctrlKey,"Control"],[n.altKey,"Alt"],[n.shiftKey,"Shift"]].filter(([k,b])=>k&&!n.code.startsWith(b)).map(([,k])=>Et(`${k}Left`)),h=(k,b)=>oe(xt(k,b));if(n.type==="keydown"){for(const k of C)h(Pe.DOWN,k);h(Pe.DOWN,m)}else{h(Pe.UP,m);for(const k of[...C].reverse())h(Pe.UP,k)}return}const f=Lt[n.code];if(!f){y(`Unknown event.code for imperative command: ${n.code}`);return}let c=a.META_NONE;n.shiftKey&&(c|=a.META_SHIFT_ON),n.altKey&&(c|=a.META_ALT_ON),n.ctrlKey&&(c|=a.META_CTRL_ON),n.metaKey&&(c|=a.META_META_ON);const d=n.type==="keydown"?a.ACTION_DOWN:a.ACTION_UP;se(`Sending Imperative Key Command: code=${n.code}, keycode=${f}, action=${d}, meta=${c}`);const K=Ze(d,f,0,c);K&&oe(K)},screenshot:n=>new Promise((f,c)=>{if(!g||g.readyState!==WebSocket.OPEN)return y("WebSocket not open, cannot send screenshot command."),c(new Error("WebSocket is not connected or connection is not open."));const d=`ui-ss-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,K={type:n?"screenshotDisplay":"screenshot",...n?{display:n}:{},id:d};ne.set(d,f),ee.set(d,c),se("Sending screenshot request:",K);try{g.send(JSON.stringify(K))}catch(m){y("Failed to send screenshot request immediately:",m),ne.delete(d),ee.delete(d),c(m);return}I.set(d,setTimeout(()=>{I.delete(d),ne.has(d)&&(y(`Screenshot request timed out for id ${d}`),ee.get(d)?.(new Error("Screenshot request timed out")),ne.delete(d),ee.delete(d))},3e4))}),terminateApp:n=>l?Promise.reject(new Error("Device is watch-only")):new Promise((f,c)=>{if(!g||g.readyState!==WebSocket.OPEN)return y("WebSocket not open, cannot send terminateApp command."),c(new Error("WebSocket is not connected or connection is not open."));const d=`ui-term-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,K={type:"terminateApp",id:d,bundleId:n};le.set(d,f),ie.set(d,c),se("Sending terminateApp request:",K);try{g.send(JSON.stringify(K))}catch(m){y("Failed to send terminateApp request immediately:",m),le.delete(d),ie.delete(d),c(m);return}$?.bumpActivity(),I.set(d,setTimeout(()=>{I.delete(d),le.has(d)&&(y(`terminateApp request timed out for id ${d}`),ie.get(d)?.(new Error("terminateApp request timed out")),le.delete(d),ie.delete(d))},3e4))}),reconnect:()=>Mt(),refreshAxTree:async()=>{const n=$;if(!n)throw new Error("Inspect mode is not active");return n.refresh()},getAxSnapshot:()=>Ie}}const ln=t=>typeof t.message=="string"?t.message:typeof t.error=="string"?t.error:null,dn=t=>typeof t.dataUri=="string"?{dataUri:t.dataUri}:typeof t.base64=="string"?t.base64.startsWith("data:")?{dataUri:t.base64}:{dataUri:`data:${t.base64.startsWith("/9j/")?"image/jpeg":"image/png"};base64,${t.base64}`}:null;exports.AMOTION_EVENT=Le;exports.ANDROID_KEYS=a;exports.AX_UNAVAILABLE_ERROR=et;exports.CONTROL_MSG_TYPE=Z;exports.DUO_BUTTONS=Mr;exports.DUO_DIMENSIONS=Tr;exports.DuoButtonSender=vr;exports.DuoTouchController=gr;exports.HingeSender=Ar;exports.MAC_INPUT_ACTION=Pe;exports.axElementAtPoint=Ur;exports.axElementRoleLabel=Xt;exports.axElementSelectorExpression=Pr;exports.axElementSummary=Lr;exports.axElementsEqual=Gt;exports.axSnapshotsEqual=jt;exports.cancelSpeakerRetry=zt;exports.clampAxFrameForScreen=kr;exports.codeMap=Lt;exports.createDeviceStream=cn;exports.createDisplayTouchMessage=Vt;exports.createInjectKeycodeMessage=Ze;exports.createMacKeyMessage=xt;exports.createMacScrollMessage=Dr;exports.createMouseControlMessage=Or;exports.createSetClipboardMessage=Bt;exports.createTouchControlMessage=Ft;exports.createTwoFingerTouchControlMessage=Cr;exports.debugLog=se;exports.debugWarn=y;exports.detectPlatform=Zt;exports.duoDisplayTurns=Wt;exports.duoPointerMode=Kr;exports.flatDisplayTouch=qt;exports.getDuoDisplay=_r;exports.macKeyCodeFor=Et;exports.normalizeAndroidTree=Jt;exports.normalizeIosTree=Ht;exports.panelTouch=Sr;exports.playSpeaker=ht;exports.safeInvoke=L;
|
package/dist/core.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core-_qwksEry.js");exports.AMOTION_EVENT=e.AMOTION_EVENT;exports.ANDROID_KEYS=e.ANDROID_KEYS;exports.AX_UNAVAILABLE_ERROR=e.AX_UNAVAILABLE_ERROR;exports.CONTROL_MSG_TYPE=e.CONTROL_MSG_TYPE;exports.DuoTouchController=e.DuoTouchController;exports.HingeSender=e.HingeSender;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.createDeviceStream=e.createDeviceStream;exports.createDisplayTouchMessage=e.createDisplayTouchMessage;exports.createInjectKeycodeMessage=e.createInjectKeycodeMessage;exports.createSetClipboardMessage=e.createSetClipboardMessage;exports.createTouchControlMessage=e.createTouchControlMessage;exports.createTwoFingerTouchControlMessage=e.createTwoFingerTouchControlMessage;exports.duoDisplayTurns=e.duoDisplayTurns;exports.flatDisplayTouch=e.flatDisplayTouch;exports.getDuoDisplay=e.getDuoDisplay;exports.normalizeAndroidTree=e.normalizeAndroidTree;exports.normalizeIosTree=e.normalizeIosTree;exports.panelTouch=e.panelTouch;
|
package/dist/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { J as s, F as o, A as r, L as t, h as l, H as n, a as c, b as i, c as E, d as T, e as u, f as m, v as p, N as A, E as g, C as D, G as S, K as h, j as x, O as d, i as M, n as O, g as y, p as C } from "./core-BPDihn1M.mjs";
|
|
2
2
|
export {
|
|
3
3
|
s as AMOTION_EVENT,
|
|
4
4
|
o as ANDROID_KEYS,
|
|
@@ -21,7 +21,7 @@ export {
|
|
|
21
21
|
x as duoDisplayTurns,
|
|
22
22
|
d as flatDisplayTouch,
|
|
23
23
|
M as getDuoDisplay,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
O as normalizeAndroidTree,
|
|
25
|
+
y as normalizeIosTree,
|
|
26
|
+
C as panelTouch
|
|
27
27
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("react/jsx-runtime"),K=require("react"),e=require("./model-source-D3_k9qRK.js"),Ge=require("./BufferGeometryUtils-CMbyl1DL.js"),fe=require("./core-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("react/jsx-runtime"),K=require("react"),e=require("./model-source-D3_k9qRK.js"),Ge=require("./BufferGeometryUtils-CMbyl1DL.js"),fe=require("./core-_qwksEry.js"),Pe=require("./duo-view-CKlDgO_u.js"),Ee=new e.Vector3;function oe(m,v,g,a,w,r){const p=2*Math.PI*w/4,I=Math.max(r-2*w,0),k=Math.PI/4;Ee.copy(v),Ee[a]=0,Ee.normalize();const i=.5*p/(p+I),L=1-Ee.angleTo(m)/k;return Math.sign(Ee[g])===1?L*i:I/(p+I)+i+i*(1-L)}class Xe extends e.BoxGeometry{constructor(v=1,g=1,a=1,w=2,r=.1){const p=w*2+1;if(r=Math.min(v/2,g/2,a/2,r),super(1,1,1,p,p,p),this.type="RoundedBoxGeometry",this.parameters={width:v,height:g,depth:a,segments:w,radius:r},p===1)return;const I=this.toNonIndexed();this.index=null,this.attributes.position=I.attributes.position,this.attributes.normal=I.attributes.normal,this.attributes.uv=I.attributes.uv;const k=new e.Vector3,i=new e.Vector3,L=new e.Vector3(v,g,a).divideScalar(2).subScalar(r),E=this.attributes.position.array,F=this.attributes.normal.array,B=this.attributes.uv.array,j=E.length/6,x=new e.Vector3,J=.5/p;for(let P=0,T=0;P<E.length;P+=3,T+=2)switch(k.fromArray(E,P),i.copy(k),i.x-=Math.sign(i.x)*J,i.y-=Math.sign(i.y)*J,i.z-=Math.sign(i.z)*J,i.normalize(),E[P+0]=L.x*Math.sign(k.x)+i.x*r,E[P+1]=L.y*Math.sign(k.y)+i.y*r,E[P+2]=L.z*Math.sign(k.z)+i.z*r,F[P+0]=i.x,F[P+1]=i.y,F[P+2]=i.z,Math.floor(P/j)){case 0:x.set(1,0,0),B[T+0]=oe(x,i,"z","y",r,a),B[T+1]=1-oe(x,i,"y","z",r,g);break;case 1:x.set(-1,0,0),B[T+0]=1-oe(x,i,"z","y",r,a),B[T+1]=1-oe(x,i,"y","z",r,g);break;case 2:x.set(0,1,0),B[T+0]=1-oe(x,i,"x","z",r,v),B[T+1]=oe(x,i,"z","x",r,a);break;case 3:x.set(0,-1,0),B[T+0]=1-oe(x,i,"x","z",r,v),B[T+1]=1-oe(x,i,"z","x",r,a);break;case 4:x.set(0,0,1),B[T+0]=1-oe(x,i,"x","y",r,v),B[T+1]=1-oe(x,i,"y","x",r,g);break;case 5:x.set(0,0,-1),B[T+0]=oe(x,i,"x","y",r,v),B[T+1]=1-oe(x,i,"y","x",r,g);break}}static fromJSON(v){return new Xe(v.width,v.height,v.depth,v.segments,v.radius)}}const{width:We,height:$,depth:z}=fe.DUO_DIMENSIONS,V=We/2,ve=(11.3-z*2)/2,xe=157.5,Re=110.8,ge=1.1,Ce=.14;function je(m,v){m.envMap=v??null,m.envMapIntensity=1,m.onBeforeCompile=g=>{g.vertexShader=`varying vec3 vDuoStudioPosition;
|
|
2
2
|
${g.vertexShader}`.replace("#include <worldpos_vertex>",`#include <worldpos_vertex>
|
|
3
3
|
vDuoStudioPosition = (modelMatrix * vec4(transformed, 1.0)).xyz;`),g.fragmentShader=`
|
|
4
4
|
varying vec3 vDuoStudioPosition;
|
|
@@ -2,8 +2,8 @@ import { jsxs as Rt, jsx as pt } from "react/jsx-runtime";
|
|
|
2
2
|
import { useRef as ut, useState as oe, useEffect as Zt } from "react";
|
|
3
3
|
import { ah as ae, d as K, G as Pt, f as Xt, M as jt, e as Yt, D as ce, ai as le, aj as _t, ak as qt, B as Jt, j as Ft, al as Qt, i as wt, l as ue, b as bt, T as de, g as $t, am as fe, an as pe, ao as ge, ap as he, h as ne, u as me, a4 as ye, c as be, V as te, S as ve, L as ee, R as xe } from "./model-source-CN_i4mVy.mjs";
|
|
4
4
|
import { a as we } from "./BufferGeometryUtils-DEy5W2hb.mjs";
|
|
5
|
-
import { D as Me, k as Se, l as Ut, m as De, p as Be } from "./core-
|
|
6
|
-
import { h as ke, u as Ie, D as Ae, a as Ee, f as ze } from "./duo-view-
|
|
5
|
+
import { D as Me, k as Se, l as Ut, m as De, p as Be } from "./core-BPDihn1M.mjs";
|
|
6
|
+
import { h as ke, u as Ie, D as Ae, a as Ee, f as ze } from "./duo-view-B2i1POpD.mjs";
|
|
7
7
|
const zt = new K();
|
|
8
8
|
function et(h, b, g, i, w, n) {
|
|
9
9
|
const f = 2 * Math.PI * w / 4, k = Math.max(n - 2 * w, 0), B = Math.PI / 4;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as o, jsxs as x, Fragment as R } from "react/jsx-runtime";
|
|
2
2
|
import ot, { useId as J, useState as S, useRef as M, useEffect as T, useCallback as at, useLayoutEffect as it, Suspense as st, lazy as ct } from "react";
|
|
3
|
-
import { u as dt, D as ut } from "./remote-control-
|
|
4
|
-
import { H as lt, D as A, h as ht, i as ft, j as mt, k as pt, l as j } from "./core-
|
|
3
|
+
import { u as dt, D as ut } from "./remote-control-DmPKov-i.mjs";
|
|
4
|
+
import { H as lt, D as A, h as ht, i as ft, j as mt, k as pt, l as j } from "./core-BPDihn1M.mjs";
|
|
5
5
|
function gt(t, n, r) {
|
|
6
6
|
const [s, i] = S(t), a = M({ nativeAngle: t, send: n, failed: r });
|
|
7
7
|
a.current = { nativeAngle: t, send: n, failed: r };
|
|
@@ -419,7 +419,7 @@ function kt({ motion: t, onFinish: n }) {
|
|
|
419
419
|
)
|
|
420
420
|
] });
|
|
421
421
|
}
|
|
422
|
-
const Pt = ct(() => import("./duo-frame-
|
|
422
|
+
const Pt = ct(() => import("./duo-frame-s8ZpiZc-.mjs"));
|
|
423
423
|
function Ft(t) {
|
|
424
424
|
const n = dt();
|
|
425
425
|
return /* @__PURE__ */ x("div", { className: "rc-duo-view", children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("react/jsx-runtime"),u=require("react"),X=require("./remote-control-CEVcOPQZ.js"),R=require("./core-BCBQrYsk.js");function $(e,o,n){const[a,i]=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 R.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)),i(s.current.nativeAngle)}),()=>d.current?.stop()),[]),u.useEffect(()=>{!x.current&&l.current===void 0&&i(e)},[e]),{angle:a,changeAngle:h=>{s.current.failed(void 0),l.current=h,i(h),d.current?.set(h)},interacting:x}}function G({angle:e,watchOnly:o=!1,changeAngle:n,interacting:a,rotate:i,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?.(),a.current=!0,h.currentTarget.setPointerCapture(h.pointerId)},onPointerUp:()=>{a.current=!1},onPointerCancel:()=>{a.current=!1},onLostPointerCapture:()=>{a.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:i,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 A({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,a,i,s){return"M"+(e+i)+","+o+"H"+(e+n-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+a-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+i)+"a"+i+","+i+" 0 0 1 "+-i+","+-i+"V"+(o+i)+"a"+i+","+i+" 0 0 1 "+i+","+-i+"Z"}function Z({inner:e,width:o,height:n}){const a=u.useId().replace(/:/g,""),i=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:a+"-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:a+"-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(#"+a+"-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,i,s),fill:"url(#"+a+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),r.jsx("path",{d:B(.48,.48,o-.96,n-.96,Math.max(.5,i-.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(#"+a+"-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 oe(e,o,n,a){const i=R.DUO_DIMENSIONS.width/(e?1:2),s=R.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:i),(a-120)/(d%2?i:s))),h=(y,m)=>{y=(y-i/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+a/2}},E=(d%2?s:i)*f,D=(d%2?i:s)*f,k={min:{x:(n-E)/2,y:(a-D)/2},max:{x:(n+E)/2,y:(a+D)/2}},p=[{button:"volumeDown",x:i-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:i-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:i+.35,y:s/2-21,width:.7,height:13,edge:"right"}],v=["top","right","bottom","left"],b=p.map(y=>{const m=v[(v.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}}),j=b.filter(y=>y.button!=="side"),g=d%2?"y":"x";j.sort((y,m)=>y[g]-m[g]);const S=d%2?"targetY":"targetX";if(j[1][g]-j[0][g]<44){const y=(j[0][g]+j[1][g])/2;j[0][S]=y-22,j[1][S]=y+22}return{bodyWidth:i,bodyHeight:s,screenWidth:l,screenHeight:x,scale:f,turns:d,buttons:p,guides:b,rect:k,iconSize:Math.min(J(k),12*f)}}function J(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function Q(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(([,i,s,l,x])=>i>=-7&&i<=52&&s>=l-12&&s<=x+12).sort((i,s)=>Math.abs(i[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 a=n.getContext("2d");return a?(n.width=Math.round(e.videoWidth*o),n.height=Math.round(e.videoHeight*o),a.drawImage(e,0,0,n.width,n.height),n):void 0}catch{return}}function se(e,o){let n=!1,a;const i=f=>{n||(d(),o(f))},s=()=>{if(n)return;const f=V(e);f&&i(f)},l=()=>{a=void 0,s(),n||(a=e?.requestVideoFrameCallback?.(l))},x=setTimeout(()=>i(void 0),2500);a=e?.requestVideoFrameCallback?.(l),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function d(){n=!0,clearTimeout(x),a!==void 0&&e?.cancelVideoFrameCallback(a),e?.removeEventListener("loadeddata",s)}return d}function ie(e,o,n,a,i=!0){const s=u.useRef(void 0),l=u.useRef(a),x=u.useRef({inner:o,frame:n});x.current={inner:o,frame:n};const[d,f]=u.useState(),h=u.useRef(void 0),E=u.useRef(void 0),D=u.useCallback(()=>{clearTimeout(E.current),h.current=void 0,f(void 0)},[]),k=p=>{if(!i||p===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||h.current)return;const v=V(e.current);if(!v)return;const b=x.current;h.current={from:b,to:b,before:v,ready:!1},f(h.current),E.current=setTimeout(D,5e3)};return u.useEffect(()=>()=>clearTimeout(E.current),[]),u.useLayoutEffect(()=>{const p=s.current,v={inner:o,frame:n};s.current=v;const b=l.current!==a;if(l.current=a,!p)return;const j=Math.abs(p.frame.rect.min.x+p.frame.rect.max.x-n.rect.min.x-n.rect.max.x)>.5||Math.abs(p.frame.rect.min.y+p.frame.rect.max.y-n.rect.min.y-n.rect.max.y)>.5;if(!i||j||b){D();return}if(p.inner===o||(f(void 0),!p.frame.scale||!n.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const g=h.current?.before??V(e.current),S=h.current?.from??p;clearTimeout(E.current),h.current=void 0,g&&f({from:S,to:v,before:g,ready:!1})},[o,n.scale,n.turns,n.rect.min.x,n.rect.min.y,a,i]),u.useEffect(()=>{if(!d||d.from.inner===o)return;const p=se(e.current,j=>{j?f(g=>g&&{...g,to:x.current,after:j,ready:!0}):D()}),v=window.matchMedia?.("(prefers-reduced-motion: reduce)"),b=()=>{v?.matches&&f(void 0)};return v?.addEventListener("change",b),()=>{p(),v?.removeEventListener("change",b)}},[d?.from,o]),{motion:d,finish:D,prepare:k}}function ae({pose:e,image:o,scale:n}){const{bodyWidth:a,bodyHeight:i,screenWidth:s,screenHeight:l}=e.frame,x=s*n,d=l*n;return r.jsxs("div",{className:"rc-duo-fold-still",style:{width:a*n,height:i*n},children:[r.jsx(Z,{inner:e.inner,width:a,height:i}),r.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:d,left:(a-s)*n/2,top:(i-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 ce({motion:e,onFinish:o}){const n=u.useRef(null),[a,i]=u.useState(!1);return u.useEffect(()=>{if(i(!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),i(!0))}).catch(()=>{s||o()}),()=>{s=!0,l?.()}},[e.ready,e.from,o]),r.jsxs(r.Fragment,{children:[!a&&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:a?"visible":"hidden"}})]})}const ue=u.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-Bm0hprn9.js")));function de(e){const o=X.useDeviceView();return r.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o.mode==="3d"?r.jsx(u.Suspense,{fallback:r.jsx(Y,{...e}),children:r.jsx(ue,{...e,onReady:o.onReady})}):r.jsx(Y,{...e}),e.showFrame!==!1&&r.jsx(X.DeviceModeToggle,{view:o,label:"Device rendering"})]})}function Y(e){const o=e.showFrame!==!1,n=u.useRef(null),a=u.useRef(null),i=u.useRef(e);i.current=e;const[s,l]=u.useState({width:0,height:0}),[x,d]=u.useState(),[f,h]=u.useState(),[E,D]=u.useState(),[k,p]=u.useState(),v=u.useRef(void 0),b=u.useRef(null);b.current||(b.current=new R.DuoTouchController((...t)=>i.current.touch(...t)));const j=u.useRef(null),g=R.getDuoDisplay(e.state),S=g?.id==="inner"?e.inner:e.outer,y=R.duoDisplayTurns(g?.orientation),m=g?.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=oe(m,H,s.width,s.height),W=o?w.screenWidth:(m?g?.height:g?.width)??1,I=o?w.screenHeight:(m?g?.width:g?.height)??1,P=o?w.bodyWidth:W,T=o?w.bodyHeight:I,M=o?w.scale:Math.max(0,Math.min(s.width/(w.turns%2?T:P),s.height/(w.turns%2?P:T))),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=a.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:N,finish:_,prepare:ee}=ie(a,m,w,e.state.orientation,o),{angle:te,changeAngle:re,interacting:ne}=$(e.state.angleDegrees,async t=>{ee(t>=90);try{await e.setAngle(t)}catch(c){throw _(),c}},d),F=()=>{b.current?.release(),v.current=void 0};u.useEffect(()=>{j.current=new R.DuoButtonSender((c,z)=>i.current.button(c,z),c=>d(String(c)));const t=()=>{F(),j.current?.release(),p(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),u.useEffect(()=>{b.current?.setDisplay(g,H),b.current?.active||(v.current=void 0)},[g,H]);const O=()=>{j.current?.release(),p(void 0)},q=t=>({disabled:e.watchOnly,onPointerDown:c=>{e.watchOnly||N||c.button!==0||(c.currentTarget.setPointerCapture(c.pointerId),j.current?.press(t),p(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=>{N||(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.repeat||(j.current?.press(t),p(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":!!N,"aria-busy":!!N,onPointerMove:t=>{if(!o)return;const c=t.currentTarget.getBoundingClientRect();h(Q(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:P*M,height:T*M,transform:"translate(-50%, -50%) rotate("+w.turns*90+"deg)"},children:[o&&r.jsx(Z,{inner:m,width:P,height:T}),r.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(P-W)/2*M,top:(T-I)/2*M,borderRadius:o?m?5.3*M:[.8,6.6,6.6,.8].map(t=>t*M+"px").join(" "):0},onKeyDown:N?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(e.watchOnly||N||v.current!==void 0||t.button!==0||!g)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const c=K(t);v.current=t.pointerId,b.current?.touch("begin",c.x,c.y)},onPointerMove:t=>{if(v.current!==t.pointerId)return;const c=K(t);b.current?.touch("move",c.x,c.y)},onPointerUp:t=>{v.current===t.pointerId&&F()},onPointerCancel:F,onLostPointerCapture:F,children:r.jsx("video",{ref:a,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":E===t.button,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button]+" physical button",title:R.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":R.DUO_BUTTONS[t.button],title:R.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(A,{button:t.button})},t.button)),N&&r.jsx(ce,{motion:N,onFinish:_})]}),o&&r.jsx(G,{watchOnly:e.watchOnly,angle:te,changeAngle:re,interacting:ne,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 le=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=G;exports.DuoHardwareIcon=A;exports.duoView=le;exports.flatHoverEdge=Q;exports.hardwareIconSize=J;exports.useDuoHinge=$;
|
|
1
|
+
"use strict";const r=require("react/jsx-runtime"),u=require("react"),X=require("./remote-control-y8mgo_2E.js"),R=require("./core-_qwksEry.js");function $(e,o,n){const[a,i]=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 R.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)),i(s.current.nativeAngle)}),()=>d.current?.stop()),[]),u.useEffect(()=>{!x.current&&l.current===void 0&&i(e)},[e]),{angle:a,changeAngle:h=>{s.current.failed(void 0),l.current=h,i(h),d.current?.set(h)},interacting:x}}function G({angle:e,watchOnly:o=!1,changeAngle:n,interacting:a,rotate:i,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?.(),a.current=!0,h.currentTarget.setPointerCapture(h.pointerId)},onPointerUp:()=>{a.current=!1},onPointerCancel:()=>{a.current=!1},onLostPointerCapture:()=>{a.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:i,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 A({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,a,i,s){return"M"+(e+i)+","+o+"H"+(e+n-s)+"a"+s+","+s+" 0 0 1 "+s+","+s+"V"+(o+a-s)+"a"+s+","+s+" 0 0 1 "+-s+","+s+"H"+(e+i)+"a"+i+","+i+" 0 0 1 "+-i+","+-i+"V"+(o+i)+"a"+i+","+i+" 0 0 1 "+i+","+-i+"Z"}function Z({inner:e,width:o,height:n}){const a=u.useId().replace(/:/g,""),i=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:a+"-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:a+"-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(#"+a+"-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,i,s),fill:"url(#"+a+"-silver)",stroke:"#696f72",strokeWidth:"0.24"}),r.jsx("path",{d:B(.48,.48,o-.96,n-.96,Math.max(.5,i-.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(#"+a+"-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 oe(e,o,n,a){const i=R.DUO_DIMENSIONS.width/(e?1:2),s=R.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:i),(a-120)/(d%2?i:s))),h=(y,m)=>{y=(y-i/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+a/2}},E=(d%2?s:i)*f,D=(d%2?i:s)*f,k={min:{x:(n-E)/2,y:(a-D)/2},max:{x:(n+E)/2,y:(a+D)/2}},p=[{button:"volumeDown",x:i-37,y:-.32,width:9.5,height:.65,edge:"top"},{button:"volumeUp",x:i-25,y:-.32,width:9.5,height:.65,edge:"top"},{button:"side",x:i+.35,y:s/2-21,width:.7,height:13,edge:"right"}],v=["top","right","bottom","left"],b=p.map(y=>{const m=v[(v.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}}),j=b.filter(y=>y.button!=="side"),g=d%2?"y":"x";j.sort((y,m)=>y[g]-m[g]);const S=d%2?"targetY":"targetX";if(j[1][g]-j[0][g]<44){const y=(j[0][g]+j[1][g])/2;j[0][S]=y-22,j[1][S]=y+22}return{bodyWidth:i,bodyHeight:s,screenWidth:l,screenHeight:x,scale:f,turns:d,buttons:p,guides:b,rect:k,iconSize:Math.min(J(k),12*f)}}function J(e){return Math.max(12,Math.min(24,Math.max(e.max.x-e.min.x,e.max.y-e.min.y)/24))}function Q(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(([,i,s,l,x])=>i>=-7&&i<=52&&s>=l-12&&s<=x+12).sort((i,s)=>Math.abs(i[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 a=n.getContext("2d");return a?(n.width=Math.round(e.videoWidth*o),n.height=Math.round(e.videoHeight*o),a.drawImage(e,0,0,n.width,n.height),n):void 0}catch{return}}function se(e,o){let n=!1,a;const i=f=>{n||(d(),o(f))},s=()=>{if(n)return;const f=V(e);f&&i(f)},l=()=>{a=void 0,s(),n||(a=e?.requestVideoFrameCallback?.(l))},x=setTimeout(()=>i(void 0),2500);a=e?.requestVideoFrameCallback?.(l),e?.addEventListener("loadeddata",s),!e?.requestVideoFrameCallback&&e&&e.readyState>=2&&s();function d(){n=!0,clearTimeout(x),a!==void 0&&e?.cancelVideoFrameCallback(a),e?.removeEventListener("loadeddata",s)}return d}function ie(e,o,n,a,i=!0){const s=u.useRef(void 0),l=u.useRef(a),x=u.useRef({inner:o,frame:n});x.current={inner:o,frame:n};const[d,f]=u.useState(),h=u.useRef(void 0),E=u.useRef(void 0),D=u.useCallback(()=>{clearTimeout(E.current),h.current=void 0,f(void 0)},[]),k=p=>{if(!i||p===o){D();return}if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||h.current)return;const v=V(e.current);if(!v)return;const b=x.current;h.current={from:b,to:b,before:v,ready:!1},f(h.current),E.current=setTimeout(D,5e3)};return u.useEffect(()=>()=>clearTimeout(E.current),[]),u.useLayoutEffect(()=>{const p=s.current,v={inner:o,frame:n};s.current=v;const b=l.current!==a;if(l.current=a,!p)return;const j=Math.abs(p.frame.rect.min.x+p.frame.rect.max.x-n.rect.min.x-n.rect.max.x)>.5||Math.abs(p.frame.rect.min.y+p.frame.rect.max.y-n.rect.min.y-n.rect.max.y)>.5;if(!i||j||b){D();return}if(p.inner===o||(f(void 0),!p.frame.scale||!n.scale)||window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;const g=h.current?.before??V(e.current),S=h.current?.from??p;clearTimeout(E.current),h.current=void 0,g&&f({from:S,to:v,before:g,ready:!1})},[o,n.scale,n.turns,n.rect.min.x,n.rect.min.y,a,i]),u.useEffect(()=>{if(!d||d.from.inner===o)return;const p=se(e.current,j=>{j?f(g=>g&&{...g,to:x.current,after:j,ready:!0}):D()}),v=window.matchMedia?.("(prefers-reduced-motion: reduce)"),b=()=>{v?.matches&&f(void 0)};return v?.addEventListener("change",b),()=>{p(),v?.removeEventListener("change",b)}},[d?.from,o]),{motion:d,finish:D,prepare:k}}function ae({pose:e,image:o,scale:n}){const{bodyWidth:a,bodyHeight:i,screenWidth:s,screenHeight:l}=e.frame,x=s*n,d=l*n;return r.jsxs("div",{className:"rc-duo-fold-still",style:{width:a*n,height:i*n},children:[r.jsx(Z,{inner:e.inner,width:a,height:i}),r.jsx("div",{className:"rc-duo-flat-screen",style:{width:x,height:d,left:(a-s)*n/2,top:(i-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 ce({motion:e,onFinish:o}){const n=u.useRef(null),[a,i]=u.useState(!1);return u.useEffect(()=>{if(i(!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),i(!0))}).catch(()=>{s||o()}),()=>{s=!0,l?.()}},[e.ready,e.from,o]),r.jsxs(r.Fragment,{children:[!a&&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:a?"visible":"hidden"}})]})}const ue=u.lazy(()=>Promise.resolve().then(()=>require("./duo-frame-d3lnF2F7.js")));function de(e){const o=X.useDeviceView();return r.jsxs("div",{className:"rc-duo-view",children:[e.showFrame!==!1&&o.mode==="3d"?r.jsx(u.Suspense,{fallback:r.jsx(Y,{...e}),children:r.jsx(ue,{...e,onReady:o.onReady})}):r.jsx(Y,{...e}),e.showFrame!==!1&&r.jsx(X.DeviceModeToggle,{view:o,label:"Device rendering"})]})}function Y(e){const o=e.showFrame!==!1,n=u.useRef(null),a=u.useRef(null),i=u.useRef(e);i.current=e;const[s,l]=u.useState({width:0,height:0}),[x,d]=u.useState(),[f,h]=u.useState(),[E,D]=u.useState(),[k,p]=u.useState(),v=u.useRef(void 0),b=u.useRef(null);b.current||(b.current=new R.DuoTouchController((...t)=>i.current.touch(...t)));const j=u.useRef(null),g=R.getDuoDisplay(e.state),S=g?.id==="inner"?e.inner:e.outer,y=R.duoDisplayTurns(g?.orientation),m=g?.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=oe(m,H,s.width,s.height),W=o?w.screenWidth:(m?g?.height:g?.width)??1,I=o?w.screenHeight:(m?g?.width:g?.height)??1,P=o?w.bodyWidth:W,T=o?w.bodyHeight:I,M=o?w.scale:Math.max(0,Math.min(s.width/(w.turns%2?T:P),s.height/(w.turns%2?P:T))),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=a.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:N,finish:_,prepare:ee}=ie(a,m,w,e.state.orientation,o),{angle:te,changeAngle:re,interacting:ne}=$(e.state.angleDegrees,async t=>{ee(t>=90);try{await e.setAngle(t)}catch(c){throw _(),c}},d),F=()=>{b.current?.release(),v.current=void 0};u.useEffect(()=>{j.current=new R.DuoButtonSender((c,z)=>i.current.button(c,z),c=>d(String(c)));const t=()=>{F(),j.current?.release(),p(void 0)};return window.addEventListener("blur",t),()=>{t(),window.removeEventListener("blur",t)}},[]),u.useEffect(()=>{b.current?.setDisplay(g,H),b.current?.active||(v.current=void 0)},[g,H]);const O=()=>{j.current?.release(),p(void 0)},q=t=>({disabled:e.watchOnly,onPointerDown:c=>{e.watchOnly||N||c.button!==0||(c.currentTarget.setPointerCapture(c.pointerId),j.current?.press(t),p(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=>{N||(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),c.repeat||(j.current?.press(t),p(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":!!N,"aria-busy":!!N,onPointerMove:t=>{if(!o)return;const c=t.currentTarget.getBoundingClientRect();h(Q(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:P*M,height:T*M,transform:"translate(-50%, -50%) rotate("+w.turns*90+"deg)"},children:[o&&r.jsx(Z,{inner:m,width:P,height:T}),r.jsx("div",{className:"rc-duo-flat-screen",role:"application","aria-label":"iPhone Duo 2D simulator",tabIndex:0,style:{width:U,height:L,left:(P-W)/2*M,top:(T-I)/2*M,borderRadius:o?m?5.3*M:[.8,6.6,6.6,.8].map(t=>t*M+"px").join(" "):0},onKeyDown:N?void 0:e.onKeyDown,onKeyUp:e.onKeyUp,onPointerDown:t=>{if(e.watchOnly||N||v.current!==void 0||t.button!==0||!g)return;t.currentTarget.focus({preventScroll:!0}),t.currentTarget.setPointerCapture(t.pointerId);const c=K(t);v.current=t.pointerId,b.current?.touch("begin",c.x,c.y)},onPointerMove:t=>{if(v.current!==t.pointerId)return;const c=K(t);b.current?.touch("move",c.x,c.y)},onPointerUp:t=>{v.current===t.pointerId&&F()},onPointerCancel:F,onLostPointerCapture:F,children:r.jsx("video",{ref:a,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":E===t.button,"data-pressed":k===t.button,"aria-label":R.DUO_BUTTONS[t.button]+" physical button",title:R.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":R.DUO_BUTTONS[t.button],title:R.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(A,{button:t.button})},t.button)),N&&r.jsx(ce,{motion:N,onFinish:_})]}),o&&r.jsx(G,{watchOnly:e.watchOnly,angle:te,changeAngle:re,interacting:ne,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 le=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));exports.DuoControls=G;exports.DuoHardwareIcon=A;exports.duoView=le;exports.flatHoverEdge=Q;exports.hardwareIconSize=J;exports.useDuoHinge=$;
|