@limrun/ui 0.20.6 → 0.20.8

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