@limrun/ui 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2770 +0,0 @@
1
- import { jsx as k, jsxs as ue, Fragment as $r } from "react/jsx-runtime";
2
- import { memo as cr, useState as V, useEffect as me, useMemo as ke, useCallback as Un, lazy as Ln, forwardRef as xn, useRef as v, useImperativeHandle as Fn, Suspense as Wn } from "react";
3
- import { createPortal as Hn } from "react-dom";
4
- import './index.css';function Xr(r) {
5
- var t, c, a = "";
6
- if (typeof r == "string" || typeof r == "number") a += r;
7
- else if (typeof r == "object") if (Array.isArray(r)) {
8
- var m = r.length;
9
- for (t = 0; t < m; t++) r[t] && (c = Xr(r[t])) && (a && (a += " "), a += c);
10
- } else for (c in r) r[c] && (a && (a += " "), a += c);
11
- return a;
12
- }
13
- function Pe() {
14
- for (var r, t, c = 0, a = "", m = arguments.length; c < m; c++) (r = arguments[c]) && (t = Xr(r)) && (a && (a += " "), a += t);
15
- return a;
16
- }
17
- const $o = { width: 164.6, height: 117.8, depth: 5.2 };
18
- function Xo(r, t, c) {
19
- return r = Math.max(0, Math.min(1, r)), t = Math.max(0, Math.min(1, t)), c === 1 ? { x: t, y: 1 - r } : c === 2 ? { x: 1 - r, y: 1 - t } : c === 3 ? { x: 1 - t, y: r } : { x: r, y: t };
20
- }
21
- function $n(r) {
22
- return Number.isFinite(r) && r >= 0 && r <= 180;
23
- }
24
- function Bo(r, t) {
25
- return { x: Math.max(0, Math.min(1, r)), y: Math.max(0, Math.min(1, 1 - t)) };
26
- }
27
- function qo(r, t, c) {
28
- return t && (r || !c) ? "touch" : r ? "ignore" : "orbit";
29
- }
30
- function Xn(r, t, c, a) {
31
- if (!Number.isInteger(r) || r < 0 || r > 3 || !Number.isInteger(t) || t < 1 || t > 255 || !Number.isFinite(c) || !Number.isFinite(a) || c < 0 || c > 1 || a < 0 || a > 1)
32
- throw new RangeError("Invalid display touch coordinates");
33
- const m = new ArrayBuffer(12), p = new DataView(m);
34
- return p.setUint8(0, 19), p.setUint8(1, r), p.setUint8(2, t), p.setFloat32(4, c, !0), p.setFloat32(8, a, !0), m;
35
- }
36
- class Vo {
37
- constructor(t, c) {
38
- this.send = t, this.failed = c;
39
- }
40
- send;
41
- failed;
42
- latest;
43
- running = !1;
44
- stopped = !1;
45
- set(t) {
46
- this.stopped || !$n(t) || (this.latest = t, this.flush());
47
- }
48
- stop() {
49
- this.stopped = !0, this.latest = void 0;
50
- }
51
- async flush() {
52
- if (!(this.running || this.stopped)) {
53
- this.running = !0;
54
- try {
55
- for (; this.latest !== void 0 && !this.stopped; ) {
56
- const t = this.latest;
57
- this.latest = void 0, await this.send(t);
58
- }
59
- } catch (t) {
60
- this.latest = void 0, this.stopped || this.failed(t);
61
- } finally {
62
- this.running = !1;
63
- }
64
- }
65
- }
66
- }
67
- const Go = {
68
- side: "Sleep/Wake",
69
- volumeUp: "Volume Up",
70
- volumeDown: "Volume Down"
71
- };
72
- class Jo {
73
- constructor(t, c) {
74
- this.send = t, this.failed = c;
75
- }
76
- send;
77
- failed;
78
- held;
79
- tail = Promise.resolve();
80
- timeout;
81
- press(t) {
82
- this.held || (this.held = t, this.enqueue(t, !0), this.timeout = setTimeout(() => this.release(), 1e4));
83
- }
84
- release() {
85
- if (!this.held) return;
86
- clearTimeout(this.timeout);
87
- const t = this.held;
88
- this.held = void 0, this.enqueue(t, !1);
89
- }
90
- enqueue(t, c) {
91
- this.tail = this.tail.then(() => this.send(t, c)).catch(this.failed);
92
- }
93
- }
94
- const xt = {
95
- INJECT_KEYCODE: 0,
96
- INJECT_TOUCH_EVENT: 2,
97
- // iOS-specific: send two touch points in one message (Option/Alt+drag pinch)
98
- INJECT_TWO_FINGER_TOUCH_EVENT: 18,
99
- SET_CLIPBOARD: 9
100
- }, L = {
101
- ACTION_DOWN: 0,
102
- ACTION_UP: 1,
103
- ACTION_MOVE: 2,
104
- ACTION_CANCEL: 3,
105
- ACTION_POINTER_DOWN: 5,
106
- ACTION_POINTER_UP: 6,
107
- BUTTON_PRIMARY: 1,
108
- BUTTON_SECONDARY: 2,
109
- BUTTON_TERTIARY: 4
110
- }, s = {
111
- // Actions
112
- ACTION_DOWN: 0,
113
- ACTION_UP: 1,
114
- // Meta state flags (from android.view.KeyEvent)
115
- META_NONE: 0,
116
- META_SHIFT_ON: 1,
117
- META_ALT_ON: 2,
118
- META_CTRL_ON: 4096,
119
- // META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON
120
- META_META_ON: 65536,
121
- KEYCODE_0: 7,
122
- KEYCODE_1: 8,
123
- KEYCODE_2: 9,
124
- KEYCODE_3: 10,
125
- KEYCODE_4: 11,
126
- KEYCODE_5: 12,
127
- KEYCODE_6: 13,
128
- KEYCODE_7: 14,
129
- KEYCODE_8: 15,
130
- KEYCODE_9: 16,
131
- DPAD_UP: 19,
132
- // KEYCODE_DPAD_UP
133
- DPAD_DOWN: 20,
134
- // KEYCODE_DPAD_DOWN
135
- DPAD_LEFT: 21,
136
- // KEYCODE_DPAD_LEFT
137
- DPAD_RIGHT: 22,
138
- KEYCODE_A: 29,
139
- KEYCODE_B: 30,
140
- KEYCODE_C: 31,
141
- KEYCODE_D: 32,
142
- KEYCODE_E: 33,
143
- KEYCODE_F: 34,
144
- KEYCODE_G: 35,
145
- KEYCODE_H: 36,
146
- KEYCODE_I: 37,
147
- KEYCODE_J: 38,
148
- KEYCODE_K: 39,
149
- KEYCODE_L: 40,
150
- KEYCODE_M: 41,
151
- KEYCODE_N: 42,
152
- KEYCODE_O: 43,
153
- KEYCODE_P: 44,
154
- KEYCODE_Q: 45,
155
- KEYCODE_R: 46,
156
- KEYCODE_S: 47,
157
- KEYCODE_T: 48,
158
- KEYCODE_U: 49,
159
- KEYCODE_V: 50,
160
- KEYCODE_W: 51,
161
- KEYCODE_X: 52,
162
- KEYCODE_Y: 53,
163
- KEYCODE_Z: 54,
164
- KEYCODE_COMMA: 55,
165
- KEYCODE_PERIOD: 56,
166
- KEYCODE_ALT_LEFT: 57,
167
- KEYCODE_ALT_RIGHT: 58,
168
- KEYCODE_SHIFT_LEFT: 59,
169
- KEYCODE_SHIFT_RIGHT: 60,
170
- KEYCODE_TAB: 61,
171
- KEYCODE_SPACE: 62,
172
- ENTER: 66,
173
- // KEYCODE_ENTER
174
- DEL: 67,
175
- // KEYCODE_DEL (Backspace)
176
- KEYCODE_GRAVE: 68,
177
- // `
178
- KEYCODE_MINUS: 69,
179
- // -
180
- KEYCODE_EQUALS: 70,
181
- // =
182
- KEYCODE_LEFT_BRACKET: 71,
183
- // [
184
- KEYCODE_RIGHT_BRACKET: 72,
185
- // ]
186
- KEYCODE_BACKSLASH: 73,
187
- // \
188
- KEYCODE_SEMICOLON: 74,
189
- // ;
190
- KEYCODE_APOSTROPHE: 75,
191
- // '
192
- KEYCODE_SLASH: 76,
193
- MENU: 82,
194
- KEYCODE_PAGE_UP: 92,
195
- KEYCODE_PAGE_DOWN: 93,
196
- KEYCODE_ESCAPE: 111,
197
- FORWARD_DEL: 112,
198
- // KEYCODE_FORWARD_DEL (Delete key)
199
- KEYCODE_CTRL_LEFT: 113,
200
- KEYCODE_CTRL_RIGHT: 114,
201
- KEYCODE_META_LEFT: 117,
202
- KEYCODE_META_RIGHT: 118,
203
- KEYCODE_MOVE_HOME: 122,
204
- KEYCODE_MOVE_END: 123,
205
- KEYCODE_INSERT: 124,
206
- KEYCODE_F1: 131,
207
- KEYCODE_F2: 132,
208
- KEYCODE_F3: 133,
209
- KEYCODE_F4: 134,
210
- KEYCODE_F5: 135,
211
- KEYCODE_F6: 136,
212
- KEYCODE_F7: 137,
213
- KEYCODE_F8: 138,
214
- KEYCODE_F9: 139,
215
- KEYCODE_F10: 140,
216
- KEYCODE_F11: 141,
217
- KEYCODE_F12: 142,
218
- KEYCODE_NUMPAD_0: 144,
219
- KEYCODE_NUMPAD_1: 145,
220
- KEYCODE_NUMPAD_2: 146,
221
- KEYCODE_NUMPAD_3: 147,
222
- KEYCODE_NUMPAD_4: 148,
223
- KEYCODE_NUMPAD_5: 149,
224
- KEYCODE_NUMPAD_6: 150,
225
- KEYCODE_NUMPAD_7: 151,
226
- KEYCODE_NUMPAD_8: 152,
227
- KEYCODE_NUMPAD_9: 153,
228
- KEYCODE_NUMPAD_DIVIDE: 154,
229
- KEYCODE_NUMPAD_MULTIPLY: 155,
230
- KEYCODE_NUMPAD_SUBTRACT: 156,
231
- KEYCODE_NUMPAD_ADD: 157,
232
- KEYCODE_NUMPAD_DOT: 158,
233
- KEYCODE_NUMPAD_COMMA: 159,
234
- KEYCODE_NUMPAD_ENTER: 160,
235
- KEYCODE_NUMPAD_EQUALS: 161
236
- }, Br = {
237
- KeyA: s.KEYCODE_A,
238
- KeyB: s.KEYCODE_B,
239
- KeyC: s.KEYCODE_C,
240
- KeyD: s.KEYCODE_D,
241
- KeyE: s.KEYCODE_E,
242
- KeyF: s.KEYCODE_F,
243
- KeyG: s.KEYCODE_G,
244
- KeyH: s.KEYCODE_H,
245
- KeyI: s.KEYCODE_I,
246
- KeyJ: s.KEYCODE_J,
247
- KeyK: s.KEYCODE_K,
248
- KeyL: s.KEYCODE_L,
249
- KeyM: s.KEYCODE_M,
250
- KeyN: s.KEYCODE_N,
251
- KeyO: s.KEYCODE_O,
252
- KeyP: s.KEYCODE_P,
253
- KeyQ: s.KEYCODE_Q,
254
- KeyR: s.KEYCODE_R,
255
- KeyS: s.KEYCODE_S,
256
- KeyT: s.KEYCODE_T,
257
- KeyU: s.KEYCODE_U,
258
- KeyV: s.KEYCODE_V,
259
- KeyW: s.KEYCODE_W,
260
- KeyX: s.KEYCODE_X,
261
- KeyY: s.KEYCODE_Y,
262
- KeyZ: s.KEYCODE_Z,
263
- Digit0: s.KEYCODE_0,
264
- Digit1: s.KEYCODE_1,
265
- Digit2: s.KEYCODE_2,
266
- Digit3: s.KEYCODE_3,
267
- Digit4: s.KEYCODE_4,
268
- Digit5: s.KEYCODE_5,
269
- Digit6: s.KEYCODE_6,
270
- Digit7: s.KEYCODE_7,
271
- Digit8: s.KEYCODE_8,
272
- Digit9: s.KEYCODE_9,
273
- Backquote: s.KEYCODE_GRAVE,
274
- Minus: s.KEYCODE_MINUS,
275
- Equal: s.KEYCODE_EQUALS,
276
- BracketLeft: s.KEYCODE_LEFT_BRACKET,
277
- BracketRight: s.KEYCODE_RIGHT_BRACKET,
278
- Backslash: s.KEYCODE_BACKSLASH,
279
- Semicolon: s.KEYCODE_SEMICOLON,
280
- Quote: s.KEYCODE_APOSTROPHE,
281
- Comma: s.KEYCODE_COMMA,
282
- Period: s.KEYCODE_PERIOD,
283
- Slash: s.KEYCODE_SLASH,
284
- Space: s.KEYCODE_SPACE,
285
- Tab: s.KEYCODE_TAB,
286
- Escape: s.KEYCODE_ESCAPE,
287
- ArrowUp: s.DPAD_UP,
288
- ArrowDown: s.DPAD_DOWN,
289
- ArrowLeft: s.DPAD_LEFT,
290
- ArrowRight: s.DPAD_RIGHT,
291
- Enter: s.ENTER,
292
- Backspace: s.DEL,
293
- Delete: s.FORWARD_DEL,
294
- Home: s.KEYCODE_MOVE_HOME,
295
- End: s.KEYCODE_MOVE_END,
296
- PageUp: s.KEYCODE_PAGE_UP,
297
- PageDown: s.KEYCODE_PAGE_DOWN,
298
- Insert: s.KEYCODE_INSERT,
299
- F1: s.KEYCODE_F1,
300
- F2: s.KEYCODE_F2,
301
- F3: s.KEYCODE_F3,
302
- F4: s.KEYCODE_F4,
303
- F5: s.KEYCODE_F5,
304
- F6: s.KEYCODE_F6,
305
- F7: s.KEYCODE_F7,
306
- F8: s.KEYCODE_F8,
307
- F9: s.KEYCODE_F9,
308
- F10: s.KEYCODE_F10,
309
- F11: s.KEYCODE_F11,
310
- F12: s.KEYCODE_F12,
311
- ShiftLeft: s.KEYCODE_SHIFT_LEFT,
312
- ShiftRight: s.KEYCODE_SHIFT_RIGHT,
313
- ControlLeft: s.KEYCODE_CTRL_LEFT,
314
- ControlRight: s.KEYCODE_CTRL_RIGHT,
315
- AltLeft: s.KEYCODE_ALT_LEFT,
316
- AltRight: s.KEYCODE_ALT_RIGHT,
317
- MetaLeft: s.KEYCODE_META_LEFT,
318
- MetaRight: s.KEYCODE_META_RIGHT,
319
- // Windows/Command key
320
- ContextMenu: s.MENU,
321
- // Often the Menu key
322
- // Numpad mappings
323
- Numpad0: s.KEYCODE_NUMPAD_0,
324
- Numpad1: s.KEYCODE_NUMPAD_1,
325
- Numpad2: s.KEYCODE_NUMPAD_2,
326
- Numpad3: s.KEYCODE_NUMPAD_3,
327
- Numpad4: s.KEYCODE_NUMPAD_4,
328
- Numpad5: s.KEYCODE_NUMPAD_5,
329
- Numpad6: s.KEYCODE_NUMPAD_6,
330
- Numpad7: s.KEYCODE_NUMPAD_7,
331
- Numpad8: s.KEYCODE_NUMPAD_8,
332
- Numpad9: s.KEYCODE_NUMPAD_9,
333
- NumpadDivide: s.KEYCODE_NUMPAD_DIVIDE,
334
- NumpadMultiply: s.KEYCODE_NUMPAD_MULTIPLY,
335
- NumpadSubtract: s.KEYCODE_NUMPAD_SUBTRACT,
336
- NumpadAdd: s.KEYCODE_NUMPAD_ADD,
337
- NumpadDecimal: s.KEYCODE_NUMPAD_DOT,
338
- NumpadComma: s.KEYCODE_NUMPAD_COMMA,
339
- // Some numpads have comma
340
- NumpadEnter: s.KEYCODE_NUMPAD_ENTER,
341
- NumpadEqual: s.KEYCODE_NUMPAD_EQUALS
342
- }, qr = `(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())}})();
343
- `, Ur = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", qr], { type: "text/javascript;charset=utf-8" });
344
- function Bn(r) {
345
- let t;
346
- try {
347
- if (t = Ur && (self.URL || self.webkitURL).createObjectURL(Ur), !t) throw "";
348
- const c = new Worker(t, {
349
- name: r?.name
350
- });
351
- return c.addEventListener("error", () => {
352
- (self.URL || self.webkitURL).revokeObjectURL(t);
353
- }), c;
354
- } catch {
355
- return new Worker(
356
- "data:text/javascript;charset=utf-8," + encodeURIComponent(qr),
357
- {
358
- name: r?.name
359
- }
360
- );
361
- }
362
- }
363
- function qn(r, t, c) {
364
- const { MediaStreamTrackProcessor: a, MediaStreamTrackGenerator: m } = globalThis, p = t.getVideoTracks()[0];
365
- let g, C, D, O, M = !1;
366
- const S = () => {
367
- M || (M = !0, g?.stop(), C?.stop(), D && (D.postMessage({ type: "stop" }), O = setTimeout(() => D?.terminate(), 1e3)));
368
- }, G = (J) => {
369
- r.srcObject = J, r.play().catch(() => {
370
- });
371
- }, ce = (J) => {
372
- M || (S(), c(J), G(t));
373
- };
374
- try {
375
- if (p && a && m) {
376
- g = p.clone();
377
- const J = new a({ track: g, maxBufferSize: 1 }), he = new m({ kind: "video" });
378
- C = he, D = new Bn(), D.onmessage = ({ data: ee }) => {
379
- ee.type === "error" ? ce(new Error(ee.message)) : ee.type === "stopped" && (clearTimeout(O), D?.terminate());
380
- }, D.onerror = (ee) => ce(new Error(ee.message)), D.postMessage({ type: "start", readable: J.readable, writable: he.writable }, [
381
- J.readable,
382
- he.writable
383
- ]), G(new MediaStream(t.getTracks().map((ee) => ee === p ? he : ee)));
384
- } else
385
- G(t);
386
- } catch (J) {
387
- ce(J);
388
- }
389
- return S;
390
- }
391
- function Vn(r, t) {
392
- const c = r.createDataChannel("latency-trace-v1", {
393
- ordered: !0,
394
- negotiated: !0,
395
- id: 2
396
- });
397
- let a = !1, m = !1, p = 0;
398
- return c.onmessage = (g) => {
399
- if (m) return;
400
- let C;
401
- try {
402
- C = JSON.parse(g.data);
403
- } catch (D) {
404
- console.warn("Invalid latency trace message", D);
405
- return;
406
- }
407
- C && typeof C == "object" && !Array.isArray(C) && t(C);
408
- }, c.onclose = () => {
409
- m = !0, a = !1;
410
- }, {
411
- accept(g) {
412
- a = !m && g === 1;
413
- },
414
- wrap(g) {
415
- if (!a || g.byteLength !== 32 || new DataView(g).getUint8(0) !== 2) return g;
416
- const C = new ArrayBuffer(38), D = new DataView(C);
417
- return D.setUint8(0, 240), D.setUint8(1, 1), D.setUint32(2, ++p, !0), new Uint8Array(C, 6).set(new Uint8Array(g)), C;
418
- },
419
- close() {
420
- m = !0, a = !1, c.onmessage = null, c.onclose = null, c.close();
421
- }
422
- };
423
- }
424
- function Pt(r, t, c, a, m, p, g = 1, C = 0, D = 0) {
425
- const O = new ArrayBuffer(32), M = new DataView(O);
426
- let S = 0;
427
- return M.setUint8(S, xt.INJECT_TOUCH_EVENT), S += 1, M.setUint8(S, r), S += 1, M.setBigInt64(S, BigInt(t), !0), S += 8, M.setInt32(S, Math.round(m), !0), S += 4, M.setInt32(S, Math.round(p), !0), S += 4, M.setUint16(S, c, !0), S += 2, M.setUint16(S, a, !0), S += 2, M.setInt16(S, Math.round(g * 65535), !0), S += 2, M.setInt32(S, C, !0), S += 4, M.setInt32(S, D, !0), O;
428
- }
429
- function Gn(r, t, c, a, m, p, g) {
430
- const C = new ArrayBuffer(24), D = new DataView(C);
431
- let O = 0;
432
- return D.setUint8(O, xt.INJECT_TWO_FINGER_TOUCH_EVENT), O += 1, D.setUint8(O, r), O += 1, D.setInt32(O, Math.round(a), !0), O += 4, D.setInt32(O, Math.round(m), !0), O += 4, D.setInt32(O, Math.round(p), !0), O += 4, D.setInt32(O, Math.round(g), !0), O += 4, D.setUint16(O, t, !0), O += 2, D.setUint16(O, c, !0), O += 2, D.setUint16(O, 0, !0), C;
433
- }
434
- function Jn(r, t = !0) {
435
- const a = new TextEncoder().encode(r), m = new ArrayBuffer(14 + a.length), p = new DataView(m);
436
- let g = 0;
437
- return p.setUint8(g, xt.SET_CLIPBOARD), g += 1, p.setBigInt64(g, BigInt(0), !1), g += 8, p.setUint8(g, t ? 1 : 0), g += 1, p.setUint32(g, a.length, !1), g += 4, new Uint8Array(m, g).set(a), m;
438
- }
439
- function gt(r, t, c = 0, a = 0) {
440
- const m = new ArrayBuffer(14), p = new DataView(m);
441
- let g = 0;
442
- return p.setUint8(g, xt.INJECT_KEYCODE), g += 1, p.setUint8(g, r), g += 1, p.setInt32(g, t, !0), g += 4, p.setInt32(g, c, !0), g += 4, p.setInt32(g, a, !0), m;
443
- }
444
- const or = "Accessibility unavailable on this device.", Lt = 500, Vr = (r, t) => Math.abs(r.x - t.x) < 0.5 && Math.abs(r.y - t.y) < 0.5 && Math.abs(r.width - t.width) < 0.5 && Math.abs(r.height - t.height) < 0.5, jn = (r) => Math.max(0, r.width) * Math.max(0, r.height), zn = (r) => {
445
- const t = r.find((c) => c.frame && c.frame.width > 0 && c.frame.height > 0);
446
- return t?.frame ? ((Math.abs(t.frame.x) > 0.5 || Math.abs(t.frame.y) > 0.5) && console.warn(
447
- `[ax-tree] iOS root frame is not anchored at (0,0): (${t.frame.x},${t.frame.y}). Element positions may be slightly off from the rendered video.`
448
- ), { x: 0, y: 0, width: t.frame.width, height: t.frame.height }) : { x: 0, y: 0, width: 1, height: 1 };
449
- }, Qn = (r) => {
450
- const t = {};
451
- return typeof r.AXUniqueId == "string" && r.AXUniqueId.length > 0 && (t.AXUniqueId = r.AXUniqueId), typeof r.AXLabel == "string" && r.AXLabel.length > 0 && (t.AXLabel = r.AXLabel), typeof r.type == "string" && r.type.length > 0 && (t.className = r.type), t;
452
- }, Zn = (r) => {
453
- const t = {};
454
- for (const [c, a] of Object.entries(r))
455
- c !== "children" && (t[c] = a);
456
- return t;
457
- };
458
- function eo(r) {
459
- const t = Array.isArray(r) ? r : [r], c = zn(t), a = [], m = (p, g) => {
460
- if (a.length >= Lt) return;
461
- const C = p.frame;
462
- if (C && C.width > 0 && C.height > 0 && !Vr(C, c)) {
463
- const O = p.role_description || p.role || "", M = (typeof p.AXLabel == "string" ? p.AXLabel : "") || (typeof p.title == "string" ? p.title : "") || "";
464
- a.push({
465
- id: typeof p.AXUniqueId == "string" && p.AXUniqueId.length > 0 ? p.AXUniqueId : g,
466
- path: g,
467
- label: M,
468
- value: typeof p.AXValue == "string" ? p.AXValue : "",
469
- role: O,
470
- type: typeof p.type == "string" ? p.type : "",
471
- enabled: p.enabled !== !1,
472
- focused: p.focused === !0,
473
- frame: { x: C.x, y: C.y, width: C.width, height: C.height },
474
- selectors: Qn(p),
475
- raw: Zn(p)
476
- });
477
- }
478
- const D = Array.isArray(p.children) ? p.children : [];
479
- for (let O = 0; O < D.length && a.length < Lt; O++)
480
- m(D[O], `${g}.${O}`);
481
- };
482
- for (let p = 0; p < t.length && a.length < Lt; p++)
483
- m(t[p], String(p));
484
- return {
485
- platform: "ios",
486
- screen: { width: c.width, height: c.height },
487
- elements: a,
488
- capturedAt: Date.now()
489
- };
490
- }
491
- const to = (r) => {
492
- let t = { x: 0, y: 0, width: 1, height: 1 }, c = 0;
493
- for (const a of r) {
494
- const m = a.parsedBounds;
495
- if (!m) continue;
496
- const p = m.right - m.left, g = m.bottom - m.top, C = Math.max(0, p) * Math.max(0, g);
497
- C > c && (c = C, t = { x: 0, y: 0, width: p, height: g });
498
- }
499
- return t;
500
- }, ro = (r) => {
501
- const t = {};
502
- return typeof r.resourceId == "string" && r.resourceId.length > 0 && (t.resourceId = r.resourceId), typeof r.contentDesc == "string" && r.contentDesc.length > 0 && (t.contentDesc = r.contentDesc), typeof r.text == "string" && r.text.length > 0 && (t.text = r.text), typeof r.className == "string" && r.className.length > 0 && (t.className = r.className), t;
503
- };
504
- function no(r) {
505
- const t = to(r), c = [];
506
- for (let a = 0; a < r.length && c.length < Lt; a++) {
507
- const m = r[a], p = m.parsedBounds;
508
- if (!p) continue;
509
- const g = Math.max(0, p.right - p.left), C = Math.max(0, p.bottom - p.top);
510
- if (g <= 0 || C <= 0) continue;
511
- const D = { x: p.left, y: p.top, width: g, height: C };
512
- if (Vr(D, { x: 0, y: 0, width: t.width, height: t.height })) continue;
513
- const O = m.contentDesc || m.text || "", M = m.className || "";
514
- c.push({
515
- id: m.resourceId && m.resourceId.length > 0 ? m.resourceId : m.contentDesc && m.contentDesc.length > 0 ? `cd:${m.contentDesc}` : String(a),
516
- path: String(a),
517
- label: O,
518
- value: typeof m.text == "string" ? m.text : "",
519
- role: M,
520
- type: M,
521
- enabled: m.enabled !== !1,
522
- focused: m.focused === !0,
523
- frame: D,
524
- selectors: ro(m),
525
- raw: { ...m }
526
- });
527
- }
528
- return {
529
- platform: "android",
530
- screen: { width: t.width, height: t.height },
531
- elements: c,
532
- capturedAt: Date.now()
533
- };
534
- }
535
- function oo(r, t) {
536
- const c = Math.max(0, r.x), a = Math.max(0, r.y), m = Math.min(t.width, r.x + r.width), p = Math.min(t.height, r.y + r.height), g = Math.max(0, m - c), C = Math.max(0, p - a);
537
- return g > 0 && C > 0 ? { x: c, y: a, width: g, height: C } : null;
538
- }
539
- function Gr(r, t) {
540
- if (r === t) return !0;
541
- if (r.id !== t.id || r.path !== t.path || r.label !== t.label || r.value !== t.value || r.role !== t.role || r.type !== t.type || r.enabled !== t.enabled || r.focused !== t.focused) return !1;
542
- const c = r.frame, a = t.frame;
543
- return c.x === a.x && c.y === a.y && c.width === a.width && c.height === a.height;
544
- }
545
- function Jr(r, t) {
546
- if (r === t) return !0;
547
- if (!r || !t || r.platform !== t.platform || r.screen.width !== t.screen.width || r.screen.height !== t.screen.height || r.elements.length !== t.elements.length) return !1;
548
- for (let c = 0; c < r.elements.length; c++)
549
- if (!Gr(r.elements[c], t.elements[c])) return !1;
550
- return !0;
551
- }
552
- function io(r, t, c) {
553
- let a = null, m = 1 / 0;
554
- for (const p of r.elements) {
555
- const g = p.frame;
556
- if (t < g.x || c < g.y || t > g.x + g.width || c > g.y + g.height) continue;
557
- const C = jn(g);
558
- C < m && (m = C, a = p);
559
- }
560
- return a;
561
- }
562
- function co(r, t) {
563
- if (t === "ios") {
564
- if (r.selectors.AXUniqueId)
565
- return `client.tapElement({ AXUniqueId: ${JSON.stringify(r.selectors.AXUniqueId)} })`;
566
- if (r.selectors.AXLabel) {
567
- const c = r.selectors.className ? `, type: ${JSON.stringify(r.selectors.className)}` : "";
568
- return `client.tapElement({ AXLabel: ${JSON.stringify(r.selectors.AXLabel)}${c} })`;
569
- }
570
- return null;
571
- }
572
- return r.selectors.resourceId ? `client.tap({ selector: { resourceId: ${JSON.stringify(r.selectors.resourceId)} } })` : r.selectors.contentDesc ? `client.tap({ selector: { contentDesc: ${JSON.stringify(r.selectors.contentDesc)} } })` : r.selectors.text ? `client.tap({ selector: { text: ${JSON.stringify(r.selectors.text)} } })` : null;
573
- }
574
- function jr(r) {
575
- const t = r.role || r.type || "";
576
- if (!t) return "element";
577
- let c = t.replace(/^AX/, "");
578
- return c.includes(".") && (c = c.split(".").pop()), c === "GenericElement" ? "Element" : (c = c.replace(/([a-z])([A-Z])/g, "$1 $2"), c);
579
- }
580
- const Lr = 80;
581
- function zr(r) {
582
- const t = jr(r), c = r.label || r.value || "";
583
- if (!c) return t;
584
- const a = c.length > Lr ? c.slice(0, Lr).trimEnd() + "…" : c;
585
- return `${t} · ${a}`;
586
- }
587
- const so = 500, ao = 2e3, xr = 5e3, uo = 8e3, lo = 1200, fo = 250, ho = () => `ax-rc-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
588
- class po {
589
- platform;
590
- send;
591
- onSnapshot;
592
- onStatusChange;
593
- baseIntervalMs;
594
- maxBackoffMs;
595
- androidElementTreeOptions;
596
- pending = /* @__PURE__ */ new Map();
597
- running = !1;
598
- timer;
599
- currentInterval;
600
- lastSnapshot = null;
601
- // Single-flight: only one outstanding request at a time. Avoids piling
602
- // identical requests on a slow server.
603
- inflight = !1;
604
- // Rate-limit floor for bumpActivity so high-frequency input (drags,
605
- // typing) doesn't trigger a request storm.
606
- lastBumpAtMs = 0;
607
- // Wall-clock timestamp until which we're in "activity boost" mode and
608
- // schedule fetches at ACTIVITY_BOOST_INTERVAL_MS instead of the normal
609
- // backed-off interval. Set by bumpActivity().
610
- boostUntilMs = 0;
611
- // Coarse-grained current status; deduplicated before emission so
612
- // identical-to-current transitions are no-ops.
613
- status = "idle";
614
- constructor(t) {
615
- this.platform = t.platform, this.send = t.send, this.onSnapshot = t.onSnapshot, this.onStatusChange = t.onStatusChange, this.baseIntervalMs = t.baseIntervalMs ?? so, this.maxBackoffMs = t.maxBackoffMs ?? ao, this.androidElementTreeOptions = t.androidElementTreeOptions, this.currentInterval = this.baseIntervalMs;
616
- }
617
- start() {
618
- this.running || (this.running = !0, this.currentInterval = this.baseIntervalMs, this.boostUntilMs = 0, this.setStatus("starting"), this.runOnce());
619
- }
620
- stop() {
621
- 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));
622
- }
623
- getStatus() {
624
- return this.status;
625
- }
626
- setStatus(t, c) {
627
- if (this.status !== t && (this.status = t, !!this.onStatusChange))
628
- try {
629
- this.onStatusChange(t, c);
630
- } catch (a) {
631
- console.error("[AxFetcher] onStatusChange threw:", a);
632
- }
633
- }
634
- // Called after any user-driven action that's likely to change the UI
635
- // (taps, scrolls, key events, openUrl, app termination, orientation
636
- // change, etc.). Has two effects:
637
- //
638
- // 1. Resets the polling interval to base and triggers an immediate
639
- // fetch (rate-limited so drags / rapid typing don't request-storm).
640
- // 2. Enters a brief "boost" window during which scheduleNext() uses a
641
- // shorter interval (ACTIVITY_BOOST_INTERVAL_MS), so we capture the
642
- // mid- and post-animation tree without waiting for the next
643
- // back-off cycle.
644
- bumpActivity() {
645
- if (!this.running) return;
646
- const t = Date.now();
647
- this.boostUntilMs = t + lo;
648
- const c = Math.max(150, Math.floor(this.baseIntervalMs / 2));
649
- if (t - this.lastBumpAtMs < c) {
650
- this.currentInterval = this.baseIntervalMs;
651
- return;
652
- }
653
- this.lastBumpAtMs = t, this.currentInterval = this.baseIntervalMs, this.timer !== void 0 && (window.clearTimeout(this.timer), this.timer = void 0), this.inflight || this.runOnce();
654
- }
655
- // Fire a one-shot fetch independent of the poll loop. Useful for the
656
- // imperative refresh() ref method customers may call.
657
- //
658
- // Goes through the same change-detect path as the regular poll loop —
659
- // identical-to-last-snapshot responses do NOT re-emit via onSnapshot, so
660
- // a customer calling refresh() in a tight loop doesn't see a stream of
661
- // duplicate snapshots. The returned promise still resolves with the
662
- // (possibly identical) snapshot for the caller's own use.
663
- async refresh() {
664
- const t = await this.requestOnce();
665
- return this.running && this.deliver(t), t;
666
- }
667
- // Returns the latest snapshot delivered to onSnapshot. May be stale.
668
- getLatest() {
669
- return this.lastSnapshot;
670
- }
671
- // Called by RemoteControl's ws.onmessage when it sees a message type we own.
672
- // Returns true when the message was a response we were waiting for.
673
- handleMessage(t) {
674
- if (!t || typeof t.id != "string") return !1;
675
- const c = t.id;
676
- if (!this.pending.get(c)) return !1;
677
- if (this.platform === "ios") {
678
- if (t.type !== "elementTreeResult") return !1;
679
- const C = typeof t.error == "string" ? t.error : null;
680
- if (C)
681
- return this.settleReject(c, new Error(C)), !0;
682
- const D = typeof t.json == "string" ? t.json : "";
683
- try {
684
- const O = JSON.parse(D), M = eo(O);
685
- this.settleResolve(c, M);
686
- } catch (O) {
687
- this.settleReject(c, O instanceof Error ? O : new Error(String(O)));
688
- }
689
- return !0;
690
- }
691
- if (t.type !== "getElementTreeResult") return !1;
692
- const m = t.error;
693
- if (m && typeof m == "object") {
694
- const C = typeof m.message == "string" ? m.message : "getElementTree failed";
695
- return this.settleReject(c, new Error(C)), !0;
696
- }
697
- const p = t.payload, g = Array.isArray(p?.nodes) ? p.nodes : [];
698
- try {
699
- const C = no(g);
700
- this.settleResolve(c, C);
701
- } catch (C) {
702
- this.settleReject(c, C instanceof Error ? C : new Error(String(C)));
703
- }
704
- return !0;
705
- }
706
- buildRequest(t) {
707
- return this.platform === "ios" ? { type: "elementTree", id: t } : { type: "getElementTree", id: t, ...this.androidElementTreeOptions };
708
- }
709
- async requestOnce() {
710
- const t = ho();
711
- return new Promise((c, a) => {
712
- const m = window.setTimeout(
713
- () => {
714
- this.pending.delete(t), a(new Error("elementTree request timed out"));
715
- },
716
- uo + (this.androidElementTreeOptions?.waitForIdleTimeoutMs ?? 0)
717
- );
718
- this.pending.set(t, { resolve: c, reject: a, timer: m }), this.send(this.buildRequest(t)) || (window.clearTimeout(m), this.pending.delete(t), a(new Error("elementTree send failed (WebSocket not open)")));
719
- });
720
- }
721
- async runOnce() {
722
- if (this.running && !this.inflight) {
723
- this.inflight = !0;
724
- try {
725
- const t = await this.requestOnce();
726
- if (!this.running) return;
727
- this.deliver(t);
728
- } catch (t) {
729
- if (!this.running) return;
730
- const c = t instanceof Error ? t.message : String(t), a = /unavailable|not (yet )?running|failed|timeout/i.test(c);
731
- this.currentInterval = a ? xr : Math.min(this.currentInterval * 2, this.maxBackoffMs), this.setStatus(a ? "unavailable" : "error", c);
732
- } finally {
733
- this.inflight = !1, this.scheduleNext();
734
- }
735
- }
736
- }
737
- deliver(t) {
738
- const c = this.lastSnapshot;
739
- if (Jr(c, t)) {
740
- this.currentInterval = Math.min(this.currentInterval * 2, this.maxBackoffMs), this.lastSnapshot = t, t.errors?.includes(or) || this.setStatus("ready");
741
- return;
742
- }
743
- this.lastSnapshot = t, this.currentInterval = this.baseIntervalMs, t.errors?.includes(or) ? (this.currentInterval = xr, this.setStatus("unavailable", or)) : this.setStatus("ready"), this.onSnapshot(t);
744
- }
745
- scheduleNext() {
746
- if (!this.running) return;
747
- this.timer !== void 0 && window.clearTimeout(this.timer);
748
- const t = Date.now() < this.boostUntilMs ? Math.min(fo, this.currentInterval) : this.currentInterval;
749
- this.timer = window.setTimeout(() => {
750
- this.timer = void 0, this.runOnce();
751
- }, t);
752
- }
753
- settleResolve(t, c) {
754
- const a = this.pending.get(t);
755
- a && (window.clearTimeout(a.timer), this.pending.delete(t), a.resolve(c));
756
- }
757
- settleReject(t, c) {
758
- const a = this.pending.get(t);
759
- a && (window.clearTimeout(a.timer), this.pending.delete(t), a.reject(c));
760
- }
761
- failAllPending(t) {
762
- for (const [c, a] of this.pending.entries())
763
- window.clearTimeout(a.timer), a.reject(new Error(t)), this.pending.delete(c);
764
- }
765
- }
766
- class mo {
767
- generation = 0;
768
- tail = Promise.resolve();
769
- get currentGeneration() {
770
- return this.generation;
771
- }
772
- enqueue(t) {
773
- const c = ++this.generation;
774
- return this.append(c, t);
775
- }
776
- /**
777
- * Queues related work without superseding an already queued request.
778
- *
779
- * The operation retains the generation current at enqueue time and becomes
780
- * stale if a later camera request increments it before this work starts.
781
- */
782
- enqueueCurrent(t) {
783
- return this.append(this.generation, t);
784
- }
785
- append(t, c) {
786
- const a = {
787
- generation: t,
788
- isCurrent: () => t === this.generation
789
- }, m = this.tail.then(() => c(a));
790
- return this.tail = m.catch(() => {
791
- }), m;
792
- }
793
- invalidate() {
794
- ++this.generation;
795
- }
796
- }
797
- function Eo(r) {
798
- if (!r || typeof r != "object") return null;
799
- const t = r;
800
- if (t.type !== "cameraRequest" || typeof t.active != "boolean") return null;
801
- const c = { active: t.active };
802
- return (t.facingMode === "user" || t.facingMode === "environment") && (c.facingMode = t.facingMode), c;
803
- }
804
- function go(r) {
805
- const t = {
806
- frameRate: { ideal: 30, max: 30 }
807
- };
808
- return r?.facingMode && (t.facingMode = { ideal: r.facingMode }), t;
809
- }
810
- function yo(r, t) {
811
- return !r || r.facingMode !== t.facingMode;
812
- }
813
- function Co(r) {
814
- const t = r.getSettings();
815
- return {
816
- width: t.width,
817
- height: t.height,
818
- frameRate: t.frameRate,
819
- deviceId: t.deviceId,
820
- label: r.label || void 0,
821
- facingMode: t.facingMode
822
- };
823
- }
824
- function vo(r) {
825
- return {
826
- type: "cameraResult",
827
- granted: !0,
828
- camera: Co(r)
829
- };
830
- }
831
- const Oo = async (r) => {
832
- if (!r) return !1;
833
- try {
834
- if (typeof navigator < "u" && navigator.clipboard?.writeText)
835
- return await navigator.clipboard.writeText(r), !0;
836
- } catch {
837
- }
838
- try {
839
- const t = document.createElement("textarea");
840
- t.value = r, t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select();
841
- const c = document.execCommand("copy");
842
- return document.body.removeChild(t), c;
843
- } catch {
844
- return !1;
845
- }
846
- }, _o = cr(
847
- function({ element: t, screen: c, highlighted: a, selected: m, selectable: p, onClick: g }) {
848
- const C = oo(t.frame, c);
849
- if (!C) return null;
850
- const D = zr(t);
851
- return /* @__PURE__ */ k(
852
- "button",
853
- {
854
- type: "button",
855
- className: Pe("rc-inspect-box", !t.enabled && "rc-inspect-box-disabled"),
856
- "data-ax-id": t.id,
857
- "data-ax-path": t.path,
858
- "data-ax-label": t.label || void 0,
859
- "data-ax-role": t.role || void 0,
860
- "data-highlighted": a ? "true" : "false",
861
- "data-selected": m ? "true" : "false",
862
- "aria-label": D,
863
- onClick: (O) => {
864
- p && (O.preventDefault(), O.stopPropagation(), g(t, { x: O.clientX, y: O.clientY }));
865
- },
866
- style: {
867
- left: `${C.x / c.width * 100}%`,
868
- top: `${C.y / c.height * 100}%`,
869
- width: `${C.width / c.width * 100}%`,
870
- height: `${C.height / c.height * 100}%`
871
- }
872
- }
873
- );
874
- },
875
- (r, t) => r.highlighted === t.highlighted && r.selected === t.selected && r.selectable === t.selectable && r.screen.width === t.screen.width && r.screen.height === t.screen.height && r.onClick === t.onClick && Gr(r.element, t.element)
876
- ), wo = 260, Do = 220, To = 6, Ao = 8, bo = cr(function({
877
- element: t,
878
- platform: c,
879
- anchor: a,
880
- cursorAnchored: m,
881
- showActions: p,
882
- onTap: g
883
- }) {
884
- const [C, D] = V(null);
885
- me(() => {
886
- if (!C) return;
887
- const X = window.setTimeout(() => D(null), 1100);
888
- return () => window.clearTimeout(X);
889
- }, [C]);
890
- const O = ke(() => {
891
- const X = wo, Ee = Do, se = To, H = Ao, ge = typeof window < "u" ? window.innerWidth : 1024, tt = typeof window < "u" ? window.innerHeight : 768, Te = a.x + se + X <= ge - H, Ue = a.y - se - Ee >= H;
892
- let _e = Te ? a.x + se : a.x - se, W = Ue ? a.y - se : a.y + se;
893
- const Wt = `translate(${Te ? "0" : "-100%"}, ${Ue ? "-100%" : "0"})`;
894
- return _e = Math.max(H + (Te ? 0 : X), Math.min(ge - H - (Te ? X : 0), _e)), W = Math.max(H + (Ue ? Ee : 0), Math.min(tt - H - (Ue ? 0 : Ee), W)), { left: `${_e}px`, top: `${W}px`, transform: Wt };
895
- }, [a.x, a.y]), M = ke(() => co(t, c), [t, c]), S = c === "ios" ? t.selectors.AXUniqueId : t.selectors.resourceId, G = c === "ios" ? "AXUniqueId" : "resourceId", ce = Un(async (X, Ee) => {
896
- if (!X) return;
897
- await Oo(X) && D(Ee);
898
- }, []), J = jr(t), he = t.label || t.value || J, ee = zr(t);
899
- return Hn(
900
- /* @__PURE__ */ ue(
901
- "div",
902
- {
903
- className: "rc-inspect-card",
904
- "data-cursor-anchored": m ? "true" : "false",
905
- style: O,
906
- onClick: (X) => X.stopPropagation(),
907
- onMouseDown: (X) => X.stopPropagation(),
908
- onMouseMove: (X) => X.stopPropagation(),
909
- children: [
910
- /* @__PURE__ */ ue("div", { className: "rc-inspect-card-header", children: [
911
- /* @__PURE__ */ k("span", { className: "rc-inspect-card-role", children: J }),
912
- !t.enabled && /* @__PURE__ */ k("span", { className: "rc-inspect-card-tag", children: "disabled" }),
913
- t.focused && /* @__PURE__ */ k("span", { className: "rc-inspect-card-tag rc-inspect-card-tag-blue", children: "focused" })
914
- ] }),
915
- /* @__PURE__ */ k("p", { className: "rc-inspect-card-title", title: ee, children: he }),
916
- S && /* @__PURE__ */ ue("div", { className: "rc-inspect-card-row", children: [
917
- /* @__PURE__ */ ue("span", { className: "rc-inspect-card-row-label", children: [
918
- G,
919
- ":"
920
- ] }),
921
- /* @__PURE__ */ k("span", { className: "rc-inspect-card-row-value", children: S })
922
- ] }),
923
- t.value && t.value !== t.label && /* @__PURE__ */ ue("div", { className: "rc-inspect-card-row", children: [
924
- /* @__PURE__ */ k("span", { className: "rc-inspect-card-row-label", children: "value:" }),
925
- /* @__PURE__ */ k("span", { className: "rc-inspect-card-row-value", children: t.value })
926
- ] }),
927
- /* @__PURE__ */ ue("div", { className: "rc-inspect-card-row", children: [
928
- /* @__PURE__ */ k("span", { className: "rc-inspect-card-row-label", children: "frame:" }),
929
- /* @__PURE__ */ ue("span", { className: "rc-inspect-card-row-value", children: [
930
- Math.round(t.frame.width),
931
- "×",
932
- Math.round(t.frame.height),
933
- " @ ",
934
- Math.round(t.frame.x),
935
- ",",
936
- Math.round(t.frame.y)
937
- ] })
938
- ] }),
939
- p && /* @__PURE__ */ ue("div", { className: "rc-inspect-card-actions", children: [
940
- /* @__PURE__ */ k(
941
- "button",
942
- {
943
- type: "button",
944
- className: "rc-inspect-card-btn rc-inspect-card-btn-primary",
945
- onClick: () => g(t, a),
946
- children: "Tap"
947
- }
948
- ),
949
- /* @__PURE__ */ k(
950
- "button",
951
- {
952
- type: "button",
953
- className: Pe("rc-inspect-card-btn", C === "selector" && "rc-inspect-card-btn-copied"),
954
- disabled: !M,
955
- title: M ?? "No usable selector for this element",
956
- onClick: () => ce(M ?? void 0, "selector"),
957
- children: C === "selector" ? "Copied!" : "Copy selector"
958
- }
959
- ),
960
- /* @__PURE__ */ k(
961
- "button",
962
- {
963
- type: "button",
964
- className: Pe("rc-inspect-card-btn", C === "id" && "rc-inspect-card-btn-copied"),
965
- disabled: !S,
966
- title: S ?? `No ${G}`,
967
- onClick: () => ce(S, "id"),
968
- children: C === "id" ? "Copied!" : `Copy ${G}`
969
- }
970
- )
971
- ] })
972
- ]
973
- }
974
- ),
975
- document.body
976
- );
977
- }), So = cr(function({
978
- snapshot: t,
979
- geometry: c,
980
- highlightedId: a,
981
- selectedId: m,
982
- mode: p,
983
- cursorPosition: g,
984
- frozenCursorPosition: C,
985
- onSelectChange: D,
986
- onTapElement: O
987
- }) {
988
- const M = p === "select", S = M ? a !== null && a !== m : a !== null, G = M ? a ?? m : a, ce = ke(() => {
989
- const H = /* @__PURE__ */ new Map();
990
- if (!t) return H;
991
- for (const ge of t.elements) H.set(ge.id, ge);
992
- return H;
993
- }, [t]), J = ke(() => G ? ce.get(G) ?? null : null, [G, ce]);
994
- if (!(!!t && !!c && t.screen.width > 0 && t.screen.height > 0 && t.elements.length > 0)) return null;
995
- const ee = S ? g : C ?? g, X = S, Ee = M && !S && m !== null, se = (H) => {
996
- M && H.target === H.currentTarget && D(null, null);
997
- };
998
- return /* @__PURE__ */ ue($r, { children: [
999
- /* @__PURE__ */ k(
1000
- "div",
1001
- {
1002
- className: Pe("rc-inspect-overlay", M && "rc-inspect-overlay-select"),
1003
- style: {
1004
- left: `${c.left}px`,
1005
- top: `${c.top}px`,
1006
- width: `${c.width}px`,
1007
- height: `${c.height}px`
1008
- },
1009
- onClick: se,
1010
- children: t.elements.map((H) => /* @__PURE__ */ k(
1011
- _o,
1012
- {
1013
- element: H,
1014
- screen: t.screen,
1015
- highlighted: H.id === a,
1016
- selected: H.id === m,
1017
- selectable: M,
1018
- onClick: D
1019
- },
1020
- H.id
1021
- ))
1022
- }
1023
- ),
1024
- J && ee && /* @__PURE__ */ k(
1025
- bo,
1026
- {
1027
- element: J,
1028
- platform: t.platform,
1029
- anchor: ee,
1030
- cursorAnchored: X,
1031
- showActions: Ee,
1032
- onTap: O
1033
- }
1034
- )
1035
- ] });
1036
- }), Mo = Ln(() => import("./duo-view-XeO_m-1d.mjs").then((r) => r.d)), F = (...r) => {
1037
- window.debugRemoteControl && console.log(...r);
1038
- }, A = (...r) => {
1039
- window.debugRemoteControl && console.warn(...r);
1040
- }, U = (r, t, ...c) => {
1041
- if (t)
1042
- try {
1043
- t(...c);
1044
- } catch (a) {
1045
- console.error(`[RemoteControl] customer callback "${r}" threw:`, a);
1046
- }
1047
- }, Ut = (r) => Object.entries(L).find(
1048
- ([c, a]) => c.startsWith("ACTION_") && a === r
1049
- )?.[0] ?? String(r), Ro = (r) => r.includes("/android_") ? "android" : "ios", Fr = (r, t) => {
1050
- const c = new URL(r);
1051
- return c.searchParams.set("token", t), c.toString();
1052
- }, Wr = 1920, Hr = 1200, ir = 3, No = 1e3, Io = 15e3, Yo = 3e3, Ko = 4e3, ko = (r, t) => r === Wr && t === Hr || r === Hr && t === Wr, Po = {
1053
- ios: {
1054
- videoBorderRadiusMultiplier: 0.15,
1055
- loadingLogoSize: "20%",
1056
- // Video position as percentage of frame dimensions
1057
- videoPosition: {
1058
- portrait: { heightMultiplier: 0.9678 },
1059
- landscape: { widthMultiplier: 0.9678 }
1060
- }
1061
- },
1062
- android: {
1063
- videoBorderRadiusMultiplier: 0.13,
1064
- loadingLogoSize: "40%",
1065
- // Video position as percentage of frame dimensions
1066
- videoPosition: {
1067
- portrait: { heightMultiplier: 0.967 },
1068
- landscape: { widthMultiplier: 0.962 }
1069
- }
1070
- }
1071
- };
1072
- function Uo(r) {
1073
- const t = r.code, c = Br[t];
1074
- if (!c)
1075
- return A(`Unknown event.code: ${t}, key: ${r.key}`), null;
1076
- let a = s.META_NONE;
1077
- const m = t >= "KeyA" && t <= "KeyZ", p = r.getModifierState("CapsLock"), g = r.shiftKey;
1078
- let C = g;
1079
- return m && (C = g !== p), C && (a |= s.META_SHIFT_ON), r.ctrlKey && (a |= s.META_CTRL_ON), r.altKey && (a |= s.META_ALT_ON), r.metaKey && (a |= s.META_META_ON), { keycode: c, metaState: a };
1080
- }
1081
- const jo = xn(
1082
- ({
1083
- className: r,
1084
- url: t,
1085
- token: c,
1086
- sessionId: a,
1087
- openUrl: m,
1088
- showFrame: p = !0,
1089
- deviceModel: g,
1090
- duoModelUrl: C,
1091
- autoReconnect: D = !1,
1092
- onTerminated: O,
1093
- assets: M,
1094
- onConnectionStateChange: S,
1095
- inspectMode: G,
1096
- onAxSnapshotChange: ce,
1097
- onInspectSelectionChange: J,
1098
- onAxStatusChange: he,
1099
- axPollIntervalMs: ee,
1100
- axMaxBackoffMs: X,
1101
- androidElementTreeOptions: Ee,
1102
- onCameraDemandChange: se,
1103
- onCameraStats: H,
1104
- onTrace: ge,
1105
- microphoneEnabled: tt = !1,
1106
- onMicrophoneStateChange: Te
1107
- }, Ue) => {
1108
- const _e = v(null), W = v(null), rt = v(/* @__PURE__ */ new Map()), Ft = v(null), [Wt, Qr] = V(!1), ye = g === "iphone-duo" || Wt, nt = v(null), [sr, ar] = V(null), [ur, lr] = V(), Le = v(
1109
- /* @__PURE__ */ new Map()
1110
- ), Ht = (e, i) => new Promise((o, n) => {
1111
- const l = T.current;
1112
- if (!l || l.readyState !== WebSocket.OPEN) {
1113
- n(new Error("Simulator disconnected"));
1114
- return;
1115
- }
1116
- const u = crypto.randomUUID(), f = setTimeout(() => {
1117
- Le.current.delete(u), n(new Error("Device control timed out"));
1118
- }, 5e3);
1119
- Le.current.set(u, { resolve: o, reject: n, timer: f }), l.send(JSON.stringify({ type: e, id: u, ...i }));
1120
- }), [Zr, $t] = V(!1), [en, yt] = V(!1), [tn, dr] = V(!1), xe = v(!1), Xt = v(!1), [fr, rn] = V(!1), [nn, on] = V(!1), [cn, hr] = V({}), T = v(null), x = v(null), P = v(null), Ct = v(null), Bt = v(ge);
1121
- Bt.current = ge;
1122
- const sn = !!ge, Fe = v(void 0), ot = v(void 0), it = v(void 0), vt = v(void 0), We = v(void 0), Ae = v(0), Ot = v(0), Ce = v(!1), qt = v(D);
1123
- qt.current = D;
1124
- const be = v(null), ne = v(null), Se = v(void 0), Vt = ke(() => new mo(), []), ve = v(se);
1125
- ve.current = se;
1126
- const _t = v(H);
1127
- _t.current = H;
1128
- const ct = v(null), wt = v(null), Gt = v(tt);
1129
- Gt.current = tt;
1130
- const Jt = v(!1), st = v(Te);
1131
- st.current = Te;
1132
- const at = v(null), pe = v(null), Dt = v(0), pr = v(Promise.resolve()), He = v(null), ut = v(!1), we = v(/* @__PURE__ */ new Map()), Oe = v(/* @__PURE__ */ new Map()), Me = v(/* @__PURE__ */ new Map()), Re = v(/* @__PURE__ */ new Map()), Z = v(/* @__PURE__ */ new Map()), Ne = v(!1), [an, un] = V(!1), B = v(null), $e = v(null), lt = v({
1133
- handle: () => {
1134
- },
1135
- end: () => {
1136
- }
1137
- }), [Ie, Tt] = V(null), te = v(null), [mr, Er] = V(null), [jt, dt] = V(null), [zt, At] = V(null), [ln, gr] = V(null), [dn, yr] = V(null), bt = v(null), ae = v(void 0), Cr = (e) => {
1138
- bt.current = e, ae.current === void 0 && (ae.current = window.requestAnimationFrame(() => {
1139
- ae.current = void 0, yr(bt.current);
1140
- }));
1141
- }, [fn, Xe] = V(null), Be = v(G);
1142
- Be.current = G;
1143
- const qe = v(null);
1144
- qe.current = mr;
1145
- const Qt = v(ce);
1146
- Qt.current = ce;
1147
- const Ve = v(J);
1148
- Ve.current = J;
1149
- const vr = v(he);
1150
- vr.current = he;
1151
- const Or = v(O);
1152
- Or.current = O;
1153
- const _r = v(S);
1154
- _r.current = S;
1155
- const Zt = v(null), Ge = (e) => {
1156
- Zt.current !== e && (Zt.current = e, U("onConnectionStateChange", _r.current, e));
1157
- }, ft = G === !0 || G === "hover-only", hn = G === "hover-only" ? "hover-only" : "select", le = ke(
1158
- () => a || Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
1159
- [a]
1160
- ), de = ke(() => Ro(t), [t]), Je = Po[de], ht = M?.[de], wr = de === "android" && nn ? fr ? ht?.tabletFrameLandscape : ht?.tabletFrame : fr ? ht?.frameLandscape : ht?.frame, Dr = ht?.loadingLogo, St = !ye && p && !!wr, K = (e) => {
1161
- F(e);
1162
- }, fe = (e) => {
1163
- !P.current || P.current.readyState !== "open" || (P.current.send(Ct.current?.wrap(e) ?? e), te.current?.bumpActivity());
1164
- }, Tr = -10, Ar = (e, i) => {
1165
- const o = pt();
1166
- if (!o) return;
1167
- const n = ze(o, e, i);
1168
- if (!n) return;
1169
- const { videoX: l, videoY: u, videoWidth: f, videoHeight: E } = n, y = Pt(
1170
- L.ACTION_DOWN,
1171
- Tr,
1172
- f,
1173
- E,
1174
- l,
1175
- u,
1176
- 1,
1177
- L.BUTTON_PRIMARY,
1178
- L.BUTTON_PRIMARY
1179
- );
1180
- y && fe(y), window.setTimeout(() => {
1181
- const h = Pt(
1182
- L.ACTION_UP,
1183
- Tr,
1184
- f,
1185
- E,
1186
- l,
1187
- u,
1188
- 0,
1189
- L.BUTTON_PRIMARY,
1190
- L.BUTTON_PRIMARY
1191
- );
1192
- h && fe(h);
1193
- }, 60);
1194
- }, pn = (e, i) => {
1195
- const o = pt();
1196
- if (!o || i.screen.width <= 0 || i.screen.height <= 0) return;
1197
- const n = e.frame.x + e.frame.width / 2, l = e.frame.y + e.frame.height / 2, u = n / i.screen.width * o.actualWidth, f = l / i.screen.height * o.actualHeight, E = o.videoRect.left + o.offsetX + u, y = o.videoRect.top + o.offsetY + f;
1198
- Ar(E, y);
1199
- }, Mt = -1, Rt = -2, Ye = -3, je = (e, i, o, n, l, u) => {
1200
- const f = Pt(
1201
- e,
1202
- i,
1203
- o,
1204
- n,
1205
- l,
1206
- u,
1207
- 1,
1208
- // pressure
1209
- L.BUTTON_PRIMARY,
1210
- L.BUTTON_PRIMARY
1211
- );
1212
- f && (F("[rc-touch] sendSingleTouch", {
1213
- action: e,
1214
- actionName: Ut(e),
1215
- pointerId: i,
1216
- x: l,
1217
- y: u,
1218
- video: { width: o, height: n }
1219
- }), fe(f));
1220
- }, Ke = (e, i, o) => {
1221
- if (!o) return;
1222
- const { videoX: n, videoY: l, videoWidth: u, videoHeight: f } = o;
1223
- let E = null, y = null, h = 1;
1224
- const R = L.BUTTON_PRIMARY;
1225
- switch (i) {
1226
- case "down":
1227
- e !== Ye && lt.current.end(), E = Z.current.size === 0 ? L.ACTION_DOWN : L.ACTION_POINTER_DOWN, y = { x: n, y: l }, Z.current.set(e, y), e === -1 && W.current?.focus();
1228
- break;
1229
- case "move":
1230
- Z.current.has(e) && (E = L.ACTION_MOVE, y = { x: n, y: l }, Z.current.set(e, y));
1231
- break;
1232
- case "up":
1233
- case "cancel":
1234
- Z.current.has(e) && (y = Z.current.get(e), Z.current.delete(e), i === "cancel" ? E = L.ACTION_CANCEL : E = Z.current.size === 0 ? L.ACTION_UP : L.ACTION_POINTER_UP);
1235
- break;
1236
- }
1237
- if (E !== null && y !== null) {
1238
- F("[rc-touch][mouse->touch] sending", {
1239
- pointerId: e,
1240
- eventType: i,
1241
- action: E,
1242
- actionName: Ut(E),
1243
- positionToSend: y,
1244
- video: { width: u, height: f },
1245
- altHeld: Ne.current,
1246
- activePointersAfter: Array.from(Z.current.entries()).map(([N, $]) => ({
1247
- id: N,
1248
- x: $.x,
1249
- y: $.y
1250
- }))
1251
- });
1252
- const _ = Pt(
1253
- E,
1254
- e,
1255
- u,
1256
- f,
1257
- y.x,
1258
- y.y,
1259
- h,
1260
- R,
1261
- R
1262
- );
1263
- _ && (F("[rc-touch][mouse->touch] buffer", {
1264
- pointerId: e,
1265
- actionName: Ut(E),
1266
- byteLength: _.byteLength
1267
- }), fe(_));
1268
- } else (i === "up" || i === "cancel") && Z.current.delete(e);
1269
- }, er = (e) => {
1270
- if (Ne.current !== e && (Ne.current = e, un(e), e || Tt(null), F("[rc-touch][alt] updateAltHeld", {
1271
- nextHeld: e,
1272
- activePointerIds: Array.from(Z.current.keys())
1273
- }), de === "ios" && P.current && P.current.readyState === "open")) {
1274
- const i = e ? s.ACTION_DOWN : s.ACTION_UP, o = gt(
1275
- i,
1276
- s.KEYCODE_ALT_LEFT,
1277
- 0,
1278
- s.META_NONE
1279
- );
1280
- F("[rc-touch][alt] sending Indigo modifier keycode", {
1281
- action: i,
1282
- keycode: s.KEYCODE_ALT_LEFT
1283
- }), o && fe(o);
1284
- }
1285
- }, pt = () => {
1286
- const e = W.current, i = _e.current;
1287
- if (!e || !i) return null;
1288
- const o = e.videoWidth, n = e.videoHeight;
1289
- if (!o || !n) return null;
1290
- const l = e.getBoundingClientRect(), u = i.getBoundingClientRect(), f = l.width, E = l.height, y = o / n, h = f / E;
1291
- let R = f, _ = E;
1292
- y > h ? _ = f / y : R = E * y;
1293
- const N = (f - R) / 2, $ = (E - _) / 2;
1294
- return {
1295
- videoWidth: o,
1296
- videoHeight: n,
1297
- videoRect: l,
1298
- containerRect: u,
1299
- actualWidth: R,
1300
- actualHeight: _,
1301
- offsetX: N,
1302
- offsetY: $
1303
- };
1304
- }, ze = (e, i, o) => {
1305
- const n = i - e.videoRect.left - e.offsetX, l = o - e.videoRect.top - e.offsetY, u = Math.max(0, Math.min(e.actualWidth, n)), f = Math.max(0, Math.min(e.actualHeight, l)), E = Math.max(
1306
- 0,
1307
- Math.min(e.videoWidth, u / e.actualWidth * e.videoWidth)
1308
- ), y = Math.max(
1309
- 0,
1310
- Math.min(e.videoHeight, f / e.actualHeight * e.videoHeight)
1311
- );
1312
- return {
1313
- videoX: E,
1314
- videoY: y,
1315
- videoWidth: e.videoWidth,
1316
- videoHeight: e.videoHeight
1317
- };
1318
- }, mn = (e, i, o) => {
1319
- const n = i - e.videoRect.left - e.offsetX, l = o - e.videoRect.top - e.offsetY, u = Math.max(0, Math.min(e.actualWidth, n)), f = Math.max(0, Math.min(e.actualHeight, l)), E = Math.max(
1320
- 0,
1321
- Math.min(e.videoWidth, u / e.actualWidth * e.videoWidth)
1322
- ), y = Math.max(
1323
- 0,
1324
- Math.min(e.videoHeight, f / e.actualHeight * e.videoHeight)
1325
- ), h = e.videoWidth - E, R = e.videoHeight - y, _ = e.videoRect.left + e.offsetX, N = e.videoRect.top + e.offsetY, $ = _ - e.containerRect.left + u, oe = N - e.containerRect.top + f, j = _ - e.containerRect.left + (e.actualWidth - u), z = N - e.containerRect.top + (e.actualHeight - f);
1326
- return {
1327
- containerX: $,
1328
- containerY: oe,
1329
- mirrorContainerX: j,
1330
- mirrorContainerY: z,
1331
- videoX: E,
1332
- videoY: y,
1333
- mirrorVideoX: h,
1334
- mirrorVideoY: R,
1335
- videoWidth: e.videoWidth,
1336
- videoHeight: e.videoHeight
1337
- };
1338
- }, En = (e, i, o, n, l, u, f) => {
1339
- const E = Gn(e, i, o, n, l, u, f);
1340
- F("[rc-touch2] sendTwoFingerMessage (iOS)", {
1341
- actionName: Ut(e),
1342
- video: { width: i, height: o },
1343
- p0: { x: n, y: l },
1344
- p1: { x: u, y: f },
1345
- byteLength: E.byteLength
1346
- }), fe(E);
1347
- }, Qe = (e, i, o, n, l, u, f, E, y) => {
1348
- if (F("[rc-touch2] applyTwoFingerEvent", {
1349
- platform: de,
1350
- eventType: e,
1351
- video: { width: i, height: o },
1352
- p0: { x: n, y: l, id: E },
1353
- p1: { x: u, y: f, id: y }
1354
- }), e === "down" && lt.current.end(), de === "ios") {
1355
- const h = e === "down" ? L.ACTION_DOWN : e === "move" ? L.ACTION_MOVE : L.ACTION_UP;
1356
- En(h, i, o, n, l, u, f);
1357
- } else
1358
- e === "down" ? (je(L.ACTION_DOWN, E, i, o, n, l), je(L.ACTION_POINTER_DOWN, y, i, o, u, f)) : e === "move" ? (je(L.ACTION_MOVE, E, i, o, n, l), je(L.ACTION_MOVE, y, i, o, u, f)) : (je(L.ACTION_POINTER_UP, y, i, o, u, f), je(L.ACTION_UP, E, i, o, n, l));
1359
- }, gn = (e, i, o) => {
1360
- if (!Ne.current) {
1361
- Ie !== null && Tt(null);
1362
- return;
1363
- }
1364
- const n = mn(e, i, o);
1365
- Tt(n);
1366
- }, yn = (e, i, o) => {
1367
- const n = qe.current;
1368
- if (!n || n.screen.width <= 0 || n.screen.height <= 0) return null;
1369
- const l = i - e.videoRect.left - e.offsetX, u = o - e.videoRect.top - e.offsetY;
1370
- if (l < 0 || u < 0 || l > e.actualWidth || u > e.actualHeight) return null;
1371
- const f = l / e.actualWidth * n.screen.width, E = u / e.actualHeight * n.screen.height;
1372
- return io(n, f, E);
1373
- }, De = (e) => {
1374
- if (ye) return;
1375
- e.preventDefault(), e.stopPropagation();
1376
- const i = pt();
1377
- if ((Be.current === !0 || Be.current === "hover-only") && !("touches" in e))
1378
- if (e.type === "mousemove") {
1379
- if (Cr({ x: e.clientX, y: e.clientY }), i) {
1380
- const n = yn(i, e.clientX, e.clientY);
1381
- dt(n?.id ?? null);
1382
- }
1383
- } else e.type === "mouseleave" && (Cr(null), dt(null));
1384
- if (Be.current !== !0 && (!("touches" in e) && i && (e.type === "mousemove" ? gn(i, e.clientX, e.clientY) : e.type === "mouseleave" && Tt(null)), !(!P.current || P.current.readyState !== "open" || !W.current || !i)))
1385
- if ("touches" in e) {
1386
- const n = e.touches, l = e.changedTouches;
1387
- let u;
1388
- switch (e.type) {
1389
- case "touchstart":
1390
- u = "down";
1391
- break;
1392
- case "touchmove":
1393
- u = "move";
1394
- break;
1395
- case "touchend":
1396
- u = "up";
1397
- break;
1398
- case "touchcancel":
1399
- u = "cancel";
1400
- break;
1401
- default:
1402
- return;
1403
- }
1404
- if (n.length === 2) {
1405
- const f = n[0], E = n[1], y = ze(i, f.clientX, f.clientY), h = ze(i, E.clientX, E.clientY);
1406
- if (!y || !h) return;
1407
- B.current ? B.current.source === "real-touch" && (B.current.finger0 = { x: y.videoX, y: y.videoY }, B.current.finger1 = { x: h.videoX, y: h.videoY }, Qe(
1408
- "move",
1409
- y.videoWidth,
1410
- y.videoHeight,
1411
- y.videoX,
1412
- y.videoY,
1413
- h.videoX,
1414
- h.videoY,
1415
- B.current.pointerId0,
1416
- B.current.pointerId1
1417
- )) : (B.current = {
1418
- finger0: { x: y.videoX, y: y.videoY },
1419
- finger1: { x: h.videoX, y: h.videoY },
1420
- videoSize: { width: y.videoWidth, height: y.videoHeight },
1421
- source: "real-touch",
1422
- pointerId0: f.identifier,
1423
- pointerId1: E.identifier
1424
- }, Qe(
1425
- "down",
1426
- y.videoWidth,
1427
- y.videoHeight,
1428
- y.videoX,
1429
- y.videoY,
1430
- h.videoX,
1431
- h.videoY,
1432
- f.identifier,
1433
- E.identifier
1434
- ));
1435
- } else if (n.length < 2 && B.current?.source === "real-touch") {
1436
- const f = B.current;
1437
- Qe(
1438
- "up",
1439
- f.videoSize.width,
1440
- f.videoSize.height,
1441
- f.finger0.x,
1442
- f.finger0.y,
1443
- f.finger1.x,
1444
- f.finger1.y,
1445
- f.pointerId0,
1446
- f.pointerId1
1447
- ), B.current = null;
1448
- return;
1449
- } else {
1450
- if (n.length > 2)
1451
- return;
1452
- {
1453
- const f = l[0];
1454
- if (f) {
1455
- const E = ze(i, f.clientX, f.clientY);
1456
- Ke(f.identifier, u, E);
1457
- }
1458
- }
1459
- }
1460
- } else {
1461
- let l = null;
1462
- const u = B.current?.source === "alt-mouse";
1463
- switch (e.type) {
1464
- case "mousedown":
1465
- e.button === 0 && (l = "down");
1466
- break;
1467
- case "mousemove":
1468
- (u || Z.current.has(-1)) && (l = "move");
1469
- break;
1470
- case "mouseup":
1471
- e.button === 0 && (l = "up");
1472
- break;
1473
- case "mouseleave":
1474
- (u || Z.current.has(-1)) && (l = "up");
1475
- break;
1476
- }
1477
- if (l) {
1478
- const f = ze(i, e.clientX, e.clientY);
1479
- if (!f)
1480
- return;
1481
- F("[rc-touch][mouse] event", {
1482
- domType: e.type,
1483
- eventType: l,
1484
- button: e.button,
1485
- buttons: e.buttons,
1486
- client: { x: e.clientX, y: e.clientY },
1487
- altHeldRef: Ne.current,
1488
- inTwoFingerMode: u,
1489
- geometry: {
1490
- videoX: f.videoX,
1491
- videoY: f.videoY,
1492
- videoWidth: f.videoWidth,
1493
- videoHeight: f.videoHeight
1494
- },
1495
- activePointerIds: Array.from(Z.current.keys())
1496
- }), Ne.current || u ? Cn(l, f) : Ke(-1, l, f);
1497
- }
1498
- }
1499
- }, Cn = (e, i) => {
1500
- const { videoX: o, videoY: n, videoWidth: l, videoHeight: u } = i, f = l - o, E = u - n;
1501
- if (e === "down") {
1502
- B.current = {
1503
- finger0: { x: o, y: n },
1504
- finger1: { x: f, y: E },
1505
- videoSize: { width: l, height: u },
1506
- source: "alt-mouse",
1507
- pointerId0: Mt,
1508
- pointerId1: Rt
1509
- }, W.current?.focus(), Qe(
1510
- "down",
1511
- l,
1512
- u,
1513
- o,
1514
- n,
1515
- f,
1516
- E,
1517
- Mt,
1518
- Rt
1519
- );
1520
- return;
1521
- }
1522
- if (e === "move") {
1523
- B.current?.source === "alt-mouse" && (B.current.finger0 = { x: o, y: n }, B.current.finger1 = { x: f, y: E }, Qe(
1524
- "move",
1525
- l,
1526
- u,
1527
- o,
1528
- n,
1529
- f,
1530
- E,
1531
- Mt,
1532
- Rt
1533
- ));
1534
- return;
1535
- }
1536
- if (e === "up" || e === "cancel") {
1537
- const y = B.current;
1538
- if (y?.source === "alt-mouse") {
1539
- const { finger0: h, finger1: R, videoSize: _ } = y;
1540
- Qe(
1541
- "up",
1542
- _.width,
1543
- _.height,
1544
- h.x,
1545
- h.y,
1546
- R.x,
1547
- R.y,
1548
- Mt,
1549
- Rt
1550
- ), B.current = null;
1551
- }
1552
- return;
1553
- }
1554
- }, vn = 150, br = () => {
1555
- const e = $e.current;
1556
- e && (window.clearTimeout(e.endTimer), Ke(Ye, "up", e.pos), $e.current = null);
1557
- }, On = (e) => {
1558
- if (e.ctrlKey || Ne.current || B.current) return;
1559
- const i = Z.current.size;
1560
- if (i > 1 || i === 1 && !Z.current.has(Ye)) return;
1561
- const o = pt();
1562
- if (!o) return;
1563
- const n = e.clientX - o.videoRect.left - o.offsetX, l = e.clientY - o.videoRect.top - o.offsetY;
1564
- if (n < 0 || n > o.actualWidth || l < 0 || l > o.actualHeight)
1565
- return;
1566
- const u = ze(o, e.clientX, e.clientY);
1567
- if (!u) return;
1568
- e.preventDefault();
1569
- const f = (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? o.actualWidth : 1) * (o.videoWidth / o.actualWidth), E = (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? o.actualHeight : 1) * (o.videoHeight / o.actualHeight), y = -e.deltaX * f, h = -e.deltaY * E, R = (z) => {
1570
- window.clearTimeout(z.endTimer), z.endTimer = window.setTimeout(br, vn);
1571
- };
1572
- if (y === 0 && h === 0) {
1573
- $e.current && R($e.current);
1574
- return;
1575
- }
1576
- const _ = () => ({
1577
- videoWidth: u.videoWidth,
1578
- videoHeight: u.videoHeight,
1579
- videoX: Math.abs(y) > Math.abs(h) ? Math.min(Math.max(u.videoX, u.videoWidth * 0.2), u.videoWidth * 0.8) : u.videoX,
1580
- videoY: Math.abs(h) >= Math.abs(y) ? Math.min(Math.max(u.videoY, u.videoHeight * 0.2), u.videoHeight * 0.8) : u.videoY
1581
- }), N = (z) => ({
1582
- ...z,
1583
- videoX: Math.min(Math.max(z.videoX + y, 0), z.videoWidth),
1584
- videoY: Math.min(Math.max(z.videoY + h, 0), z.videoHeight)
1585
- });
1586
- let $ = $e.current;
1587
- if ($)
1588
- window.clearTimeout($.endTimer);
1589
- else {
1590
- const z = _();
1591
- Ke(Ye, "down", z), $ = { pos: z, endTimer: 0 }, $e.current = $;
1592
- }
1593
- let oe = $.pos, j = N(oe);
1594
- j.videoX === oe.videoX && j.videoY === oe.videoY && (Ke(Ye, "up", oe), oe = _(), Ke(Ye, "down", oe), j = N(oe)), Ke(Ye, "move", j), $.pos = j, R($);
1595
- };
1596
- me(() => {
1597
- lt.current = { handle: On, end: br };
1598
- }), me(() => {
1599
- const e = _e.current;
1600
- if (!e) return;
1601
- const i = (o) => lt.current.handle(o);
1602
- return e.addEventListener("wheel", i, { passive: !1 }), () => {
1603
- lt.current.end(), e.removeEventListener("wheel", i);
1604
- };
1605
- }, []), me(() => {
1606
- const e = (n) => {
1607
- n.key === "Alt" && er(!0);
1608
- }, i = (n) => {
1609
- n.key === "Alt" && er(!1);
1610
- }, o = () => {
1611
- er(!1);
1612
- };
1613
- return window.addEventListener("keydown", e, !0), window.addEventListener("keyup", i, !0), window.addEventListener("blur", o), () => {
1614
- window.removeEventListener("keydown", e, !0), window.removeEventListener("keyup", i, !0), window.removeEventListener("blur", o);
1615
- };
1616
- }, []);
1617
- const Nt = (e) => {
1618
- e.preventDefault(), e.stopPropagation();
1619
- const i = document.activeElement === W.current || ye && document.activeElement === e.currentTarget;
1620
- if (F("Keyboard event:", {
1621
- type: e.type,
1622
- key: e.key,
1623
- keyCode: e.keyCode,
1624
- code: e.code,
1625
- target: e.target.tagName,
1626
- focused: i
1627
- }), !i) {
1628
- A("Simulator input not focused, skipping keyboard event");
1629
- return;
1630
- }
1631
- if (!P.current || P.current.readyState !== "open") {
1632
- A("Data channel not ready for keyboard event:", P.current?.readyState);
1633
- return;
1634
- }
1635
- if (e.type === "keydown") {
1636
- if (e.key.toLowerCase() === "v" && (e.metaKey || e.ctrlKey)) {
1637
- F("Paste shortcut detected"), navigator.clipboard.readText().then((n) => {
1638
- if (n) {
1639
- F(
1640
- "Pasting text via SET_CLIPBOARD:",
1641
- n.substring(0, 20) + (n.length > 20 ? "..." : "")
1642
- );
1643
- const l = Jn(n, !0);
1644
- fe(l);
1645
- }
1646
- }).catch((n) => {
1647
- console.error("Failed to read clipboard contents: ", n);
1648
- });
1649
- return;
1650
- }
1651
- if (e.key.toLowerCase() === "m" && (e.metaKey || e.ctrlKey)) {
1652
- F("Menu shortcut detected");
1653
- const n = gt(
1654
- s.ACTION_DOWN,
1655
- s.MENU,
1656
- 0,
1657
- s.META_NONE
1658
- // Modifiers are handled by the shortcut check, not passed down
1659
- );
1660
- fe(n);
1661
- const l = gt(
1662
- s.ACTION_UP,
1663
- s.MENU,
1664
- 0,
1665
- s.META_NONE
1666
- );
1667
- fe(l);
1668
- return;
1669
- }
1670
- }
1671
- const o = Uo(e);
1672
- if (o) {
1673
- const { keycode: n, metaState: l } = o, u = e.type === "keydown" ? s.ACTION_DOWN : s.ACTION_UP;
1674
- F(`Sending Keycode: key=${e.key}, code=${n}, action=${u}, meta=${l}`);
1675
- const f = gt(
1676
- u,
1677
- n,
1678
- 0,
1679
- // repeat count, typically 0 for single presses
1680
- l
1681
- );
1682
- fe(f);
1683
- } else
1684
- F(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`);
1685
- }, _n = () => {
1686
- T.current && T.current.readyState === WebSocket.OPEN && T.current.send(
1687
- JSON.stringify({
1688
- type: "keepAlive",
1689
- sessionId: le
1690
- })
1691
- );
1692
- }, Sr = () => {
1693
- Fe.current && window.clearInterval(Fe.current), Fe.current = window.setInterval(_n, 1e4);
1694
- }, Mr = () => {
1695
- Fe.current && (window.clearInterval(Fe.current), Fe.current = void 0);
1696
- }, It = () => {
1697
- ot.current && (window.clearTimeout(ot.current), ot.current = void 0);
1698
- }, Yt = () => {
1699
- it.current && (window.clearTimeout(it.current), it.current = void 0);
1700
- }, mt = () => {
1701
- vt.current && (window.clearInterval(vt.current), vt.current = void 0);
1702
- }, Et = () => {
1703
- We.current !== void 0 && (window.clearTimeout(We.current), We.current = void 0);
1704
- }, wn = () => {
1705
- ut.current || (ut.current = !0, mt(), $t(!0), Ge("connected"));
1706
- }, re = (e) => {
1707
- for (const i of e.getTracks())
1708
- try {
1709
- i.stop();
1710
- } catch (o) {
1711
- A("track.stop() failed:", o);
1712
- }
1713
- }, Dn = () => {
1714
- const e = ne.current;
1715
- e && (ne.current = null, re(e));
1716
- }, Rr = (e) => {
1717
- const i = pr.current.then(e).catch((o) => {
1718
- A("microphone operation failed:", o);
1719
- });
1720
- return pr.current = i, i;
1721
- }, tr = () => Gt.current || Jt.current, Nr = (e) => {
1722
- const i = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1723
- He.current = i, e.send(JSON.stringify({ type: "microphoneStart", id: i }));
1724
- }, rr = () => Rr(() => Tn()), Tn = async () => {
1725
- const e = Dt.current, i = () => e === Dt.current && tr(), o = (E) => {
1726
- U("onMicrophoneStateChange", st.current, {
1727
- active: !1,
1728
- error: E
1729
- });
1730
- };
1731
- if (!i()) return;
1732
- const n = T.current, l = at.current;
1733
- if (!n || n.readyState !== WebSocket.OPEN || !l || pe.current) return;
1734
- if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
1735
- console.warn(
1736
- "[RemoteControl] navigator.mediaDevices.getUserMedia unavailable. getUserMedia requires a secure context (https or http://localhost)."
1737
- ), o("Microphone capture requires a secure context (https)");
1738
- return;
1739
- }
1740
- let u = null;
1741
- try {
1742
- u = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !1 });
1743
- } catch (E) {
1744
- console.warn("[RemoteControl] microphone getUserMedia denied/failed:", E);
1745
- }
1746
- if (!i()) {
1747
- u && re(u);
1748
- return;
1749
- }
1750
- if (!u) {
1751
- o("Microphone permission denied or no device available");
1752
- return;
1753
- }
1754
- const f = u.getAudioTracks()[0] ?? null;
1755
- if (!f) {
1756
- re(u), o("Captured stream has no audio track");
1757
- return;
1758
- }
1759
- try {
1760
- await l.replaceTrack(f);
1761
- } catch (E) {
1762
- A("replaceTrack(audioTrack) failed:", E), re(u), o("Failed to attach the microphone track to the connection");
1763
- return;
1764
- }
1765
- if (!i()) {
1766
- try {
1767
- await l.replaceTrack(null);
1768
- } catch (E) {
1769
- A("replaceTrack(null) on stale mic attach failed:", E);
1770
- }
1771
- re(u);
1772
- return;
1773
- }
1774
- pe.current = u, f.onended = () => {
1775
- pe.current === u && Kt("microphone capture ended by the browser");
1776
- }, Nr(n), U("onMicrophoneStateChange", st.current, {
1777
- active: !0,
1778
- label: f.label || void 0
1779
- });
1780
- }, Kt = (e) => (++Dt.current, He.current = null, Rr(async () => {
1781
- const i = at.current, o = pe.current;
1782
- if (pe.current = null, i && o)
1783
- try {
1784
- await i.replaceTrack(null);
1785
- } catch (l) {
1786
- A("replaceTrack(null) on mic detach failed:", l);
1787
- }
1788
- o && re(o);
1789
- const n = T.current;
1790
- if (o && n && n.readyState === WebSocket.OPEN) {
1791
- const l = `ui-mic-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
1792
- n.send(JSON.stringify({ type: "microphoneStop", id: l }));
1793
- }
1794
- (o || e) && U("onMicrophoneStateChange", st.current, {
1795
- active: !1,
1796
- ...e !== void 0 && { error: e }
1797
- });
1798
- })), Ir = (e, i) => {
1799
- let o;
1800
- try {
1801
- o = vo(i), console.info(
1802
- `[RemoteControl] camera capture: ${o.camera?.width}x${o.camera?.height} @ ${o.camera?.frameRate ?? "?"}fps` + (o.camera?.label ? ` — ${o.camera.label}` : "")
1803
- );
1804
- } catch (n) {
1805
- A("getSettings() on outbound camera track failed:", n), o = {
1806
- type: "cameraResult",
1807
- granted: !0,
1808
- camera: {
1809
- label: i.label || void 0
1810
- }
1811
- };
1812
- }
1813
- e.send(JSON.stringify(o)), U("onCameraDemandChange", ve.current, !0, !0, o.camera);
1814
- }, An = (e) => {
1815
- if (!e) return;
1816
- const i = e.indexOf("/"), n = (i >= 0 ? e.slice(i + 1) : e).toUpperCase();
1817
- return n === "HEVC" ? "H265" : n;
1818
- }, bn = async () => {
1819
- const e = be.current, i = _t.current;
1820
- if (!e || !i) return;
1821
- let o;
1822
- try {
1823
- o = await e.getStats();
1824
- } catch {
1825
- return;
1826
- }
1827
- let n, l, u;
1828
- if (o.forEach((N) => {
1829
- N.type === "outbound-rtp" && N.kind === "video" ? n = N : N.type === "remote-inbound-rtp" && N.kind === "video" && (u = N);
1830
- }), n?.codecId) {
1831
- const N = o.get(n.codecId);
1832
- N && (l = N.mimeType);
1833
- }
1834
- if (!n) return;
1835
- const f = n.timestamp ?? Date.now(), E = wt.current;
1836
- let y, h, R;
1837
- if (E && f > E.timestamp) {
1838
- const N = (f - E.timestamp) / 1e3;
1839
- if (typeof n.framesEncoded == "number" && typeof E.framesEncoded == "number" && (y = Math.max(0, (n.framesEncoded - E.framesEncoded) / N)), typeof n.bytesSent == "number" && typeof E.bytesSent == "number" && (h = Math.max(0, (n.bytesSent - E.bytesSent) * 8 / N)), typeof n.packetsSent == "number" && typeof E.packetsSent == "number" && u && typeof u.packetsLost == "number" && typeof E.packetsLost == "number") {
1840
- const $ = n.packetsSent - E.packetsSent, oe = u.packetsLost - E.packetsLost;
1841
- $ > 0 && (R = Math.max(0, Math.min(100, oe / $ * 100)));
1842
- }
1843
- }
1844
- wt.current = {
1845
- timestamp: f,
1846
- framesEncoded: n.framesEncoded,
1847
- bytesSent: n.bytesSent,
1848
- packetsSent: n.packetsSent,
1849
- packetsLost: u?.packetsLost
1850
- };
1851
- const _ = {
1852
- codec: An(l),
1853
- encoderImplementation: n.encoderImplementation,
1854
- hardwareAccelerated: typeof n.powerEfficientEncoder == "boolean" ? n.powerEfficientEncoder : void 0,
1855
- framesPerSecond: y,
1856
- framesEncoded: n.framesEncoded,
1857
- bitrateBps: h,
1858
- width: n.frameWidth,
1859
- height: n.frameHeight,
1860
- qualityLimitationReason: n.qualityLimitationReason,
1861
- rttMs: typeof u?.roundTripTime == "number" ? u.roundTripTime * 1e3 : void 0,
1862
- packetsLostPct: R
1863
- };
1864
- U("onCameraStats", _t.current, _);
1865
- }, Yr = () => {
1866
- ct.current === null && (wt.current = null, ct.current = setInterval(() => {
1867
- bn();
1868
- }, 1e3));
1869
- }, kt = () => {
1870
- ct.current !== null && (clearInterval(ct.current), ct.current = null), wt.current = null, U("onCameraStats", _t.current, null);
1871
- }, Sn = (e, i, o, n) => Vt.enqueue(async ({ isCurrent: l }) => {
1872
- const u = () => l() && n() && T.current === i && be.current === o;
1873
- if (!u()) return;
1874
- if (!e.active) {
1875
- const _ = ne.current;
1876
- try {
1877
- await o.replaceTrack(null);
1878
- } catch (N) {
1879
- A("replaceTrack(null) on camera detach failed:", N);
1880
- }
1881
- if (ne.current === _ && (ne.current = null, Se.current = void 0, _ && re(_)), kt(), !u()) return;
1882
- U("onCameraDemandChange", ve.current, !1);
1883
- return;
1884
- }
1885
- U("onCameraDemandChange", ve.current, !0);
1886
- const f = ne.current, E = f?.getVideoTracks()[0], y = Se.current;
1887
- if (E?.readyState === "live" && y && !yo(y, e)) {
1888
- Se.current = e, Ir(i, E), Yr();
1889
- return;
1890
- }
1891
- if (f) {
1892
- try {
1893
- await o.replaceTrack(null);
1894
- } catch (_) {
1895
- A("replaceTrack(null) before camera switch failed:", _);
1896
- }
1897
- if (ne.current === f && (ne.current = null, Se.current = void 0, re(f)), kt(), !u()) return;
1898
- }
1899
- if (!navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
1900
- if (console.warn(
1901
- "[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."
1902
- ), !u()) return;
1903
- i.send(JSON.stringify({ type: "cameraResult", granted: !1 })), U("onCameraDemandChange", ve.current, !0, !1);
1904
- return;
1905
- }
1906
- let h = null;
1907
- try {
1908
- h = await navigator.mediaDevices.getUserMedia({
1909
- video: go(e),
1910
- audio: !1
1911
- });
1912
- } catch (_) {
1913
- console.warn("[RemoteControl] getUserMedia denied/failed:", _);
1914
- }
1915
- if (!u()) {
1916
- h && re(h);
1917
- return;
1918
- }
1919
- if (!h) {
1920
- i.send(JSON.stringify({ type: "cameraResult", granted: !1 })), U("onCameraDemandChange", ve.current, !0, !1);
1921
- return;
1922
- }
1923
- const R = h.getVideoTracks()[0] ?? null;
1924
- if (!R) {
1925
- if (re(h), !u()) return;
1926
- i.send(JSON.stringify({ type: "cameraResult", granted: !1 })), U("onCameraDemandChange", ve.current, !0, !1);
1927
- return;
1928
- }
1929
- try {
1930
- R.contentHint = "motion";
1931
- } catch {
1932
- }
1933
- try {
1934
- await o.replaceTrack(R);
1935
- } catch (_) {
1936
- if (A("replaceTrack(videoTrack) failed:", _), re(h), !u()) return;
1937
- i.send(JSON.stringify({ type: "cameraResult", granted: !1 })), U("onCameraDemandChange", ve.current, !0, !1);
1938
- return;
1939
- }
1940
- if (!u()) {
1941
- try {
1942
- await o.replaceTrack(null);
1943
- } catch (_) {
1944
- A("replaceTrack(null) for stale camera attach failed:", _);
1945
- }
1946
- re(h);
1947
- return;
1948
- }
1949
- try {
1950
- const _ = o.getParameters();
1951
- (!_.encodings || _.encodings.length === 0) && (_.encodings = [{}]), _.encodings[0].maxBitrate = 8e6, _.encodings[0].maxFramerate = 30, _.degradationPreference = "maintain-framerate", await o.setParameters(_);
1952
- } catch (_) {
1953
- A("setParameters on outbound camera failed:", _);
1954
- }
1955
- if (!u()) {
1956
- try {
1957
- await o.replaceTrack(null);
1958
- } catch (_) {
1959
- A("replaceTrack(null) for stale camera finalize failed:", _);
1960
- }
1961
- re(h);
1962
- return;
1963
- }
1964
- ne.current = h, Se.current = e, R.onended = () => {
1965
- ne.current === h && Vt.enqueueCurrent(async ({ isCurrent: _ }) => {
1966
- if (!(!_() || ne.current !== h || !n() || T.current !== i || be.current !== o)) {
1967
- try {
1968
- await o.replaceTrack(null);
1969
- } catch (N) {
1970
- A("replaceTrack(null) after camera ended failed:", N);
1971
- }
1972
- !_() || ne.current !== h || !n() || T.current !== i || be.current !== o || (ne.current = null, Se.current = void 0, re(h), kt(), i.send(JSON.stringify({ type: "cameraResult", granted: !1 })), U("onCameraDemandChange", ve.current, !0, !1));
1973
- }
1974
- }).catch((_) => A("camera ended cleanup failed:", _));
1975
- }, u() && (Ir(i, R), Yr());
1976
- }), Ze = () => {
1977
- for (const e of rt.current.values()) e();
1978
- rt.current.clear();
1979
- for (const e of Le.current.values())
1980
- clearTimeout(e.timer), e.reject(new Error("Simulator disconnected"));
1981
- Le.current.clear(), ar(null), nt.current && (nt.current.srcObject = null), Yt(), Et(), mt(), te.current && (te.current.stop(), te.current = null), Vt.invalidate(), kt(), Dn(), Se.current = void 0, be.current = null, ++Dt.current, Jt.current = !1, He.current = null, pe.current && (re(pe.current), pe.current = null, U("onMicrophoneStateChange", st.current, {
1982
- active: !1
1983
- })), at.current = null, ae.current !== void 0 && (window.cancelAnimationFrame(ae.current), ae.current = void 0), T.current && (T.current.onopen = null, T.current.onmessage = null, T.current.onerror = null, T.current.onclose = null, T.current.close(), T.current = null), Ct.current?.close(), Ct.current = null, x.current && (x.current.onconnectionstatechange = null, x.current.oniceconnectionstatechange = null, x.current.ontrack = null, x.current.onicecandidate = null, x.current.close(), x.current = null), W.current && (W.current.srcObject = null), P.current && (P.current.onopen = null, P.current.onclose = null, P.current.onerror = null, P.current.close(), P.current = null);
1984
- }, Kr = () => {
1985
- document.hidden ? Mr() : Sr();
1986
- }, Mn = async () => {
1987
- if (typeof navigator < "u" && navigator.onLine === !1)
1988
- return !1;
1989
- let e;
1990
- try {
1991
- const n = new URL(t);
1992
- n.protocol = n.protocol === "wss:" ? "https:" : n.protocol === "ws:" ? "http:" : n.protocol, e = Fr(n.toString(), c);
1993
- } catch {
1994
- return !1;
1995
- }
1996
- const i = new AbortController(), o = window.setTimeout(() => i.abort(), Ko);
1997
- try {
1998
- return (await fetch(e, { method: "GET", cache: "no-store", signal: i.signal })).status === 404;
1999
- } catch {
2000
- return !1;
2001
- } finally {
2002
- window.clearTimeout(o);
2003
- }
2004
- }, Rn = () => {
2005
- xe.current || (xe.current = !0, dr(!0), yt(!1), Ae.current += 1, It(), Yt(), Et(), Ze(), K("Instance terminated"), Ge("terminated"), U("onTerminated", Or.current));
2006
- }, Nn = () => {
2007
- xe.current || Xt.current || (Xt.current = !0, Mn().then((e) => {
2008
- Xt.current = !1, e && Rn();
2009
- }));
2010
- }, et = (e, i) => {
2011
- if (xe.current || i !== Ae.current)
2012
- return;
2013
- if (Nn(), Ce.current) {
2014
- if (!qt.current) {
2015
- K(`Connection failed after it was established: ${e}`), yt(!0), Ge("failed"), Ze();
2016
- return;
2017
- }
2018
- K(`Reconnecting after established session dropped: ${e}`), Ce.current = !1, Ot.current = -1;
2019
- }
2020
- It();
2021
- const o = Ot.current + 1;
2022
- if (o >= ir) {
2023
- K(`Connection failed after ${ir} attempts: ${e}`), yt(!0), Ge("failed"), Ze();
2024
- return;
2025
- }
2026
- K(`Retrying connection (${o + 1}/${ir})`), Ge("reconnecting"), Ze(), ot.current = window.setTimeout(() => {
2027
- ot.current = void 0, i === Ae.current && kr(o);
2028
- }, No);
2029
- }, kr = async (e = 0) => {
2030
- if (xe.current) return;
2031
- const i = Ae.current + 1;
2032
- Ae.current = i, Ot.current = e, Ce.current = !1, yt(!1), e === 0 && Zt.current !== "reconnecting" && Ge("connecting"), It(), Yt(), mt(), ut.current = !1, $t(!1), Ze();
2033
- const o = () => i === Ae.current;
2034
- it.current = window.setTimeout(() => {
2035
- it.current = void 0, !(!o() || Ce.current) && et("Connection did not succeed within 15 seconds", i);
2036
- }, Io);
2037
- try {
2038
- const n = new WebSocket(Fr(t, c));
2039
- if (T.current = n, await new Promise((w, d) => {
2040
- let Y = !1;
2041
- const Q = window.setTimeout(() => d(new Error("WebSocket connection timeout")), 3e4), b = (I) => {
2042
- Y || (Y = !0, window.clearTimeout(Q), I());
2043
- };
2044
- n.onopen = () => {
2045
- !o() || T.current !== n || b(w);
2046
- }, n.onerror = (I) => {
2047
- !o() || T.current !== n || (K("WebSocket error: " + I), b(() => d(new Error("WebSocket connection failed"))));
2048
- }, n.onclose = () => {
2049
- !o() || T.current !== n || (K("WebSocket closed"), b(() => d(new Error("WebSocket closed before connection was established"))));
2050
- };
2051
- }), !o() || T.current !== n)
2052
- return;
2053
- n.onerror = (w) => {
2054
- !o() || T.current !== n || K("WebSocket error: " + w);
2055
- }, n.onclose = () => {
2056
- !o() || T.current !== n || K("WebSocket closed");
2057
- };
2058
- const l = new Promise((w, d) => {
2059
- const Y = (I) => {
2060
- window.clearTimeout(Q), n.removeEventListener("message", b), I();
2061
- }, Q = window.setTimeout(
2062
- () => Y(() => d(new Error("RTCConfiguration timeout"))),
2063
- 3e4
2064
- ), b = (I) => {
2065
- if (!(!o() || T.current !== n))
2066
- try {
2067
- const q = JSON.parse(I.data);
2068
- if (q.type === "signalingError" && q.requestType === "requestRtcConfiguration" && q.sessionId === le) {
2069
- const ie = typeof q.error == "string" ? q.error : "Unable to load streaming configuration";
2070
- Y(() => d(new Error(ie)));
2071
- } else q.type === "rtcConfiguration" && Y(
2072
- () => w({
2073
- rtcConfiguration: q.rtcConfiguration,
2074
- cameraSupported: q.cameraSupported === !0,
2075
- foldSupported: q.foldSupported === !0
2076
- })
2077
- );
2078
- } catch (q) {
2079
- console.error("Error handling RTC configuration:", q), Y(() => d(q));
2080
- }
2081
- };
2082
- n.addEventListener("message", b), n.send(
2083
- JSON.stringify({
2084
- type: "requestRtcConfiguration",
2085
- sessionId: le
2086
- })
2087
- );
2088
- }), {
2089
- rtcConfiguration: u,
2090
- cameraSupported: f,
2091
- foldSupported: E
2092
- } = await l;
2093
- if (!o() || T.current !== n)
2094
- return;
2095
- const y = g === "iphone-duo" || E;
2096
- Qr(y);
2097
- const h = new RTCPeerConnection({ ...u, iceTransportPolicy: "relay" });
2098
- x.current = h, h.addTransceiver("audio", { direction: "recvonly" });
2099
- const R = h.addTransceiver("video", { direction: "recvonly" }), _ = y ? h.addTransceiver("video", { direction: "recvonly" }) : null, N = de === "ios" || f, $ = N ? h.addTransceiver("video", {
2100
- direction: "sendonly"
2101
- }) : null;
2102
- be.current = $?.sender ?? null;
2103
- const oe = N ? h.addTransceiver("audio", {
2104
- direction: "sendonly"
2105
- }) : null;
2106
- if (at.current = oe?.sender ?? null, RTCRtpReceiver.getCapabilities) {
2107
- const w = RTCRtpReceiver.getCapabilities("video");
2108
- if (w && w.codecs) {
2109
- const Y = w.codecs.sort((Q, b) => {
2110
- const I = (q) => {
2111
- const ie = q.mimeType.toLowerCase();
2112
- return ie.includes("vp9") ? 1 : ie.includes("h265") || ie.includes("hevc") ? 2 : ie.includes("h264") || ie.includes("avc") ? 3 : 4;
2113
- };
2114
- return I(Q) - I(b);
2115
- });
2116
- R.setCodecPreferences(Y), _?.setCodecPreferences(Y), F("Set codec preferences:", Y.map((Q) => Q.mimeType).join(", "));
2117
- }
2118
- }
2119
- if ($ && RTCRtpSender.getCapabilities) {
2120
- const w = RTCRtpSender.getCapabilities("video");
2121
- if (w && w.codecs) {
2122
- const d = /* @__PURE__ */ new Set(["42e01f", "42e028", "640c1f"]), Y = (b) => {
2123
- const I = b.mimeType.toLowerCase(), ie = (b.sdpFmtpLine || "").toLowerCase().match(/profile-level-id=([0-9a-f]{6})/), Pn = ie ? ie[1] : "";
2124
- return I === "video/h265" || I === "video/hevc" ? 1 : I === "video/h264" && d.has(Pn) ? 2 : I === "video/h264" ? 3 : I === "video/vp9" ? 4 : I === "video/vp8" ? 5 : I === "video/rtx" || I === "video/red" || I === "video/ulpfec" ? 0 : 6;
2125
- }, Q = [...w.codecs].sort((b, I) => Y(b) - Y(I));
2126
- try {
2127
- $.setCodecPreferences(Q), F(
2128
- "Outbound camera codec preferences:",
2129
- Q.map((b) => `${b.mimeType}${b.sdpFmtpLine ? `[${b.sdpFmtpLine}]` : ""}`).join(", ")
2130
- );
2131
- } catch (b) {
2132
- A("Failed to set outbound camera codec preferences:", b);
2133
- }
2134
- }
2135
- }
2136
- const j = h.createDataChannel("control", {
2137
- ordered: !0,
2138
- negotiated: !0,
2139
- id: 1
2140
- });
2141
- P.current = j;
2142
- const z = de === "ios" && !y && Bt.current ? Vn(h, (w) => {
2143
- o() && x.current === h && U("onTrace", Bt.current, w);
2144
- }) : null;
2145
- if (Ct.current = z, j.onopen = () => {
2146
- if (!o() || P.current !== j || T.current !== n)
2147
- return;
2148
- Ce.current = !0, Yt(), K("Control channel opened"), y && n.send(JSON.stringify({ type: "getFoldState", id: "duo-capabilities" })), te.current || (te.current = new po({
2149
- platform: de,
2150
- baseIntervalMs: ee,
2151
- maxBackoffMs: X,
2152
- androidElementTreeOptions: Ee,
2153
- send: (d) => {
2154
- if (!T.current || T.current.readyState !== WebSocket.OPEN) return !1;
2155
- try {
2156
- return T.current.send(JSON.stringify(d)), !0;
2157
- } catch {
2158
- return !1;
2159
- }
2160
- },
2161
- onSnapshot: (d) => {
2162
- Er((Y) => Jr(Y, d) ? Y : d), queueMicrotask(() => {
2163
- U("onAxSnapshotChange", Qt.current, d);
2164
- });
2165
- },
2166
- onStatusChange: (d, Y) => {
2167
- U("onAxStatusChange", vr.current, d, Y);
2168
- }
2169
- }), (Be.current === !0 || Be.current === "hover-only") && te.current.start());
2170
- const w = () => {
2171
- !o() || ut.current || P.current !== j || T.current !== n || n.readyState !== WebSocket.OPEN || n.send(JSON.stringify({ type: "requestFrame", sessionId: le }));
2172
- };
2173
- if (w(), mt(), vt.current = window.setInterval(() => {
2174
- if (!o() || ut.current || P.current !== j || T.current !== n || n.readyState !== WebSocket.OPEN) {
2175
- mt();
2176
- return;
2177
- }
2178
- w();
2179
- }, 250), m) {
2180
- try {
2181
- const d = decodeURIComponent(m);
2182
- K("Opening URL"), n.send(
2183
- JSON.stringify({
2184
- type: "openUrl",
2185
- url: d,
2186
- sessionId: le
2187
- })
2188
- );
2189
- } catch (d) {
2190
- console.error({ error: d }, "Error decoding URL, falling back to the original URL"), n.send(
2191
- JSON.stringify({
2192
- type: "openUrl",
2193
- url: m,
2194
- sessionId: le
2195
- })
2196
- );
2197
- }
2198
- te.current?.bumpActivity();
2199
- }
2200
- }, j.onclose = () => {
2201
- !o() || P.current !== j || K("Control channel closed");
2202
- }, j.onerror = (w) => {
2203
- !o() || P.current !== j || (console.error("Control channel error:", w), K("Control channel error: " + w));
2204
- }, h.onconnectionstatechange = () => {
2205
- !o() || x.current !== h || (K("Connection state: " + h.connectionState), h.connectionState === "failed" && Ce.current && et("WebRTC connection entered failed state", i));
2206
- }, h.oniceconnectionstatechange = () => {
2207
- if (!o() || x.current !== h)
2208
- return;
2209
- const w = h.iceConnectionState;
2210
- if (K("ICE state: " + w), w === "connected" || w === "completed") {
2211
- Et(), tr() && !pe.current && rr();
2212
- return;
2213
- }
2214
- if (w === "failed") {
2215
- Et(), Ce.current && et("ICE connection entered failed state", i);
2216
- return;
2217
- }
2218
- w === "disconnected" && Ce.current && qt.current && We.current === void 0 && (We.current = window.setTimeout(() => {
2219
- We.current = void 0, !(!o() || x.current !== h) && h.iceConnectionState === "disconnected" && et("ICE stayed disconnected past grace period", i);
2220
- }, Yo));
2221
- }, h.ontrack = (w) => {
2222
- if (!(!o() || x.current !== h) && (K("Received remote track: " + w.track.kind), w.track.kind === "video" && W.current)) {
2223
- F(`[${(/* @__PURE__ */ new Date()).toISOString()}] Video track received:`, w.track);
2224
- const Y = w.track.id === "duo-inner" || w.streams.some((Q) => Q.id === "duo-inner") ? nt.current : W.current;
2225
- if (Y) {
2226
- const Q = y ? new MediaStream([w.track]) : w.streams[0] ?? new MediaStream([w.track]);
2227
- rt.current.get(Y)?.(), rt.current.set(
2228
- Y,
2229
- qn(Y, Q, (b) => A("Video playback fallback:", b))
2230
- );
2231
- }
2232
- }
2233
- }, h.onicecandidate = (w) => {
2234
- if (!(!o() || x.current !== h || T.current !== n))
2235
- if (w.candidate && n.readyState === WebSocket.OPEN) {
2236
- const d = {
2237
- type: "candidate",
2238
- candidate: w.candidate.candidate,
2239
- sdpMid: w.candidate.sdpMid,
2240
- sdpMLineIndex: w.candidate.sdpMLineIndex,
2241
- sessionId: le
2242
- };
2243
- n.send(JSON.stringify(d)), K("Sent ICE candidate");
2244
- } else
2245
- K("ICE candidate gathering completed");
2246
- }, n.onmessage = async (w) => {
2247
- if (!o() || T.current !== n)
2248
- return;
2249
- let d;
2250
- try {
2251
- d = JSON.parse(w.data);
2252
- } catch (Y) {
2253
- A("Error parsing message:", Y);
2254
- return;
2255
- }
2256
- if (!te.current?.handleMessage(d))
2257
- switch (K("Received: " + d.type), d.type) {
2258
- case "performActionsResult":
2259
- case "foldStateResult":
2260
- case "foldStateChanged": {
2261
- if (!y) break;
2262
- d.state ? (ar(d.state), lr(void 0)) : d.id === "duo-capabilities" && lr(d.error || "This instance does not support native iPhone Duo displays.");
2263
- const b = Le.current.get(d.id);
2264
- b && (clearTimeout(b.timer), Le.current.delete(d.id), d.error ? b.reject(new Error(d.error)) : b.resolve());
2265
- break;
2266
- }
2267
- case "signalingError": {
2268
- if (d.requestType !== "offer" || d.sessionId !== le)
2269
- break;
2270
- const b = typeof d.error == "string" ? d.error : "Unable to establish the streaming connection";
2271
- K("Error: " + b), et(b, i);
2272
- break;
2273
- }
2274
- case "answer":
2275
- if (!x.current || x.current !== h) {
2276
- K("No peer connection, skipping answer");
2277
- break;
2278
- }
2279
- if (z?.accept(d.latencyTraceVersion), await h.setRemoteDescription(
2280
- new RTCSessionDescription({
2281
- type: "answer",
2282
- sdp: d.sdp
2283
- })
2284
- ), !o() || x.current !== h)
2285
- return;
2286
- K("Set remote description");
2287
- break;
2288
- case "candidate":
2289
- if (!x.current || x.current !== h) {
2290
- K("No peer connection, skipping candidate");
2291
- break;
2292
- }
2293
- if (await h.addIceCandidate(
2294
- new RTCIceCandidate({
2295
- candidate: d.candidate,
2296
- sdpMid: d.sdpMid,
2297
- sdpMLineIndex: d.sdpMLineIndex
2298
- })
2299
- ), !o() || x.current !== h)
2300
- return;
2301
- K("Added ICE candidate");
2302
- break;
2303
- case "screenshot":
2304
- case "screenshotResult": {
2305
- if (typeof d.id != "string") {
2306
- A("Received invalid screenshot success message:", d);
2307
- break;
2308
- }
2309
- const b = Lo(d);
2310
- if (b) {
2311
- const ie = Oe.current.get(d.id);
2312
- if (!ie) {
2313
- A(`Received screenshot error for unknown or handled id: ${d.id}`);
2314
- break;
2315
- }
2316
- A(`Received screenshot error for id ${d.id}: ${b}`), ie(new Error(b)), we.current.delete(d.id), Oe.current.delete(d.id);
2317
- break;
2318
- }
2319
- const I = xo(d);
2320
- if (!I) {
2321
- A("Received screenshot message without image data:", d);
2322
- break;
2323
- }
2324
- const q = we.current.get(d.id);
2325
- if (!q) {
2326
- A(`Received screenshot data for unknown or handled id: ${d.id}`);
2327
- break;
2328
- }
2329
- F(`Received screenshot data for id ${d.id}`), q(I), we.current.delete(d.id), Oe.current.delete(d.id);
2330
- break;
2331
- }
2332
- case "screenshotError":
2333
- if (typeof d.id != "string" || typeof d.message != "string") {
2334
- A("Received invalid screenshot error message:", d);
2335
- break;
2336
- }
2337
- const Y = Oe.current.get(d.id);
2338
- if (!Y) {
2339
- A(`Received screenshot error for unknown or handled id: ${d.id}`);
2340
- break;
2341
- }
2342
- A(`Received screenshot error for id ${d.id}: ${d.message}`), Y(new Error(d.message)), we.current.delete(d.id), Oe.current.delete(d.id);
2343
- break;
2344
- case "cameraRequest": {
2345
- const b = be.current;
2346
- if (!b)
2347
- break;
2348
- const I = Eo(d);
2349
- if (!I) {
2350
- A("Received invalid cameraRequest:", d);
2351
- break;
2352
- }
2353
- console.info("[RemoteControl] cameraRequest received:", I.active, I.facingMode), await Sn(I, n, b, o);
2354
- break;
2355
- }
2356
- case "microphoneRequest": {
2357
- if (!at.current)
2358
- break;
2359
- const b = d.active === !0;
2360
- if (Jt.current = b, console.info("[RemoteControl] microphoneRequest received, active=", b), !b) {
2361
- Gt.current || await Kt();
2362
- break;
2363
- }
2364
- if (pe.current) {
2365
- Nr(n);
2366
- break;
2367
- }
2368
- await rr();
2369
- break;
2370
- }
2371
- case "microphoneStartResult": {
2372
- if (He.current === null || d.id !== He.current)
2373
- break;
2374
- He.current = null, typeof d.error == "string" && (console.warn("[RemoteControl] microphoneStart rejected by host:", d.error), Kt(d.error));
2375
- break;
2376
- }
2377
- case "terminateAppResult":
2378
- if (typeof d.id != "string") {
2379
- A("Received invalid terminateApp result message:", d);
2380
- break;
2381
- }
2382
- if (typeof d.error == "string") {
2383
- const b = Re.current.get(d.id);
2384
- if (!b) {
2385
- A(`Received terminateApp error for unknown or handled id: ${d.id}`);
2386
- break;
2387
- }
2388
- A(`Received terminateApp error for id ${d.id}: ${d.error}`), b(new Error(d.error)), Me.current.delete(d.id), Re.current.delete(d.id);
2389
- break;
2390
- }
2391
- const Q = Me.current.get(d.id);
2392
- if (!Q) {
2393
- A(`Received terminateApp result for unknown or handled id: ${d.id}`);
2394
- break;
2395
- }
2396
- F(`Received terminateApp success for id ${d.id}`), Q(), Me.current.delete(d.id), Re.current.delete(d.id);
2397
- break;
2398
- default:
2399
- A(`Received unhandled message type: ${d.type}`, d);
2400
- break;
2401
- }
2402
- }, x.current === h) {
2403
- const w = await h.createOffer({
2404
- offerToReceiveVideo: !0,
2405
- offerToReceiveAudio: !1
2406
- });
2407
- if (!o() || x.current !== h || (await h.setLocalDescription(w), !o() || x.current !== h))
2408
- return;
2409
- o() && T.current === n && n.readyState === WebSocket.OPEN && n.send(
2410
- JSON.stringify({
2411
- type: "offer",
2412
- ...y ? { displayStreams: !0 } : {},
2413
- ...z ? { latencyTraceVersion: 1 } : {},
2414
- sdp: w.sdp,
2415
- sessionId: le
2416
- })
2417
- ), K("Sent offer");
2418
- }
2419
- } catch (n) {
2420
- if (!o())
2421
- return;
2422
- const l = n instanceof Error ? n.message : String(n);
2423
- K("Error: " + l), et(l, i);
2424
- }
2425
- }, nr = () => {
2426
- xe.current = !1, dr(!1), kr(0);
2427
- }, In = () => {
2428
- Ae.current += 1, Ot.current = 0, Ce.current = !1, It(), Et(), Ze(), K("Stopped");
2429
- }, Yn = (e) => {
2430
- e.stopPropagation(), nr();
2431
- };
2432
- me(() => {
2433
- tr() ? rr() : Kt();
2434
- }, [tt]), me(() => ($t(!1), nr(), document.hidden || Sr(), document.addEventListener("visibilitychange", Kr), () => {
2435
- Mr(), In(), document.removeEventListener("visibilitychange", Kr);
2436
- }), [t, c, a, g, sn]);
2437
- const Pr = () => {
2438
- const e = pt();
2439
- if (!e) {
2440
- gr(null);
2441
- return;
2442
- }
2443
- const i = {
2444
- left: e.videoRect.left - e.containerRect.left + e.offsetX,
2445
- top: e.videoRect.top - e.containerRect.top + e.offsetY,
2446
- width: e.actualWidth,
2447
- height: e.actualHeight
2448
- };
2449
- gr(
2450
- (o) => o && o.left === i.left && o.top === i.top && o.width === i.width && o.height === i.height ? o : i
2451
- );
2452
- };
2453
- me(() => {
2454
- const e = W.current, i = Ft.current, o = _e.current;
2455
- if (!e) return;
2456
- const n = () => {
2457
- if (!St || !i) {
2458
- hr({}), Pr();
2459
- return;
2460
- }
2461
- const f = i.clientWidth, E = i.clientHeight;
2462
- if (f === 0 || E === 0) return;
2463
- const y = e.videoWidth > e.videoHeight;
2464
- rn(y), on(
2465
- de === "android" && ko(e.videoWidth, e.videoHeight)
2466
- );
2467
- const h = y ? Je.videoPosition.landscape : Je.videoPosition.portrait;
2468
- let R = {};
2469
- h.heightMultiplier ? (R.height = `${E * h.heightMultiplier}px`, R.width = "auto") : h.widthMultiplier && (R.width = `${f * h.widthMultiplier}px`, R.height = "auto"), R.borderRadius = `${y ? E * Je.videoBorderRadiusMultiplier : f * Je.videoBorderRadiusMultiplier}px`, hr(R), Pr();
2470
- }, l = new ResizeObserver(() => {
2471
- n();
2472
- });
2473
- i && l.observe(i), l.observe(e), o && l.observe(o), i && i.addEventListener("load", n), e.addEventListener("loadedmetadata", n), e.addEventListener("resize", n);
2474
- const u = () => te.current?.bumpActivity();
2475
- return e.addEventListener("resize", u), n(), () => {
2476
- l.disconnect(), e.removeEventListener("loadedmetadata", n), e.removeEventListener("resize", n), e.removeEventListener("resize", u), i && i.removeEventListener("load", n);
2477
- };
2478
- }, [Je, St]), me(() => {
2479
- const e = te.current;
2480
- ft ? e?.start() : (e?.stop(), Er(null), dt(null), At(null), yr(null), Xe(null), bt.current = null, ae.current !== void 0 && (window.cancelAnimationFrame(ae.current), ae.current = void 0), U("onAxSnapshotChange", Qt.current, null));
2481
- }, [ft]), me(() => () => {
2482
- ae.current !== void 0 && (window.cancelAnimationFrame(ae.current), ae.current = void 0);
2483
- }, []), me(() => {
2484
- if (!ft) return;
2485
- const e = (i) => {
2486
- i.key === "Escape" && (zt || jt) && (At(null), dt(null), Xe(null), U("onInspectSelectionChange", Ve.current, null));
2487
- };
2488
- return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
2489
- }, [ft, zt, jt]);
2490
- const Kn = () => {
2491
- W.current && W.current.focus();
2492
- };
2493
- Fn(Ue, () => ({
2494
- openUrl: (e) => {
2495
- if (!T.current || T.current.readyState !== WebSocket.OPEN) {
2496
- A("WebSocket not open, cannot send open_url command via ref.");
2497
- return;
2498
- }
2499
- try {
2500
- const i = decodeURIComponent(e);
2501
- K("Opening URL"), T.current.send(
2502
- JSON.stringify({
2503
- type: "openUrl",
2504
- url: i,
2505
- sessionId: le
2506
- })
2507
- );
2508
- } catch (i) {
2509
- A("Error decoding or sending URL via ref:", { error: i, url: e }), T.current.send(
2510
- JSON.stringify({
2511
- type: "openUrl",
2512
- url: e,
2513
- sessionId: le
2514
- })
2515
- );
2516
- }
2517
- te.current?.bumpActivity();
2518
- },
2519
- sendKeyEvent: (e) => {
2520
- if (!P.current || P.current.readyState !== "open") {
2521
- A("Data channel not ready for imperative key command:", P.current?.readyState);
2522
- return;
2523
- }
2524
- const i = Br[e.code];
2525
- if (!i) {
2526
- A(`Unknown event.code for imperative command: ${e.code}`);
2527
- return;
2528
- }
2529
- let o = s.META_NONE;
2530
- e.shiftKey && (o |= s.META_SHIFT_ON), e.altKey && (o |= s.META_ALT_ON), e.ctrlKey && (o |= s.META_CTRL_ON), e.metaKey && (o |= s.META_META_ON);
2531
- const n = e.type === "keydown" ? s.ACTION_DOWN : s.ACTION_UP;
2532
- F(
2533
- `Sending Imperative Key Command: code=${e.code}, keycode=${i}, action=${n}, meta=${o}`
2534
- );
2535
- const l = gt(
2536
- n,
2537
- i,
2538
- 0,
2539
- // repeat count, typically 0 for single presses
2540
- o
2541
- );
2542
- l && fe(l);
2543
- },
2544
- screenshot: (e) => new Promise((i, o) => {
2545
- if (!T.current || T.current.readyState !== WebSocket.OPEN)
2546
- return A("WebSocket not open, cannot send screenshot command."), o(new Error("WebSocket is not connected or connection is not open."));
2547
- const n = `ui-ss-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, l = {
2548
- type: e ? "screenshotDisplay" : "screenshot",
2549
- ...e ? { display: e } : {},
2550
- id: n
2551
- };
2552
- we.current.set(n, i), Oe.current.set(n, o), F("Sending screenshot request:", l);
2553
- try {
2554
- T.current.send(JSON.stringify(l));
2555
- } catch (u) {
2556
- A("Failed to send screenshot request immediately:", u), we.current.delete(n), Oe.current.delete(n), o(u);
2557
- return;
2558
- }
2559
- setTimeout(() => {
2560
- we.current.has(n) && (A(`Screenshot request timed out for id ${n}`), Oe.current.get(n)?.(new Error("Screenshot request timed out")), we.current.delete(n), Oe.current.delete(n));
2561
- }, 3e4);
2562
- }),
2563
- terminateApp: (e) => new Promise((i, o) => {
2564
- if (!T.current || T.current.readyState !== WebSocket.OPEN)
2565
- return A("WebSocket not open, cannot send terminateApp command."), o(new Error("WebSocket is not connected or connection is not open."));
2566
- const n = `ui-term-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`, l = {
2567
- type: "terminateApp",
2568
- id: n,
2569
- bundleId: e
2570
- };
2571
- Me.current.set(n, i), Re.current.set(n, o), F("Sending terminateApp request:", l);
2572
- try {
2573
- T.current.send(JSON.stringify(l));
2574
- } catch (u) {
2575
- A("Failed to send terminateApp request immediately:", u), Me.current.delete(n), Re.current.delete(n), o(u);
2576
- return;
2577
- }
2578
- te.current?.bumpActivity(), setTimeout(() => {
2579
- Me.current.has(n) && (A(`terminateApp request timed out for id ${n}`), Re.current.get(n)?.(new Error("terminateApp request timed out")), Me.current.delete(n), Re.current.delete(n));
2580
- }, 3e4);
2581
- }),
2582
- reconnect: () => nr(),
2583
- refreshAxTree: async () => {
2584
- const e = te.current;
2585
- if (!e)
2586
- throw new Error("Inspect mode is not active");
2587
- return e.refresh();
2588
- },
2589
- getAxSnapshot: () => qe.current,
2590
- setInspectHighlight: (e) => {
2591
- dt(e?.id ?? null);
2592
- },
2593
- setInspectSelection: (e) => {
2594
- At(e?.id ?? null), Xe(e ? bt.current : null);
2595
- const i = qe.current;
2596
- e && i ? U("onInspectSelectionChange", Ve.current, { element: e, snapshot: i }) : U("onInspectSelectionChange", Ve.current, null);
2597
- },
2598
- getAxStatus: () => te.current?.getStatus() ?? "idle"
2599
- }));
2600
- const kn = an && Ie !== null;
2601
- return /* @__PURE__ */ ue(
2602
- "div",
2603
- {
2604
- ref: _e,
2605
- className: Pe("rc-container", r),
2606
- style: { touchAction: "none" },
2607
- onMouseDown: De,
2608
- onMouseMove: De,
2609
- onMouseUp: De,
2610
- onMouseLeave: De,
2611
- onTouchStart: De,
2612
- onTouchMove: De,
2613
- onTouchEnd: De,
2614
- onTouchCancel: De,
2615
- children: [
2616
- kn && Ie && /* @__PURE__ */ ue($r, { children: [
2617
- /* @__PURE__ */ k(
2618
- "div",
2619
- {
2620
- className: "rc-touch-indicator",
2621
- style: {
2622
- left: `${Ie.containerX}px`,
2623
- top: `${Ie.containerY}px`
2624
- }
2625
- }
2626
- ),
2627
- /* @__PURE__ */ k(
2628
- "div",
2629
- {
2630
- className: "rc-touch-indicator",
2631
- style: {
2632
- left: `${Ie.mirrorContainerX}px`,
2633
- top: `${Ie.mirrorContainerY}px`
2634
- }
2635
- }
2636
- )
2637
- ] }),
2638
- St && /* @__PURE__ */ k(
2639
- "img",
2640
- {
2641
- ref: Ft,
2642
- src: wr,
2643
- alt: "",
2644
- className: de === "ios" ? Pe("rc-phone-frame", "rc-phone-frame-ios") : "rc-phone-frame",
2645
- draggable: !1
2646
- }
2647
- ),
2648
- /* @__PURE__ */ k(
2649
- "video",
2650
- {
2651
- ref: W,
2652
- className: Pe(
2653
- "rc-video",
2654
- !St && "rc-video-frameless",
2655
- !Zr && "rc-video-loading"
2656
- ),
2657
- style: {
2658
- ...cn,
2659
- ...ye ? { opacity: 0, width: 1, height: 1, pointerEvents: "none" } : {},
2660
- ...Dr ? {
2661
- backgroundImage: `url("${Dr}")`,
2662
- backgroundRepeat: "no-repeat",
2663
- backgroundPosition: "center",
2664
- backgroundSize: Je.loadingLogoSize
2665
- } : {}
2666
- },
2667
- autoPlay: !0,
2668
- playsInline: !0,
2669
- muted: !0,
2670
- tabIndex: ye ? -1 : 0,
2671
- onKeyDown: Nt,
2672
- onKeyUp: Nt,
2673
- onClick: Kn,
2674
- onLoadedData: wn,
2675
- onFocus: () => {
2676
- W.current && (W.current.style.outline = "none");
2677
- },
2678
- onBlur: () => {
2679
- W.current && (W.current.style.outline = "none");
2680
- }
2681
- }
2682
- ),
2683
- ye && /* @__PURE__ */ k(
2684
- "video",
2685
- {
2686
- ref: nt,
2687
- autoPlay: !0,
2688
- playsInline: !0,
2689
- muted: !0,
2690
- style: { position: "absolute", width: 1, height: 1, opacity: 0, pointerEvents: "none" }
2691
- }
2692
- ),
2693
- ye && sr && /* @__PURE__ */ k(Wn, { fallback: /* @__PURE__ */ k("div", { children: "Loading iPhone Duo…" }), children: /* @__PURE__ */ k(
2694
- Mo,
2695
- {
2696
- showFrame: p,
2697
- modelUrl: C,
2698
- outer: W.current,
2699
- inner: nt.current,
2700
- state: sr,
2701
- setAngle: (e) => Ht("setHingeAngle", { angleDegrees: e }),
2702
- setOrientation: (e) => Ht("setDuoOrientation", { orientation: e }),
2703
- button: (e, i) => Ht("performActions", {
2704
- actions: [{ type: i ? "buttonDown" : "buttonUp", button: e }]
2705
- }),
2706
- touch: (e, i, o, n) => {
2707
- const l = P.current;
2708
- l?.readyState === "open" && l.send(Xn(e, i, o, n));
2709
- },
2710
- onKeyDown: Nt,
2711
- onKeyUp: Nt
2712
- }
2713
- ) }),
2714
- ye && ur && /* @__PURE__ */ k("div", { role: "alert", className: "rc-duo-error", children: ur }),
2715
- !ye && ft && /* @__PURE__ */ k(
2716
- So,
2717
- {
2718
- snapshot: mr,
2719
- geometry: ln,
2720
- highlightedId: jt,
2721
- selectedId: zt,
2722
- mode: hn,
2723
- cursorPosition: dn,
2724
- frozenCursorPosition: fn,
2725
- onSelectChange: (e, i) => {
2726
- At(e?.id ?? null), e && i ? Xe(i) : e || Xe(null);
2727
- const o = qe.current;
2728
- e && o ? U("onInspectSelectionChange", Ve.current, {
2729
- element: e,
2730
- snapshot: o
2731
- }) : U("onInspectSelectionChange", Ve.current, null);
2732
- },
2733
- onTapElement: (e, i) => {
2734
- if (i) {
2735
- Ar(i.x, i.y);
2736
- return;
2737
- }
2738
- const o = qe.current;
2739
- o && pn(e, o);
2740
- }
2741
- }
2742
- ),
2743
- tn ? /* @__PURE__ */ ue("div", { className: "rc-terminated", role: "status", children: [
2744
- /* @__PURE__ */ k("div", { className: "rc-terminated-title", children: "Instance terminated" }),
2745
- /* @__PURE__ */ k("div", { className: "rc-terminated-message", children: "This instance no longer exists and can't be reconnected." })
2746
- ] }) : en && /* @__PURE__ */ k("button", { type: "button", className: "rc-retry-button", onClick: Yn, children: "Retry" })
2747
- ]
2748
- }
2749
- );
2750
- }
2751
- ), Lo = (r) => typeof r.message == "string" ? r.message : typeof r.error == "string" ? r.error : null, xo = (r) => typeof r.dataUri == "string" ? { dataUri: r.dataUri } : typeof r.base64 == "string" ? r.base64.startsWith("data:") ? { dataUri: r.base64 } : { dataUri: `data:${r.base64.startsWith("/9j/") ? "image/jpeg" : "image/png"};base64,${r.base64}` } : null;
2752
- export {
2753
- or as A,
2754
- $o as D,
2755
- Vo as H,
2756
- jo as R,
2757
- io as a,
2758
- co as b,
2759
- zr as c,
2760
- Gr as d,
2761
- Jr as e,
2762
- oo as f,
2763
- eo as g,
2764
- Jo as h,
2765
- Go as i,
2766
- Xo as j,
2767
- qo as k,
2768
- no as n,
2769
- Bo as p
2770
- };