@limrun/ui 0.20.8 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1299 @@
1
+ import { jsx as m, jsxs as V, Fragment as Pt } from "react/jsx-runtime";
2
+ import { f as un, c as kt, d as hn, b as fn, h as pn, i as mn, j as It, s as Me, k as gn, l as yn, M as Ne, e as vn, m as wn, o as X, p as ot, q as bn, r as An, t as Be, u as S, v as Ke, a as Tn, w as Cn, x as v, y as Rn } from "./core-CRIachT9.mjs";
3
+ import { memo as it, useState as R, useEffect as K, useMemo as me, useCallback as Yt, lazy as Mn, forwardRef as Nn, useRef as O, useImperativeHandle as En, Suspense as In } from "react";
4
+ import { createPortal as On } from "react-dom";
5
+ import './index.css';const Sn = async (u) => {
6
+ if (!u) return !1;
7
+ try {
8
+ if (typeof navigator < "u" && navigator.clipboard?.writeText)
9
+ return await navigator.clipboard.writeText(u), !0;
10
+ } catch {
11
+ }
12
+ try {
13
+ const i = document.createElement("textarea");
14
+ i.value = u, i.style.position = "fixed", i.style.opacity = "0", document.body.appendChild(i), i.select();
15
+ const h = document.execCommand("copy");
16
+ return document.body.removeChild(i), h;
17
+ } catch {
18
+ return !1;
19
+ }
20
+ }, _n = it(
21
+ function({ element: i, screen: h, highlighted: f, selected: M, selectable: j, onClick: N }) {
22
+ const p = un(i.frame, h);
23
+ if (!p) return null;
24
+ const z = kt(i);
25
+ return /* @__PURE__ */ m(
26
+ "button",
27
+ {
28
+ type: "button",
29
+ className: i.enabled ? "rc-inspect-box" : "rc-inspect-box rc-inspect-box-disabled",
30
+ "data-ax-id": i.id,
31
+ "data-ax-path": i.path,
32
+ "data-ax-label": i.label || void 0,
33
+ "data-ax-role": i.role || void 0,
34
+ "data-highlighted": f ? "true" : "false",
35
+ "data-selected": M ? "true" : "false",
36
+ "aria-label": z,
37
+ onClick: (w) => {
38
+ j && (w.preventDefault(), w.stopPropagation(), N(i, { x: w.clientX, y: w.clientY }));
39
+ },
40
+ style: {
41
+ left: `${p.x / h.width * 100}%`,
42
+ top: `${p.y / h.height * 100}%`,
43
+ width: `${p.width / h.width * 100}%`,
44
+ height: `${p.height / h.height * 100}%`
45
+ }
46
+ }
47
+ );
48
+ },
49
+ (u, i) => u.highlighted === i.highlighted && u.selected === i.selected && u.selectable === i.selectable && u.screen.width === i.screen.width && u.screen.height === i.screen.height && u.onClick === i.onClick && hn(u.element, i.element)
50
+ ), Pn = 260, kn = 220, Yn = 6, Dn = 8, Ln = it(function({
51
+ element: i,
52
+ platform: h,
53
+ anchor: f,
54
+ cursorAnchored: M,
55
+ showActions: j,
56
+ onTap: N
57
+ }) {
58
+ const [p, z] = R(null);
59
+ K(() => {
60
+ if (!p) return;
61
+ const C = window.setTimeout(() => z(null), 1100);
62
+ return () => window.clearTimeout(C);
63
+ }, [p]);
64
+ const w = me(() => {
65
+ const C = Pn, q = kn, U = Yn, b = Dn, Z = typeof window < "u" ? window.innerWidth : 1024, ke = typeof window < "u" ? window.innerHeight : 768, J = f.x + U + C <= Z - b, ne = f.y - U - q >= b;
66
+ let se = J ? f.x + U : f.x - U, ge = ne ? f.y - U : f.y + U;
67
+ const oe = `translate(${J ? "0" : "-100%"}, ${ne ? "-100%" : "0"})`;
68
+ return se = Math.max(b + (J ? 0 : C), Math.min(Z - b - (J ? C : 0), se)), ge = Math.max(b + (ne ? q : 0), Math.min(ke - b - (ne ? 0 : q), ge)), { left: `${se}px`, top: `${ge}px`, transform: oe };
69
+ }, [f.x, f.y]), _ = me(() => fn(i, h), [i, h]), E = h === "ios" ? i.selectors.AXUniqueId : i.selectors.resourceId, W = h === "ios" ? "AXUniqueId" : "resourceId", Q = Yt(async (C, q) => {
70
+ if (!C) return;
71
+ await Sn(C) && z(q);
72
+ }, []), te = pn(i), B = i.label || i.value || te, ce = kt(i);
73
+ return On(
74
+ /* @__PURE__ */ V(
75
+ "div",
76
+ {
77
+ className: "rc-inspect-card",
78
+ "data-cursor-anchored": M ? "true" : "false",
79
+ style: w,
80
+ onClick: (C) => C.stopPropagation(),
81
+ onMouseDown: (C) => C.stopPropagation(),
82
+ onMouseMove: (C) => C.stopPropagation(),
83
+ children: [
84
+ /* @__PURE__ */ V("div", { className: "rc-inspect-card-header", children: [
85
+ /* @__PURE__ */ m("span", { className: "rc-inspect-card-role", children: te }),
86
+ !i.enabled && /* @__PURE__ */ m("span", { className: "rc-inspect-card-tag", children: "disabled" }),
87
+ i.focused && /* @__PURE__ */ m("span", { className: "rc-inspect-card-tag rc-inspect-card-tag-blue", children: "focused" })
88
+ ] }),
89
+ /* @__PURE__ */ m("p", { className: "rc-inspect-card-title", title: ce, children: B }),
90
+ E && /* @__PURE__ */ V("div", { className: "rc-inspect-card-row", children: [
91
+ /* @__PURE__ */ V("span", { className: "rc-inspect-card-row-label", children: [
92
+ W,
93
+ ":"
94
+ ] }),
95
+ /* @__PURE__ */ m("span", { className: "rc-inspect-card-row-value", children: E })
96
+ ] }),
97
+ i.value && i.value !== i.label && /* @__PURE__ */ V("div", { className: "rc-inspect-card-row", children: [
98
+ /* @__PURE__ */ m("span", { className: "rc-inspect-card-row-label", children: "value:" }),
99
+ /* @__PURE__ */ m("span", { className: "rc-inspect-card-row-value", children: i.value })
100
+ ] }),
101
+ /* @__PURE__ */ V("div", { className: "rc-inspect-card-row", children: [
102
+ /* @__PURE__ */ m("span", { className: "rc-inspect-card-row-label", children: "frame:" }),
103
+ /* @__PURE__ */ V("span", { className: "rc-inspect-card-row-value", children: [
104
+ Math.round(i.frame.width),
105
+ "×",
106
+ Math.round(i.frame.height),
107
+ " @ ",
108
+ Math.round(i.frame.x),
109
+ ",",
110
+ Math.round(i.frame.y)
111
+ ] })
112
+ ] }),
113
+ j && /* @__PURE__ */ V("div", { className: "rc-inspect-card-actions", children: [
114
+ /* @__PURE__ */ m(
115
+ "button",
116
+ {
117
+ type: "button",
118
+ className: "rc-inspect-card-btn rc-inspect-card-btn-primary",
119
+ disabled: !N,
120
+ onClick: () => N?.(i, f),
121
+ children: "Tap"
122
+ }
123
+ ),
124
+ /* @__PURE__ */ m(
125
+ "button",
126
+ {
127
+ type: "button",
128
+ className: p === "selector" ? "rc-inspect-card-btn rc-inspect-card-btn-copied" : "rc-inspect-card-btn",
129
+ disabled: !_,
130
+ title: _ ?? "No usable selector for this element",
131
+ onClick: () => Q(_ ?? void 0, "selector"),
132
+ children: p === "selector" ? "Copied!" : "Copy selector"
133
+ }
134
+ ),
135
+ /* @__PURE__ */ m(
136
+ "button",
137
+ {
138
+ type: "button",
139
+ className: p === "id" ? "rc-inspect-card-btn rc-inspect-card-btn-copied" : "rc-inspect-card-btn",
140
+ disabled: !E,
141
+ title: E ?? `No ${W}`,
142
+ onClick: () => Q(E, "id"),
143
+ children: p === "id" ? "Copied!" : `Copy ${W}`
144
+ }
145
+ )
146
+ ] })
147
+ ]
148
+ }
149
+ ),
150
+ document.body
151
+ );
152
+ }), Xn = it(function({
153
+ snapshot: i,
154
+ geometry: h,
155
+ highlightedId: f,
156
+ selectedId: M,
157
+ mode: j,
158
+ cursorPosition: N,
159
+ frozenCursorPosition: p,
160
+ onSelectChange: z,
161
+ onTapElement: w
162
+ }) {
163
+ const _ = j === "select", E = _ ? f !== null && f !== M : f !== null, W = _ ? f ?? M : f, Q = me(() => {
164
+ const b = /* @__PURE__ */ new Map();
165
+ if (!i) return b;
166
+ for (const Z of i.elements) b.set(Z.id, Z);
167
+ return b;
168
+ }, [i]), te = me(() => W ? Q.get(W) ?? null : null, [W, Q]);
169
+ if (!(!!i && !!h && i.screen.width > 0 && i.screen.height > 0 && i.elements.length > 0)) return null;
170
+ const ce = E ? N : p ?? N, C = E, q = _ && !E && M !== null, U = (b) => {
171
+ _ && b.target === b.currentTarget && z(null, null);
172
+ };
173
+ return /* @__PURE__ */ V(Pt, { children: [
174
+ /* @__PURE__ */ m(
175
+ "div",
176
+ {
177
+ className: _ ? "rc-inspect-overlay rc-inspect-overlay-select" : "rc-inspect-overlay",
178
+ style: {
179
+ left: `${h.left}px`,
180
+ top: `${h.top}px`,
181
+ width: `${h.width}px`,
182
+ height: `${h.height}px`
183
+ },
184
+ onClick: U,
185
+ children: i.elements.map((b) => /* @__PURE__ */ m(
186
+ _n,
187
+ {
188
+ element: b,
189
+ screen: i.screen,
190
+ highlighted: b.id === f,
191
+ selected: b.id === M,
192
+ selectable: _,
193
+ onClick: z
194
+ },
195
+ b.id
196
+ ))
197
+ }
198
+ ),
199
+ te && ce && /* @__PURE__ */ m(
200
+ Ln,
201
+ {
202
+ element: te,
203
+ platform: i.platform,
204
+ anchor: ce,
205
+ cursorAnchored: C,
206
+ showActions: q,
207
+ onTap: w
208
+ }
209
+ )
210
+ ] });
211
+ });
212
+ function Wn(u, i) {
213
+ if (!i.startsWith("lim_st_")) return !1;
214
+ try {
215
+ const h = new URL(u).pathname.split("/").map(decodeURIComponent).find((w) => /^(ios|android)_[a-z0-9_]+$/.test(w));
216
+ if (!h) return !1;
217
+ const f = h.split("_")[0], M = i.slice(7).split(".");
218
+ if (M.length !== 3 || M.some((w) => !w)) return !1;
219
+ const j = atob(M[1].replace(/-/g, "+").replace(/_/g, "/")), N = JSON.parse(
220
+ new TextDecoder().decode(Uint8Array.from(j, (w) => w.charCodeAt(0)))
221
+ );
222
+ if (!N || typeof N != "object" || !("scopes" in N)) return !1;
223
+ const p = N.scopes;
224
+ if (!Array.isArray(p) || !p.every((w) => typeof w == "string")) return !1;
225
+ let z = !1;
226
+ for (const w of p) {
227
+ const [_, E, W, Q] = w.split(":");
228
+ if (!(Q !== void 0 || _ !== f && _ !== "*") && !(E !== h && E !== "*")) {
229
+ if (W === "stream" || W === "all") return !1;
230
+ W === "watch" && (z = !0);
231
+ }
232
+ }
233
+ return z;
234
+ } catch {
235
+ return !1;
236
+ }
237
+ }
238
+ const Hn = Mn(() => import("./duo-view-BeqYIqfQ.mjs").then((u) => u.d)), Ve = (u) => Object.entries(v).find(
239
+ ([h, f]) => h.startsWith("ACTION_") && f === u
240
+ )?.[0] ?? String(u), Ot = 1920, St = 1200, xn = (u, i) => u === Ot && i === St || u === St && i === Ot, Un = {
241
+ ios: {
242
+ videoBorderRadiusMultiplier: 0.15,
243
+ loadingLogoSize: "20%",
244
+ // Video position as percentage of frame dimensions
245
+ videoPosition: {
246
+ portrait: { heightMultiplier: 0.9678 },
247
+ landscape: { widthMultiplier: 0.9678 }
248
+ }
249
+ },
250
+ android: {
251
+ videoBorderRadiusMultiplier: 0.13,
252
+ loadingLogoSize: "40%",
253
+ // Video position as percentage of frame dimensions
254
+ videoPosition: {
255
+ portrait: { heightMultiplier: 0.967 },
256
+ landscape: { widthMultiplier: 0.962 }
257
+ }
258
+ },
259
+ // A macOS virtual machine is a desktop display: no device frame around it.
260
+ macos: {
261
+ videoBorderRadiusMultiplier: 0,
262
+ loadingLogoSize: "10%",
263
+ videoPosition: {
264
+ portrait: { heightMultiplier: 1 },
265
+ landscape: { widthMultiplier: 1 }
266
+ }
267
+ }
268
+ }, $n = {
269
+ "iphone-se": {
270
+ videoBorderRadiusMultiplier: 0,
271
+ loadingLogoSize: "20%",
272
+ videoPosition: {
273
+ portrait: { heightMultiplier: 667 / 889 },
274
+ landscape: { widthMultiplier: 667 / 889 }
275
+ },
276
+ // The SE has no home indicator, so its frame's home button is the way home: 64 points across,
277
+ // centered in the bottom bezel 389 points below the frame's center.
278
+ homeButton: { offset: 389 / 889, diameter: 64 / 889 }
279
+ },
280
+ "iphone-17e": {
281
+ videoBorderRadiusMultiplier: 47.33 / 452,
282
+ loadingLogoSize: "20%",
283
+ videoPosition: {
284
+ portrait: { heightMultiplier: 844 / 888 },
285
+ landscape: { widthMultiplier: 844 / 888 }
286
+ }
287
+ }
288
+ }, Fn = {
289
+ videoBorderRadiusMultiplier: 32 / 1837,
290
+ loadingLogoSize: "40%",
291
+ videoPosition: {
292
+ portrait: { heightMultiplier: 2560 / 2798 },
293
+ landscape: { widthMultiplier: 2560 / 2798 }
294
+ }
295
+ };
296
+ function zn(u) {
297
+ const i = u.code, h = Cn[i];
298
+ if (!h)
299
+ return ot(`Unknown event.code: ${i}, key: ${u.key}`), null;
300
+ let f = S.META_NONE;
301
+ const M = i >= "KeyA" && i <= "KeyZ", j = u.getModifierState("CapsLock"), N = u.shiftKey;
302
+ let p = N;
303
+ return M && (p = N !== j), p && (f |= S.META_SHIFT_ON), u.ctrlKey && (f |= S.META_CTRL_ON), u.altKey && (f |= S.META_ALT_ON), u.metaKey && (f |= S.META_META_ON), { keycode: h, metaState: f };
304
+ }
305
+ function _t(u, i) {
306
+ const h = Object.keys(u);
307
+ return h.length === Object.keys(i).length && h.every((f) => u[f] === i[f]);
308
+ }
309
+ const Gn = Nn(
310
+ ({
311
+ className: u,
312
+ url: i,
313
+ token: h,
314
+ sessionId: f,
315
+ openUrl: M,
316
+ watchOnly: j = !1,
317
+ showFrame: N = !0,
318
+ deviceModel: p,
319
+ duoModelUrl: z,
320
+ autoReconnect: w,
321
+ jitterBufferTargetMs: _,
322
+ onPlaybackStats: E,
323
+ onTerminated: W,
324
+ assets: Q,
325
+ onConnectionStateChange: te,
326
+ inspectMode: B,
327
+ onAxSnapshotChange: ce,
328
+ onInspectSelectionChange: C,
329
+ onAxStatusChange: q,
330
+ axPollIntervalMs: U,
331
+ axMaxBackoffMs: b,
332
+ androidElementTreeOptions: Z,
333
+ onCameraDemandChange: ke,
334
+ onCameraStats: J,
335
+ onTrace: ne,
336
+ microphoneEnabled: se = !1,
337
+ onMicrophoneStateChange: ge
338
+ }, rt) => {
339
+ const ct = me(() => Wn(i, h), [i, h]), oe = j || ct, Ye = O(null), P = O(null), st = O(null), [Dt, Lt] = R(!1), G = p === "iphone-duo" || Dt, De = p === "iphone-duo" ? p : void 0, Le = O(null), [at, Xt] = R(null), [lt, Wt] = R(), [Ht, xt] = R(!1), [Ut, $t] = R(!1), [Ft, zt] = R(!1), [je, dt] = R(!1), [ut, ht] = R(!1), [Bt, ft] = R({}), [pt, mt] = R(null), Ge = O(null), Y = O(/* @__PURE__ */ new Map()), ae = O(!1), [Kt, Vt] = R(!1), I = O(null), ye = O(null), Ee = O({
340
+ handle: () => {
341
+ },
342
+ end: () => {
343
+ }
344
+ }), [le, Xe] = R(null), [gt, qe] = R(null), [Je, Ie] = R(null), [Qe, We] = R(null), [jt, yt] = R(null), [Gt, vt] = R(null), He = O(null), ee = O(void 0), wt = (e) => {
345
+ He.current = e, ee.current === void 0 && (ee.current = window.requestAnimationFrame(() => {
346
+ ee.current = void 0, vt(He.current);
347
+ }));
348
+ }, [qt, ve] = R(null), de = O(null);
349
+ de.current = gt;
350
+ const we = O(C);
351
+ we.current = C;
352
+ const ue = B === !0 || B === "hover-only", bt = O(ue);
353
+ bt.current = ue;
354
+ const Jt = B === "hover-only" ? "hover-only" : "select", D = me(() => mn(i), [i]), Qt = me(
355
+ () => f || Array.from(crypto.getRandomValues(new Uint32Array(4)), (e) => e.toString(36)).join(""),
356
+ [f]
357
+ ), Oe = D === "ios" && p && p !== "iphone-duo" ? p : void 0, he = D === "android" && ut ? Fn : Oe ? $n[Oe] : Un[D], be = Q?.[D], At = Oe && be?.modelFrames?.[Oe], Tt = D === "android" && ut ? je ? be?.tabletFrameLandscape : be?.tabletFrame : Oe ? je ? At?.frameLandscape : At?.frame : je ? be?.frameLandscape : be?.frame, Ct = be?.loadingLogo, Se = !G && N && !!Tt, y = O(null), $ = (e) => y.current?.sendControl(e), xe = O(/* @__PURE__ */ new Set()), Ue = Yt(() => {
358
+ for (const e of xe.current)
359
+ y.current?.sendControl(It(Ne.UP, e));
360
+ xe.current.clear();
361
+ }, []), Ze = (e, n) => y.current?.sendDuoControl(e, n) ?? Promise.reject(new Error("Simulator disconnected")), Rt = -10, Mt = (e, n) => {
362
+ const o = Te();
363
+ if (!o) return;
364
+ const t = ie(o, e, n);
365
+ if (!t) return;
366
+ const { videoX: s, videoY: r, videoWidth: c, videoHeight: l } = t, a = Ke(
367
+ v.ACTION_DOWN,
368
+ Rt,
369
+ c,
370
+ l,
371
+ s,
372
+ r,
373
+ 1,
374
+ v.BUTTON_PRIMARY,
375
+ v.BUTTON_PRIMARY
376
+ );
377
+ a && $(a), window.setTimeout(() => {
378
+ const d = Ke(
379
+ v.ACTION_UP,
380
+ Rt,
381
+ c,
382
+ l,
383
+ s,
384
+ r,
385
+ 0,
386
+ v.BUTTON_PRIMARY,
387
+ v.BUTTON_PRIMARY
388
+ );
389
+ d && $(d);
390
+ }, 60);
391
+ }, Zt = (e, n) => {
392
+ const o = Te();
393
+ if (!o || n.screen.width <= 0 || n.screen.height <= 0) return;
394
+ const t = e.frame.x + e.frame.width / 2, s = e.frame.y + e.frame.height / 2, r = t / n.screen.width * o.actualWidth, c = s / n.screen.height * o.actualHeight, l = o.videoRect.left + o.offsetX + r, a = o.videoRect.top + o.offsetY + c;
395
+ Mt(l, a);
396
+ }, $e = -1, Fe = -2, fe = -3, Ae = (e, n, o, t, s, r) => {
397
+ const c = Ke(
398
+ e,
399
+ n,
400
+ o,
401
+ t,
402
+ s,
403
+ r,
404
+ 1,
405
+ // pressure
406
+ v.BUTTON_PRIMARY,
407
+ v.BUTTON_PRIMARY
408
+ );
409
+ c && (X("[rc-touch] sendSingleTouch", {
410
+ action: e,
411
+ actionName: Ve(e),
412
+ pointerId: n,
413
+ x: s,
414
+ y: r,
415
+ video: { width: o, height: t }
416
+ }), $(c));
417
+ }, pe = (e, n, o) => {
418
+ if (!o) return;
419
+ const { videoX: t, videoY: s, videoWidth: r, videoHeight: c } = o;
420
+ let l = null, a = null, d = 1;
421
+ const k = v.BUTTON_PRIMARY;
422
+ switch (n) {
423
+ case "down":
424
+ e !== fe && Ee.current.end(), l = Y.current.size === 0 ? v.ACTION_DOWN : v.ACTION_POINTER_DOWN, a = { x: t, y: s }, Y.current.set(e, a), e === -1 && P.current?.focus();
425
+ break;
426
+ case "move":
427
+ Y.current.has(e) && (l = v.ACTION_MOVE, a = { x: t, y: s }, Y.current.set(e, a));
428
+ break;
429
+ case "up":
430
+ case "cancel":
431
+ Y.current.has(e) && (a = Y.current.get(e), Y.current.delete(e), n === "cancel" ? l = v.ACTION_CANCEL : l = Y.current.size === 0 ? v.ACTION_UP : v.ACTION_POINTER_UP);
432
+ break;
433
+ }
434
+ if (l !== null && a !== null) {
435
+ X("[rc-touch][mouse->touch] sending", {
436
+ pointerId: e,
437
+ eventType: n,
438
+ action: l,
439
+ actionName: Ve(l),
440
+ positionToSend: a,
441
+ video: { width: r, height: c },
442
+ altHeld: ae.current,
443
+ activePointersAfter: Array.from(Y.current.entries()).map(([L, T]) => ({
444
+ id: L,
445
+ x: T.x,
446
+ y: T.y
447
+ }))
448
+ });
449
+ const A = Ke(
450
+ l,
451
+ e,
452
+ r,
453
+ c,
454
+ a.x,
455
+ a.y,
456
+ d,
457
+ k,
458
+ k
459
+ );
460
+ A && (X("[rc-touch][mouse->touch] buffer", {
461
+ pointerId: e,
462
+ actionName: Ve(l),
463
+ byteLength: A.byteLength
464
+ }), $(A));
465
+ } else (n === "up" || n === "cancel") && Y.current.delete(e);
466
+ }, et = (e) => {
467
+ if (ae.current !== e && (ae.current = e, Vt(e), e || Xe(null), X("[rc-touch][alt] updateAltHeld", {
468
+ nextHeld: e,
469
+ activePointerIds: Array.from(Y.current.keys())
470
+ }), D === "ios" && y.current?.getState().controlReady)) {
471
+ const n = e ? S.ACTION_DOWN : S.ACTION_UP, o = Be(
472
+ n,
473
+ S.KEYCODE_ALT_LEFT,
474
+ 0,
475
+ S.META_NONE
476
+ );
477
+ X("[rc-touch][alt] sending Indigo modifier keycode", {
478
+ action: n,
479
+ keycode: S.KEYCODE_ALT_LEFT
480
+ }), o && $(o);
481
+ }
482
+ }, Te = () => {
483
+ const e = P.current, n = Ye.current;
484
+ if (!e || !n) return null;
485
+ const o = e.videoWidth, t = e.videoHeight;
486
+ if (!o || !t) return null;
487
+ const s = e.getBoundingClientRect(), r = n.getBoundingClientRect(), c = s.width, l = s.height, a = o / t, d = c / l;
488
+ let k = c, A = l;
489
+ a > d ? A = c / a : k = l * a;
490
+ const L = (c - k) / 2, T = (l - A) / 2;
491
+ return {
492
+ videoWidth: o,
493
+ videoHeight: t,
494
+ videoRect: s,
495
+ containerRect: r,
496
+ actualWidth: k,
497
+ actualHeight: A,
498
+ offsetX: L,
499
+ offsetY: T
500
+ };
501
+ }, ie = (e, n, o) => {
502
+ const t = n - e.videoRect.left - e.offsetX, s = o - e.videoRect.top - e.offsetY, r = Math.max(0, Math.min(e.actualWidth, t)), c = Math.max(0, Math.min(e.actualHeight, s)), l = Math.max(
503
+ 0,
504
+ Math.min(e.videoWidth, r / e.actualWidth * e.videoWidth)
505
+ ), a = Math.max(
506
+ 0,
507
+ Math.min(e.videoHeight, c / e.actualHeight * e.videoHeight)
508
+ );
509
+ return {
510
+ videoX: l,
511
+ videoY: a,
512
+ videoWidth: e.videoWidth,
513
+ videoHeight: e.videoHeight
514
+ };
515
+ }, en = (e, n, o) => {
516
+ const t = n - e.videoRect.left - e.offsetX, s = o - e.videoRect.top - e.offsetY, r = Math.max(0, Math.min(e.actualWidth, t)), c = Math.max(0, Math.min(e.actualHeight, s)), l = Math.max(
517
+ 0,
518
+ Math.min(e.videoWidth, r / e.actualWidth * e.videoWidth)
519
+ ), a = Math.max(
520
+ 0,
521
+ Math.min(e.videoHeight, c / e.actualHeight * e.videoHeight)
522
+ ), d = e.videoWidth - l, k = e.videoHeight - a, A = e.videoRect.left + e.offsetX, L = e.videoRect.top + e.offsetY, T = A - e.containerRect.left + r, H = L - e.containerRect.top + c, x = A - e.containerRect.left + (e.actualWidth - r), g = L - e.containerRect.top + (e.actualHeight - c);
523
+ return {
524
+ containerX: T,
525
+ containerY: H,
526
+ mirrorContainerX: x,
527
+ mirrorContainerY: g,
528
+ videoX: l,
529
+ videoY: a,
530
+ mirrorVideoX: d,
531
+ mirrorVideoY: k,
532
+ videoWidth: e.videoWidth,
533
+ videoHeight: e.videoHeight
534
+ };
535
+ }, tn = (e, n, o, t, s, r, c) => {
536
+ const l = Rn(e, n, o, t, s, r, c);
537
+ X("[rc-touch2] sendTwoFingerMessage (iOS)", {
538
+ actionName: Ve(e),
539
+ video: { width: n, height: o },
540
+ p0: { x: t, y: s },
541
+ p1: { x: r, y: c },
542
+ byteLength: l.byteLength
543
+ }), $(l);
544
+ }, Ce = (e, n, o, t, s, r, c, l, a) => {
545
+ if (X("[rc-touch2] applyTwoFingerEvent", {
546
+ platform: D,
547
+ eventType: e,
548
+ video: { width: n, height: o },
549
+ p0: { x: t, y: s, id: l },
550
+ p1: { x: r, y: c, id: a }
551
+ }), e === "down" && Ee.current.end(), D === "ios") {
552
+ const d = e === "down" ? v.ACTION_DOWN : e === "move" ? v.ACTION_MOVE : v.ACTION_UP;
553
+ tn(d, n, o, t, s, r, c);
554
+ } else
555
+ e === "down" ? (Ae(v.ACTION_DOWN, l, n, o, t, s), Ae(v.ACTION_POINTER_DOWN, a, n, o, r, c)) : e === "move" ? (Ae(v.ACTION_MOVE, l, n, o, t, s), Ae(v.ACTION_MOVE, a, n, o, r, c)) : (Ae(v.ACTION_POINTER_UP, a, n, o, r, c), Ae(v.ACTION_UP, l, n, o, t, s));
556
+ }, nn = (e, n, o) => {
557
+ if (!ae.current) {
558
+ le !== null && Xe(null);
559
+ return;
560
+ }
561
+ const t = en(e, n, o);
562
+ Xe(t);
563
+ }, on = (e, n, o) => {
564
+ const t = de.current;
565
+ if (!t || t.screen.width <= 0 || t.screen.height <= 0) return null;
566
+ const s = n - e.videoRect.left - e.offsetX, r = o - e.videoRect.top - e.offsetY;
567
+ if (s < 0 || r < 0 || s > e.actualWidth || r > e.actualHeight) return null;
568
+ const c = s / e.actualWidth * t.screen.width, l = r / e.actualHeight * t.screen.height;
569
+ return Tn(t, c, l);
570
+ }, re = (e) => {
571
+ if (G) return;
572
+ e.preventDefault(), e.stopPropagation();
573
+ const n = Te();
574
+ if ((B === !0 || B === "hover-only") && !("touches" in e))
575
+ if (e.type === "mousemove") {
576
+ if (wt({ x: e.clientX, y: e.clientY }), n) {
577
+ const t = on(n, e.clientX, e.clientY);
578
+ Ie(t?.id ?? null);
579
+ }
580
+ } else e.type === "mouseleave" && (wt(null), Ie(null));
581
+ if (B !== !0) {
582
+ if (D === "macos") {
583
+ if ("touches" in e || !n || !y.current?.getState().controlReady) return;
584
+ const t = ie(n, e.clientX, e.clientY);
585
+ if (!t) return;
586
+ const s = e.type === "mousedown" ? Ne.DOWN : e.type === "mouseup" ? Ne.UP : Ne.MOVE, r = e.type === "mouseleave" ? 0 : e.buttons;
587
+ e.type === "mousedown" && P.current?.focus(), $(
588
+ wn(
589
+ s,
590
+ t.videoWidth,
591
+ t.videoHeight,
592
+ t.videoX,
593
+ t.videoY,
594
+ r
595
+ )
596
+ );
597
+ return;
598
+ }
599
+ if (!("touches" in e) && n && (e.type === "mousemove" ? nn(n, e.clientX, e.clientY) : e.type === "mouseleave" && Xe(null)), !(!y.current?.getState().controlReady || !P.current || !n))
600
+ if ("touches" in e) {
601
+ const t = e.touches, s = e.changedTouches;
602
+ let r;
603
+ switch (e.type) {
604
+ case "touchstart":
605
+ r = "down";
606
+ break;
607
+ case "touchmove":
608
+ r = "move";
609
+ break;
610
+ case "touchend":
611
+ r = "up";
612
+ break;
613
+ case "touchcancel":
614
+ r = "cancel";
615
+ break;
616
+ default:
617
+ return;
618
+ }
619
+ if (t.length === 2) {
620
+ const c = t[0], l = t[1], a = ie(n, c.clientX, c.clientY), d = ie(n, l.clientX, l.clientY);
621
+ if (!a || !d) return;
622
+ I.current ? I.current.source === "real-touch" && (I.current.finger0 = { x: a.videoX, y: a.videoY }, I.current.finger1 = { x: d.videoX, y: d.videoY }, Ce(
623
+ "move",
624
+ a.videoWidth,
625
+ a.videoHeight,
626
+ a.videoX,
627
+ a.videoY,
628
+ d.videoX,
629
+ d.videoY,
630
+ I.current.pointerId0,
631
+ I.current.pointerId1
632
+ )) : (I.current = {
633
+ finger0: { x: a.videoX, y: a.videoY },
634
+ finger1: { x: d.videoX, y: d.videoY },
635
+ videoSize: { width: a.videoWidth, height: a.videoHeight },
636
+ source: "real-touch",
637
+ pointerId0: c.identifier,
638
+ pointerId1: l.identifier
639
+ }, Ce(
640
+ "down",
641
+ a.videoWidth,
642
+ a.videoHeight,
643
+ a.videoX,
644
+ a.videoY,
645
+ d.videoX,
646
+ d.videoY,
647
+ c.identifier,
648
+ l.identifier
649
+ ));
650
+ } else if (t.length < 2 && I.current?.source === "real-touch") {
651
+ const c = I.current;
652
+ Ce(
653
+ "up",
654
+ c.videoSize.width,
655
+ c.videoSize.height,
656
+ c.finger0.x,
657
+ c.finger0.y,
658
+ c.finger1.x,
659
+ c.finger1.y,
660
+ c.pointerId0,
661
+ c.pointerId1
662
+ ), I.current = null;
663
+ return;
664
+ } else {
665
+ if (t.length > 2)
666
+ return;
667
+ {
668
+ const c = s[0];
669
+ if (c) {
670
+ const l = ie(n, c.clientX, c.clientY);
671
+ pe(c.identifier, r, l);
672
+ }
673
+ }
674
+ }
675
+ } else {
676
+ let s = null;
677
+ const r = I.current?.source === "alt-mouse";
678
+ switch (e.type) {
679
+ case "mousedown":
680
+ e.button === 0 && (s = "down");
681
+ break;
682
+ case "mousemove":
683
+ (r || Y.current.has(-1)) && (s = "move");
684
+ break;
685
+ case "mouseup":
686
+ e.button === 0 && (s = "up");
687
+ break;
688
+ case "mouseleave":
689
+ (r || Y.current.has(-1)) && (s = "up");
690
+ break;
691
+ }
692
+ if (s) {
693
+ const c = ie(n, e.clientX, e.clientY);
694
+ if (!c)
695
+ return;
696
+ X("[rc-touch][mouse] event", {
697
+ domType: e.type,
698
+ eventType: s,
699
+ button: e.button,
700
+ buttons: e.buttons,
701
+ client: { x: e.clientX, y: e.clientY },
702
+ altHeldRef: ae.current,
703
+ inTwoFingerMode: r,
704
+ geometry: {
705
+ videoX: c.videoX,
706
+ videoY: c.videoY,
707
+ videoWidth: c.videoWidth,
708
+ videoHeight: c.videoHeight
709
+ },
710
+ activePointerIds: Array.from(Y.current.keys())
711
+ }), ae.current || r ? rn(s, c) : pe(-1, s, c);
712
+ }
713
+ }
714
+ }
715
+ }, rn = (e, n) => {
716
+ const { videoX: o, videoY: t, videoWidth: s, videoHeight: r } = n, c = s - o, l = r - t;
717
+ if (e === "down") {
718
+ I.current = {
719
+ finger0: { x: o, y: t },
720
+ finger1: { x: c, y: l },
721
+ videoSize: { width: s, height: r },
722
+ source: "alt-mouse",
723
+ pointerId0: $e,
724
+ pointerId1: Fe
725
+ }, P.current?.focus(), Ce(
726
+ "down",
727
+ s,
728
+ r,
729
+ o,
730
+ t,
731
+ c,
732
+ l,
733
+ $e,
734
+ Fe
735
+ );
736
+ return;
737
+ }
738
+ if (e === "move") {
739
+ I.current?.source === "alt-mouse" && (I.current.finger0 = { x: o, y: t }, I.current.finger1 = { x: c, y: l }, Ce(
740
+ "move",
741
+ s,
742
+ r,
743
+ o,
744
+ t,
745
+ c,
746
+ l,
747
+ $e,
748
+ Fe
749
+ ));
750
+ return;
751
+ }
752
+ if (e === "up" || e === "cancel") {
753
+ const a = I.current;
754
+ if (a?.source === "alt-mouse") {
755
+ const { finger0: d, finger1: k, videoSize: A } = a;
756
+ Ce(
757
+ "up",
758
+ A.width,
759
+ A.height,
760
+ d.x,
761
+ d.y,
762
+ k.x,
763
+ k.y,
764
+ $e,
765
+ Fe
766
+ ), I.current = null;
767
+ }
768
+ return;
769
+ }
770
+ }, cn = 150, Nt = () => {
771
+ const e = ye.current;
772
+ e && (window.clearTimeout(e.endTimer), pe(fe, "up", e.pos), ye.current = null);
773
+ }, sn = (e) => {
774
+ if (!y.current?.getState().controlReady || e.ctrlKey) return;
775
+ if (D === "macos") {
776
+ const g = Te();
777
+ if (!g) return;
778
+ const Re = e.clientX - g.videoRect.left - g.offsetX, _e = e.clientY - g.videoRect.top - g.offsetY;
779
+ if (Re < 0 || Re > g.actualWidth || _e < 0 || _e > g.actualHeight)
780
+ return;
781
+ const Pe = ie(g, e.clientX, e.clientY);
782
+ if (!Pe) return;
783
+ e.preventDefault();
784
+ const Et = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 : e.deltaMode === WheelEvent.DOM_DELTA_PAGE ? g.actualHeight : 1;
785
+ $(
786
+ yn(
787
+ Pe.videoWidth,
788
+ Pe.videoHeight,
789
+ Pe.videoX,
790
+ Pe.videoY,
791
+ e.deltaX * Et,
792
+ e.deltaY * Et
793
+ )
794
+ );
795
+ return;
796
+ }
797
+ if (ae.current || I.current) return;
798
+ const n = Y.current.size;
799
+ if (n > 1 || n === 1 && !Y.current.has(fe)) return;
800
+ const o = Te();
801
+ if (!o) return;
802
+ const t = e.clientX - o.videoRect.left - o.offsetX, s = e.clientY - o.videoRect.top - o.offsetY;
803
+ if (t < 0 || t > o.actualWidth || s < 0 || s > o.actualHeight)
804
+ return;
805
+ const r = ie(o, e.clientX, e.clientY);
806
+ if (!r) return;
807
+ e.preventDefault();
808
+ const c = (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? o.actualWidth : 1) * (o.videoWidth / o.actualWidth), l = (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? o.actualHeight : 1) * (o.videoHeight / o.actualHeight), a = -e.deltaX * c, d = -e.deltaY * l, k = (g) => {
809
+ window.clearTimeout(g.endTimer), g.endTimer = window.setTimeout(Nt, cn);
810
+ };
811
+ if (a === 0 && d === 0) {
812
+ ye.current && k(ye.current);
813
+ return;
814
+ }
815
+ const A = () => ({
816
+ videoWidth: r.videoWidth,
817
+ videoHeight: r.videoHeight,
818
+ videoX: Math.abs(a) > Math.abs(d) ? Math.min(Math.max(r.videoX, r.videoWidth * 0.2), r.videoWidth * 0.8) : r.videoX,
819
+ videoY: Math.abs(d) >= Math.abs(a) ? Math.min(Math.max(r.videoY, r.videoHeight * 0.2), r.videoHeight * 0.8) : r.videoY
820
+ }), L = (g) => ({
821
+ ...g,
822
+ videoX: Math.min(Math.max(g.videoX + a, 0), g.videoWidth),
823
+ videoY: Math.min(Math.max(g.videoY + d, 0), g.videoHeight)
824
+ });
825
+ let T = ye.current;
826
+ if (T)
827
+ window.clearTimeout(T.endTimer);
828
+ else {
829
+ const g = A();
830
+ pe(fe, "down", g), T = { pos: g, endTimer: 0 }, ye.current = T;
831
+ }
832
+ let H = T.pos, x = L(H);
833
+ x.videoX === H.videoX && x.videoY === H.videoY && (pe(fe, "up", H), H = A(), pe(fe, "down", H), x = L(H)), pe(fe, "move", x), T.pos = x, k(T);
834
+ };
835
+ K(() => {
836
+ Ee.current = { handle: sn, end: Nt };
837
+ }), K(() => {
838
+ const e = Ye.current;
839
+ if (!e) return;
840
+ const n = (o) => Ee.current.handle(o);
841
+ return e.addEventListener("wheel", n, { passive: !1 }), () => {
842
+ Ee.current.end(), e.removeEventListener("wheel", n);
843
+ };
844
+ }, []), K(() => {
845
+ const e = (s) => {
846
+ s.key === "Alt" && et(!0);
847
+ }, n = (s) => {
848
+ s.key === "Alt" && et(!1);
849
+ }, o = () => {
850
+ et(!1), Ue();
851
+ }, t = () => {
852
+ document.hidden && Ue();
853
+ };
854
+ return window.addEventListener("keydown", e, !0), window.addEventListener("keyup", n, !0), window.addEventListener("blur", o), document.addEventListener("visibilitychange", t), () => {
855
+ window.removeEventListener("keydown", e, !0), window.removeEventListener("keyup", n, !0), window.removeEventListener("blur", o), document.removeEventListener("visibilitychange", t);
856
+ };
857
+ }, [Ue]);
858
+ const ze = (e) => {
859
+ e.preventDefault(), e.stopPropagation();
860
+ const n = document.activeElement === P.current || G && document.activeElement === e.currentTarget;
861
+ if (X("Keyboard event:", {
862
+ type: e.type,
863
+ key: e.key,
864
+ keyCode: e.keyCode,
865
+ code: e.code,
866
+ target: e.target.tagName,
867
+ focused: n
868
+ }), !n) {
869
+ ot("Simulator input not focused, skipping keyboard event");
870
+ return;
871
+ }
872
+ if (!y.current?.getState().controlReady) {
873
+ ot("Data channel not ready for keyboard event:", y.current?.getState().connection);
874
+ return;
875
+ }
876
+ if (D === "macos") {
877
+ if (e.type === "keydown" && e.repeat) return;
878
+ const t = bn(e.code);
879
+ if (t === void 0) {
880
+ X(`Ignoring unmapped key for macOS: code=${e.code}`);
881
+ return;
882
+ }
883
+ e.type === "keydown" ? xe.current.add(t) : xe.current.delete(t), $(
884
+ It(
885
+ e.type === "keydown" ? Ne.DOWN : Ne.UP,
886
+ t
887
+ )
888
+ );
889
+ return;
890
+ }
891
+ if (e.type === "keydown") {
892
+ if (e.key.toLowerCase() === "v" && (e.metaKey || e.ctrlKey)) {
893
+ X("Paste shortcut detected"), navigator.clipboard.readText().then((t) => {
894
+ if (t) {
895
+ X(
896
+ "Pasting text via SET_CLIPBOARD:",
897
+ t.substring(0, 20) + (t.length > 20 ? "..." : "")
898
+ );
899
+ const s = An(t, !0);
900
+ $(s);
901
+ }
902
+ }).catch((t) => {
903
+ console.error("Failed to read clipboard contents: ", t);
904
+ });
905
+ return;
906
+ }
907
+ if (e.key.toLowerCase() === "m" && (e.metaKey || e.ctrlKey)) {
908
+ X("Menu shortcut detected");
909
+ const t = Be(
910
+ S.ACTION_DOWN,
911
+ S.MENU,
912
+ 0,
913
+ S.META_NONE
914
+ // Modifiers are handled by the shortcut check, not passed down
915
+ );
916
+ $(t);
917
+ const s = Be(
918
+ S.ACTION_UP,
919
+ S.MENU,
920
+ 0,
921
+ S.META_NONE
922
+ );
923
+ $(s);
924
+ return;
925
+ }
926
+ }
927
+ const o = zn(e);
928
+ if (o) {
929
+ const { keycode: t, metaState: s } = o, r = e.type === "keydown" ? S.ACTION_DOWN : S.ACTION_UP;
930
+ X(`Sending Keycode: key=${e.key}, code=${t}, action=${r}, meta=${s}`);
931
+ const c = Be(
932
+ r,
933
+ t,
934
+ 0,
935
+ // repeat count, typically 0 for single presses
936
+ s
937
+ );
938
+ $(c);
939
+ } else
940
+ X(`Ignoring unhandled key event: type=${e.type}, key=${e.key}`);
941
+ }, an = (e) => {
942
+ e.stopPropagation(), y.current?.reconnect();
943
+ }, F = O({
944
+ onAxSnapshotChange: ce,
945
+ onAxStatusChange: q,
946
+ onCameraDemandChange: ke,
947
+ onCameraStats: J,
948
+ onMicrophoneStateChange: ge,
949
+ onTrace: ne,
950
+ onTerminated: W,
951
+ onConnectionStateChange: te,
952
+ onPlaybackStats: E
953
+ });
954
+ F.current = {
955
+ onAxSnapshotChange: ce,
956
+ onAxStatusChange: q,
957
+ onCameraDemandChange: ke,
958
+ onCameraStats: J,
959
+ onMicrophoneStateChange: ge,
960
+ onTrace: ne,
961
+ onTerminated: W,
962
+ onConnectionStateChange: te,
963
+ onPlaybackStats: E
964
+ };
965
+ const tt = !!ne;
966
+ K(() => {
967
+ Ge.current = null, dt(!1), ht(!1), ft({}), mt(null);
968
+ }, [i, De]), K(() => {
969
+ let e = !0;
970
+ de.current !== null && (de.current = null, qe(null), Me("onAxSnapshotChange", F.current.onAxSnapshotChange, null));
971
+ const n = gn({
972
+ url: i,
973
+ token: h,
974
+ sessionId: Qt,
975
+ watchOnly: oe,
976
+ deviceModel: De,
977
+ autoReconnect: w,
978
+ jitterBufferTargetMs: _,
979
+ openUrl: M,
980
+ inspectMode: B,
981
+ axPollIntervalMs: U,
982
+ axMaxBackoffMs: b,
983
+ androidElementTreeOptions: Z,
984
+ microphoneEnabled: se,
985
+ onStateChange: (t) => {
986
+ (t.videoReady || t.connection === "idle" || t.connection === "connecting" || t.connection === "reconnecting") && xt(t.videoReady), $t(t.connection === "failed"), zt(t.connection === "terminated"), Lt(t.duo), Xt(t.duoState), Wt(t.duoError);
987
+ },
988
+ onAxSnapshotChange: (t) => {
989
+ e && (qe((s) => vn(s, t) ? s : t), F.current.onAxSnapshotChange?.(t));
990
+ },
991
+ onAxStatusChange: (...t) => F.current.onAxStatusChange?.(...t),
992
+ onCameraDemandChange: (...t) => F.current.onCameraDemandChange?.(...t),
993
+ onCameraStats: J ? (...t) => F.current.onCameraStats?.(...t) : void 0,
994
+ onMicrophoneStateChange: (...t) => F.current.onMicrophoneStateChange?.(...t),
995
+ onTrace: tt ? (...t) => F.current.onTrace?.(...t) : void 0,
996
+ onTerminated: () => F.current.onTerminated?.(),
997
+ onConnectionStateChange: (...t) => F.current.onConnectionStateChange?.(...t),
998
+ onPlaybackStats: E ? (...t) => F.current.onPlaybackStats?.(...t) : void 0
999
+ });
1000
+ y.current = n;
1001
+ const o = P.current ? n.attachVideo(P.current) : void 0;
1002
+ return n.start(), () => {
1003
+ e = !1, n.dispose(), o?.(), y.current = null;
1004
+ };
1005
+ }, [i, f, De, tt, oe]), K(() => {
1006
+ if (G && Le.current)
1007
+ return y.current?.attachVideo(Le.current, "inner");
1008
+ }, [G, i, f, De, tt, oe]), K(() => {
1009
+ y.current?.updateOptions({
1010
+ token: h,
1011
+ openUrl: M,
1012
+ axPollIntervalMs: U,
1013
+ axMaxBackoffMs: b,
1014
+ androidElementTreeOptions: Z,
1015
+ autoReconnect: w,
1016
+ jitterBufferTargetMs: _,
1017
+ microphoneEnabled: se,
1018
+ inspectMode: B,
1019
+ onPlaybackStats: E ? (...e) => F.current.onPlaybackStats?.(...e) : void 0,
1020
+ onCameraStats: J ? (...e) => F.current.onCameraStats?.(...e) : void 0
1021
+ });
1022
+ }, [
1023
+ h,
1024
+ w,
1025
+ _,
1026
+ se,
1027
+ B,
1028
+ !!E,
1029
+ !!J,
1030
+ M,
1031
+ U,
1032
+ b,
1033
+ Z
1034
+ ]);
1035
+ const nt = () => {
1036
+ if (!bt.current) return;
1037
+ const e = Te();
1038
+ if (!e) {
1039
+ yt(null);
1040
+ return;
1041
+ }
1042
+ const n = {
1043
+ left: e.videoRect.left - e.containerRect.left + e.offsetX,
1044
+ top: e.videoRect.top - e.containerRect.top + e.offsetY,
1045
+ width: e.actualWidth,
1046
+ height: e.actualHeight
1047
+ };
1048
+ yt(
1049
+ (o) => o && o.left === n.left && o.top === n.top && o.width === n.width && o.height === n.height ? o : n
1050
+ );
1051
+ };
1052
+ K(() => {
1053
+ const e = P.current, n = st.current, o = Ye.current;
1054
+ if (!e) return;
1055
+ const t = (a) => ft((d) => _t(d, a) ? d : a), s = (a) => mt((d) => d && a && _t(d, a) ? d : a), r = () => {
1056
+ const a = e.videoWidth > 0 && e.videoHeight > 0;
1057
+ a && (Ge.current = { width: e.videoWidth, height: e.videoHeight });
1058
+ const d = Ge.current, k = d ? `${d.width} / ${d.height}` : void 0;
1059
+ if (!Se || !n) {
1060
+ t(
1061
+ !a && d ? {
1062
+ aspectRatio: k,
1063
+ contain: "size",
1064
+ containIntrinsicSize: `${d.width}px ${d.height}px`
1065
+ } : {}
1066
+ ), s(null), nt();
1067
+ return;
1068
+ }
1069
+ const A = n.clientWidth, L = n.clientHeight;
1070
+ if (A === 0 || L === 0) return;
1071
+ const T = d ? d.width > d.height : !1;
1072
+ dt(T), ht(
1073
+ D === "android" && !!d && xn(d.width, d.height)
1074
+ );
1075
+ const H = T ? he.videoPosition.landscape : he.videoPosition.portrait;
1076
+ let x = { aspectRatio: k };
1077
+ H.heightMultiplier ? (x.height = `${L * H.heightMultiplier}px`, x.width = "auto") : H.widthMultiplier && (x.width = `${A * H.widthMultiplier}px`, x.height = "auto"), x.borderRadius = `${T ? L * he.videoBorderRadiusMultiplier : A * he.videoBorderRadiusMultiplier}px`, t(x);
1078
+ const g = he.homeButton, Re = T ? A : L, _e = `calc(50% + ${Re * (g?.offset ?? 0)}px)`;
1079
+ s(
1080
+ g ? {
1081
+ width: `${Re * g.diameter}px`,
1082
+ height: `${Re * g.diameter}px`,
1083
+ left: T ? _e : "50%",
1084
+ top: T ? "50%" : _e
1085
+ } : null
1086
+ ), nt();
1087
+ }, c = new ResizeObserver(() => {
1088
+ r();
1089
+ });
1090
+ n && c.observe(n), c.observe(e), o && c.observe(o), n && n.addEventListener("load", r), e.addEventListener("loadedmetadata", r), e.addEventListener("resize", r);
1091
+ const l = () => y.current?.bumpActivity();
1092
+ return e.addEventListener("resize", l), r(), () => {
1093
+ c.disconnect(), e.removeEventListener("loadedmetadata", r), e.removeEventListener("resize", r), e.removeEventListener("resize", l), n && n.removeEventListener("load", r);
1094
+ };
1095
+ }, [he, Se, i, p]), K(() => {
1096
+ ue ? nt() : (qe(null), Ie(null), We(null), vt(null), ve(null), He.current = null, ee.current !== void 0 && (window.cancelAnimationFrame(ee.current), ee.current = void 0));
1097
+ }, [ue]), K(() => () => {
1098
+ ee.current !== void 0 && (window.cancelAnimationFrame(ee.current), ee.current = void 0);
1099
+ }, []), K(() => {
1100
+ if (!ue) return;
1101
+ const e = (n) => {
1102
+ n.key === "Escape" && (Qe || Je) && (We(null), Ie(null), ve(null), Me("onInspectSelectionChange", we.current, null));
1103
+ };
1104
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
1105
+ }, [ue, Qe, Je]);
1106
+ const ln = () => {
1107
+ P.current && P.current.focus();
1108
+ };
1109
+ En(rt, () => ({
1110
+ openUrl: (e) => y.current?.openUrl(e),
1111
+ sendKeyEvent: (e) => y.current?.sendKeyEvent(e),
1112
+ screenshot: (e) => y.current?.screenshot(e) ?? Promise.reject(new Error("Simulator disconnected")),
1113
+ terminateApp: (e) => y.current?.terminateApp(e) ?? Promise.reject(new Error("Simulator disconnected")),
1114
+ reconnect: () => y.current?.reconnect(),
1115
+ refreshAxTree: () => y.current?.refreshAxTree() ?? Promise.reject(new Error("Simulator disconnected")),
1116
+ getAxSnapshot: () => y.current?.getAxSnapshot() ?? null,
1117
+ setInspectHighlight: (e) => {
1118
+ Ie(e?.id ?? null);
1119
+ },
1120
+ setInspectSelection: (e) => {
1121
+ We(e?.id ?? null), ve(e ? He.current : null);
1122
+ const n = de.current;
1123
+ e && n ? Me("onInspectSelectionChange", we.current, { element: e, snapshot: n }) : Me("onInspectSelectionChange", we.current, null);
1124
+ },
1125
+ getAxStatus: () => y.current?.getAxStatus() ?? "idle"
1126
+ }));
1127
+ const dn = Kt && le !== null;
1128
+ return /* @__PURE__ */ V(
1129
+ "div",
1130
+ {
1131
+ ref: Ye,
1132
+ className: ["rc-container", u].filter(Boolean).join(" "),
1133
+ style: { touchAction: "none" },
1134
+ onMouseDown: re,
1135
+ onMouseMove: re,
1136
+ onMouseUp: re,
1137
+ onMouseLeave: re,
1138
+ onTouchStart: re,
1139
+ onTouchMove: re,
1140
+ onTouchEnd: re,
1141
+ onTouchCancel: re,
1142
+ onContextMenu: D === "macos" ? (e) => e.preventDefault() : void 0,
1143
+ children: [
1144
+ dn && le && /* @__PURE__ */ V(Pt, { children: [
1145
+ /* @__PURE__ */ m(
1146
+ "div",
1147
+ {
1148
+ className: "rc-touch-indicator",
1149
+ style: {
1150
+ left: `${le.containerX}px`,
1151
+ top: `${le.containerY}px`
1152
+ }
1153
+ }
1154
+ ),
1155
+ /* @__PURE__ */ m(
1156
+ "div",
1157
+ {
1158
+ className: "rc-touch-indicator",
1159
+ style: {
1160
+ left: `${le.mirrorContainerX}px`,
1161
+ top: `${le.mirrorContainerY}px`
1162
+ }
1163
+ }
1164
+ )
1165
+ ] }),
1166
+ Se && /* @__PURE__ */ m(
1167
+ "img",
1168
+ {
1169
+ ref: st,
1170
+ src: Tt,
1171
+ alt: "",
1172
+ className: D === "ios" ? "rc-phone-frame rc-phone-frame-ios" : "rc-phone-frame",
1173
+ draggable: !1
1174
+ }
1175
+ ),
1176
+ Se && pt && !oe && /* @__PURE__ */ m(
1177
+ "button",
1178
+ {
1179
+ type: "button",
1180
+ className: "rc-home-button",
1181
+ "aria-label": "Home",
1182
+ title: "Home",
1183
+ style: pt,
1184
+ onMouseDown: (e) => e.stopPropagation(),
1185
+ onTouchStart: (e) => e.stopPropagation(),
1186
+ onTouchEnd: (e) => {
1187
+ e.stopPropagation(), e.preventDefault(), y.current?.pressButton("home");
1188
+ },
1189
+ onClick: (e) => {
1190
+ e.stopPropagation(), y.current?.pressButton("home");
1191
+ }
1192
+ }
1193
+ ),
1194
+ /* @__PURE__ */ m(
1195
+ "video",
1196
+ {
1197
+ ref: P,
1198
+ className: [
1199
+ "rc-video",
1200
+ !Se && "rc-video-frameless",
1201
+ !Ht && (D === "macos" ? "rc-video-loading-desktop" : "rc-video-loading")
1202
+ ].filter(Boolean).join(" "),
1203
+ style: {
1204
+ ...Bt,
1205
+ ...G ? { opacity: 0, width: 1, height: 1, pointerEvents: "none" } : {},
1206
+ ...Ct ? {
1207
+ backgroundImage: `url("${Ct}")`,
1208
+ backgroundRepeat: "no-repeat",
1209
+ backgroundPosition: "center",
1210
+ backgroundSize: he.loadingLogoSize
1211
+ } : {}
1212
+ },
1213
+ autoPlay: !0,
1214
+ playsInline: !0,
1215
+ muted: !0,
1216
+ tabIndex: G ? -1 : 0,
1217
+ onKeyDown: ze,
1218
+ onKeyUp: ze,
1219
+ onClick: ln,
1220
+ onFocus: () => {
1221
+ P.current && (P.current.style.outline = "none");
1222
+ },
1223
+ onBlur: () => {
1224
+ P.current && (P.current.style.outline = "none"), Ue();
1225
+ }
1226
+ }
1227
+ ),
1228
+ G && /* @__PURE__ */ m(
1229
+ "video",
1230
+ {
1231
+ ref: Le,
1232
+ autoPlay: !0,
1233
+ playsInline: !0,
1234
+ muted: !0,
1235
+ style: { position: "absolute", width: 1, height: 1, opacity: 0, pointerEvents: "none" }
1236
+ }
1237
+ ),
1238
+ G && at && /* @__PURE__ */ m(In, { fallback: /* @__PURE__ */ m("div", { children: "Loading iPhone Duo…" }), children: /* @__PURE__ */ m(
1239
+ Hn,
1240
+ {
1241
+ watchOnly: oe,
1242
+ showFrame: N,
1243
+ modelUrl: z,
1244
+ outer: P.current,
1245
+ inner: Le.current,
1246
+ state: at,
1247
+ setAngle: (e) => Ze("setHingeAngle", { angleDegrees: e }),
1248
+ setOrientation: (e) => Ze("setDuoOrientation", { orientation: e }),
1249
+ button: (e, n) => Ze("performActions", {
1250
+ actions: [{ type: n ? "buttonDown" : "buttonUp", button: e }]
1251
+ }),
1252
+ touch: (e, n, o, t) => {
1253
+ y.current?.sendDisplayTouch(e, n, o, t);
1254
+ },
1255
+ onKeyDown: ze,
1256
+ onKeyUp: ze
1257
+ }
1258
+ ) }),
1259
+ G && lt && /* @__PURE__ */ m("div", { role: "alert", className: "rc-duo-error", children: lt }),
1260
+ !G && ue && /* @__PURE__ */ m(
1261
+ Xn,
1262
+ {
1263
+ snapshot: gt,
1264
+ geometry: jt,
1265
+ highlightedId: Je,
1266
+ selectedId: Qe,
1267
+ mode: Jt,
1268
+ cursorPosition: Gt,
1269
+ frozenCursorPosition: qt,
1270
+ onSelectChange: (e, n) => {
1271
+ We(e?.id ?? null), e && n ? ve(n) : e || ve(null);
1272
+ const o = de.current;
1273
+ e && o ? Me("onInspectSelectionChange", we.current, {
1274
+ element: e,
1275
+ snapshot: o
1276
+ }) : Me("onInspectSelectionChange", we.current, null);
1277
+ },
1278
+ onTapElement: oe ? void 0 : ((e, n) => {
1279
+ if (n) {
1280
+ Mt(n.x, n.y);
1281
+ return;
1282
+ }
1283
+ const o = de.current;
1284
+ o && Zt(e, o);
1285
+ })
1286
+ }
1287
+ ),
1288
+ Ft ? /* @__PURE__ */ V("div", { className: "rc-terminated", role: "status", children: [
1289
+ /* @__PURE__ */ m("div", { className: "rc-terminated-title", children: "Instance terminated" }),
1290
+ /* @__PURE__ */ m("div", { className: "rc-terminated-message", children: "This instance no longer exists and can't be reconnected." })
1291
+ ] }) : Ut && /* @__PURE__ */ m("button", { type: "button", className: "rc-retry-button", onClick: an, children: "Retry" })
1292
+ ]
1293
+ }
1294
+ );
1295
+ }
1296
+ );
1297
+ export {
1298
+ Gn as R
1299
+ };