@tapflowio/relay 0.18.0 → 0.20.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.
Files changed (114) hide show
  1. package/README.md +1 -1
  2. package/dist/RelayServer.d.ts +299 -2
  3. package/dist/RelayServer.d.ts.map +1 -1
  4. package/dist/RelayServer.js +1050 -177
  5. package/dist/RelayServer.js.map +1 -1
  6. package/dist/SessionManager.d.ts +83 -17
  7. package/dist/SessionManager.d.ts.map +1 -1
  8. package/dist/SessionManager.js +111 -14
  9. package/dist/SessionManager.js.map +1 -1
  10. package/dist/index.d.ts +1 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/cert/index.d.ts +1 -1
  15. package/dist/lib/cert/index.d.ts.map +1 -1
  16. package/dist/lib/cert/index.js +1 -1
  17. package/dist/lib/cert/index.js.map +1 -1
  18. package/dist/lib/cert/parseCert.d.ts +4 -0
  19. package/dist/lib/cert/parseCert.d.ts.map +1 -1
  20. package/dist/lib/cert/parseCert.js +68 -0
  21. package/dist/lib/cert/parseCert.js.map +1 -1
  22. package/dist/lib/trailingRequester.d.ts +23 -0
  23. package/dist/lib/trailingRequester.d.ts.map +1 -0
  24. package/dist/lib/trailingRequester.js +56 -0
  25. package/dist/lib/trailingRequester.js.map +1 -0
  26. package/dist/server.js +4 -2
  27. package/dist/server.js.map +1 -1
  28. package/dist/types.d.ts +2 -38
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/types.js +13 -0
  31. package/dist/types.js.map +1 -1
  32. package/package.json +8 -8
  33. package/public/assets/{AppCenter-B3FO67aw.js → AppCenter-Dg4dscW-.js} +6 -6
  34. package/public/assets/AppCenter-Dg4dscW-.js.br +0 -0
  35. package/public/assets/Default-Dxi8aZ1t.js +1 -0
  36. package/public/assets/Default-Dxi8aZ1t.js.br +0 -0
  37. package/public/assets/Invite-0EwoClX6.js +1 -0
  38. package/public/assets/Invite-0EwoClX6.js.br +0 -0
  39. package/public/assets/MacResources-Dy1M3EqK.js +1 -0
  40. package/public/assets/MacResources-Dy1M3EqK.js.br +0 -0
  41. package/public/assets/NotFound-BoDDivK5.js +1 -0
  42. package/public/assets/NotFound-BoDDivK5.js.br +0 -0
  43. package/public/assets/QASession-DqMj8JL1.js +140 -0
  44. package/public/assets/QASession-DqMj8JL1.js.br +0 -0
  45. package/public/assets/ResetPassword-CXU2bRry.js +1 -0
  46. package/public/assets/ResetPassword-CXU2bRry.js.br +0 -0
  47. package/public/assets/Setup-XXChRxeL.js +1 -0
  48. package/public/assets/Setup-XXChRxeL.js.br +0 -0
  49. package/public/assets/{Team-CBsjuUwh.js → Team-D0bXpmEY.js} +3 -3
  50. package/public/assets/Team-D0bXpmEY.js.br +0 -0
  51. package/public/assets/Tokens-D0YNHS5e.js +1 -0
  52. package/public/assets/Tokens-D0YNHS5e.js.br +0 -0
  53. package/public/assets/alert-dialog-CgatMXjB.js +1 -0
  54. package/public/assets/alert-dialog-CgatMXjB.js.br +0 -0
  55. package/public/assets/badge-B6Nf3A0Y.js +1 -0
  56. package/public/assets/badge-B6Nf3A0Y.js.br +0 -0
  57. package/public/assets/{build-format-B78hbKY9.js → build-format-BFC8gLoh.js} +5 -5
  58. package/public/assets/build-format-BFC8gLoh.js.br +0 -0
  59. package/public/assets/{dialog-BxC9v2BL.js → dialog-DK9a3b4z.js} +5 -5
  60. package/public/assets/dialog-DK9a3b4z.js.br +0 -0
  61. package/public/assets/index-9vdYIm7s.js +210 -0
  62. package/public/assets/index-9vdYIm7s.js.br +0 -0
  63. package/public/assets/index-ClHUQm-F.css +1 -0
  64. package/public/assets/index-ClHUQm-F.css.br +0 -0
  65. package/public/assets/{pencil-Cq64I9LV.js → pencil-BeLNLEKe.js} +2 -2
  66. package/public/assets/pencil-BeLNLEKe.js.br +0 -0
  67. package/public/assets/table-DW57-o1p.js +1 -0
  68. package/public/assets/table-DW57-o1p.js.br +0 -0
  69. package/public/assets/tabs-Xlttuqxh.js +1 -0
  70. package/public/assets/tabs-Xlttuqxh.js.br +0 -0
  71. package/public/assets/{trash-2-CszwJHEh.js → trash-2-CGxISX8x.js} +3 -3
  72. package/public/assets/trash-2-CGxISX8x.js.br +0 -0
  73. package/public/assets/vendor-charts-DyX5CBcf.js +5 -0
  74. package/public/assets/vendor-charts-DyX5CBcf.js.br +0 -0
  75. package/public/assets/vendor-react-AJpf4YZ0.js +49 -0
  76. package/public/assets/vendor-react-AJpf4YZ0.js.br +0 -0
  77. package/public/assets/vendor-router-ChFy8CZ1.js +12 -0
  78. package/public/assets/vendor-router-ChFy8CZ1.js.br +0 -0
  79. package/public/index.html +4 -2
  80. package/public/index.html.br +0 -0
  81. package/public/assets/AppCenter-B3FO67aw.js.br +0 -0
  82. package/public/assets/Default-BlNUv5dw.js +0 -1
  83. package/public/assets/Default-BlNUv5dw.js.br +0 -0
  84. package/public/assets/Invite-CKYFmy7S.js +0 -1
  85. package/public/assets/Invite-CKYFmy7S.js.br +0 -0
  86. package/public/assets/MacResources-BK4VQnFc.js +0 -5
  87. package/public/assets/MacResources-BK4VQnFc.js.br +0 -0
  88. package/public/assets/NotFound-BMmi1paB.js +0 -1
  89. package/public/assets/NotFound-BMmi1paB.js.br +0 -0
  90. package/public/assets/QASession-CVTlqW3d.js +0 -125
  91. package/public/assets/QASession-CVTlqW3d.js.br +0 -0
  92. package/public/assets/ResetPassword-VPPBWzSI.js +0 -1
  93. package/public/assets/ResetPassword-VPPBWzSI.js.br +0 -0
  94. package/public/assets/Setup-CRdnCl41.js +0 -1
  95. package/public/assets/Setup-CRdnCl41.js.br +0 -0
  96. package/public/assets/Team-CBsjuUwh.js.br +0 -0
  97. package/public/assets/Tokens-CU9HB9WD.js +0 -1
  98. package/public/assets/Tokens-CU9HB9WD.js.br +0 -0
  99. package/public/assets/alert-dialog-DWqGDQTB.js +0 -1
  100. package/public/assets/alert-dialog-DWqGDQTB.js.br +0 -0
  101. package/public/assets/badge-OToVq1dK.js +0 -1
  102. package/public/assets/badge-OToVq1dK.js.br +0 -0
  103. package/public/assets/build-format-B78hbKY9.js.br +0 -3
  104. package/public/assets/dialog-BxC9v2BL.js.br +0 -0
  105. package/public/assets/index-DXjMx9hQ.js +0 -274
  106. package/public/assets/index-DXjMx9hQ.js.br +0 -0
  107. package/public/assets/index-uGJGo6ac.css +0 -1
  108. package/public/assets/index-uGJGo6ac.css.br +0 -0
  109. package/public/assets/pencil-Cq64I9LV.js.br +0 -0
  110. package/public/assets/table-CbATN5Pi.js +0 -1
  111. package/public/assets/table-CbATN5Pi.js.br +0 -0
  112. package/public/assets/tabs-BVumgDA4.js +0 -1
  113. package/public/assets/tabs-BVumgDA4.js.br +0 -0
  114. package/public/assets/trash-2-CszwJHEh.js.br +0 -0
@@ -0,0 +1,140 @@
1
+ import{i as s,j as n}from"./vendor-react-AJpf4YZ0.js";import{W as te,J as ee,y as Vt,T as Re,z as ke,B as ie,x as je,S as Cn,a4 as Ce,r as hr,s as Ut,K as qe,a9 as Ze,t as et,O as Tn,a8 as dt,af as pr,ab as mr,U as gr,w as xr,f as br,ag as vr,aa as yr,a7 as wr,L as Sr}from"./index-9vdYIm7s.js";import{f as Rr,a as kr,P as En,c as ln,S as jr,b as Cr}from"./build-format-BFC8gLoh.js";import{u as Nn,n as X,T as Tr,b as Er,c as un,a as dn}from"./tabs-Xlttuqxh.js";import{c as An,b as Nr}from"./vendor-router-ChFy8CZ1.js";import{A as Ar,c as _r,f as Pr,g as Dr,d as Lr,e as Ir,b as Mr,a as Ur}from"./alert-dialog-CgatMXjB.js";import{D as _n,a as Pn,d as $r,e as Dn,b as Or,c as Fr,k as Br,S as Hr,i as zr,j as Wr,g as Vr,h as fn}from"./dialog-DK9a3b4z.js";import{B as qr}from"./badge-B6Nf3A0Y.js";/**
2
+ * @license lucide-react v1.33.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Xr=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Kr=te("arrow-left",Xr);/**
7
+ * @license lucide-react v1.33.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Yr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Gr=te("arrow-up",Yr);/**
12
+ * @license lucide-react v1.33.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Jr=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],Qr=te("camera",Jr);/**
17
+ * @license lucide-react v1.33.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Zr=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],es=te("download",Zr);/**
22
+ * @license lucide-react v1.33.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const ts=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],ns=te("film",ts);/**
27
+ * @license lucide-react v1.33.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const rs=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],Ln=te("house",rs);/**
32
+ * @license lucide-react v1.33.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const ss=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],os=te("image-plus",ss);/**
37
+ * @license lucide-react v1.33.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const as=[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]],is=te("keyboard",as);/**
42
+ * @license lucide-react v1.33.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const cs=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],In=te("link-2",cs);/**
47
+ * @license lucide-react v1.33.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const ls=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],yt=te("loader-circle",ls);/**
52
+ * @license lucide-react v1.33.0 - ISC
53
+ *
54
+ * This source code is licensed under the ISC license.
55
+ * See the LICENSE file in the root directory of this source tree.
56
+ */const us=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],ds=te("message-square",us);/**
57
+ * @license lucide-react v1.33.0 - ISC
58
+ *
59
+ * This source code is licensed under the ISC license.
60
+ * See the LICENSE file in the root directory of this source tree.
61
+ */const fs=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],hs=te("power",fs);/**
62
+ * @license lucide-react v1.33.0 - ISC
63
+ *
64
+ * This source code is licensed under the ISC license.
65
+ * See the LICENSE file in the root directory of this source tree.
66
+ */const ps=[["path",{d:"M13.414 13.414a2 2 0 1 1-2.828-2.828",key:"srl686"}],["path",{d:"M16.247 7.761a6 6 0 0 1 1.744 4.572",key:"1h86sp"}],["path",{d:"M19.075 4.933a10 10 0 0 1 2.234 10.72",key:"1n13k4"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}]],ms=te("radio-off",ps);/**
67
+ * @license lucide-react v1.33.0 - ISC
68
+ *
69
+ * This source code is licensed under the ISC license.
70
+ * See the LICENSE file in the root directory of this source tree.
71
+ */const gs=[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],Bt=te("radio",gs);/**
72
+ * @license lucide-react v1.33.0 - ISC
73
+ *
74
+ * This source code is licensed under the ISC license.
75
+ * See the LICENSE file in the root directory of this source tree.
76
+ */const xs=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],bs=te("refresh-cw",xs);/**
77
+ * @license lucide-react v1.33.0 - ISC
78
+ *
79
+ * This source code is licensed under the ISC license.
80
+ * See the LICENSE file in the root directory of this source tree.
81
+ */const vs=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],ys=te("rotate-cw",vs);/**
82
+ * @license lucide-react v1.33.0 - ISC
83
+ *
84
+ * This source code is licensed under the ISC license.
85
+ * See the LICENSE file in the root directory of this source tree.
86
+ */const ws=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["path",{d:"M7 12h10",key:"b7w52i"}]],Ss=te("scan-line",ws);/**
87
+ * @license lucide-react v1.33.0 - ISC
88
+ *
89
+ * This source code is licensed under the ISC license.
90
+ * See the LICENSE file in the root directory of this source tree.
91
+ */const Rs=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],ks=te("square",Rs);/**
92
+ * @license lucide-react v1.33.0 - ISC
93
+ *
94
+ * This source code is licensed under the ISC license.
95
+ * See the LICENSE file in the root directory of this source tree.
96
+ */const js=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Cs=te("video",js);/**
97
+ * @license lucide-react v1.33.0 - ISC
98
+ *
99
+ * This source code is licensed under the ISC license.
100
+ * See the LICENSE file in the root directory of this source tree.
101
+ */const Ts=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}]],Es=te("volume-1",Ts);/**
102
+ * @license lucide-react v1.33.0 - ISC
103
+ *
104
+ * This source code is licensed under the ISC license.
105
+ * See the LICENSE file in the root directory of this source tree.
106
+ */const Ns=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]],As=te("volume-2",Ns);function _s(t){const[e,r]=s.useState(null);return s.useEffect(()=>{t&&Rr(t).then(r)},[t]),{build:e}}function Ps(t){const[e,r]=s.useState([]),[o,i]=s.useState(null),[a,l]=s.useState(null),[f,d]=s.useState(""),[h,m]=s.useState(!1),[g,x]=s.useState(""),u=s.useCallback(C=>{C.type==="agents:listed"&&r(C.sessions),C.type==="session:joined"&&(m(!1),x("Connected")),C.type==="error"&&(m(!1),x(`Error: ${C.message}`))},[]),{send:v,connected:w}=Nn(u);s.useEffect(()=>{if(!w)return;v({type:"agents:list"});const C=setInterval(()=>v({type:"agents:list"}),5e3);return()=>clearInterval(C)},[w,v]);const N=s.useRef({sessionId:a,deviceId:f});s.useEffect(()=>{N.current={sessionId:a,deviceId:f}},[a,f]),s.useEffect(()=>()=>{const{sessionId:C,deviceId:$}=N.current;C&&$&&v({type:"device:shutdown",sessionId:C,payload:{deviceId:$}})},[v]);const k=e.filter(C=>C.devices.some($=>$.platform===t)),j=s.useCallback(C=>{d(C.id),m(!0),x("Booting…"),l(C.sessionId)},[]),_=s.useCallback(()=>d(""),[]),T=s.useCallback(()=>{const{sessionId:C,deviceId:$}=N.current;C&&$&&v({type:"device:shutdown",sessionId:C,payload:{deviceId:$}}),l(null),m(!1),x("")},[v]),L=s.useCallback(()=>{const{sessionId:C,deviceId:$}=N.current;C&&$&&v({type:"device:shutdown",sessionId:C,payload:{deviceId:$}}),l(null),i(null),m(!1),x(""),v({type:"agents:list"})},[v]),M=s.useCallback(()=>{l(null),i(null),m(!1),x(""),v({type:"agents:list"})},[v]);return{sessions:e,selectedAgent:o,setSelectedAgent:i,activeSessionId:a,deviceId:f,booting:h,status:g,send:v,connected:w,agentGroups:k,startDevice:j,resetDevice:_,handleBack:T,handleBackToMacs:L,handleSessionEnded:M}}function Ds(t,e){const[r,o]=s.useState(""),[i,a]=s.useState(""),[l,f]=s.useState("app-only"),[d,h]=s.useState("app-only"),m=(t==null?void 0:t.capabilities.includes("full-reset"))??!1,g=s.useCallback(()=>{h(m?l:"app-only"),f("app-only")},[l,m]),x=(t==null?void 0:t.devices.filter(w=>w.platform===e))??[],u=[...new Set(x.map(w=>w.osVersion).filter(Boolean))].sort((w,N)=>{const k=T=>T.replace(/^[^\d]*/,"").split(".").map(Number),[j,_]=[k(w),k(N)];for(let T=0;T<Math.max(j.length,_.length);T++){const L=(_[T]??0)-(j[T]??0);if(L!==0)return L}return 0}),v=(r?x.filter(w=>w.osVersion===r):x).filter(w=>!i||w.name.toLowerCase().includes(i.toLowerCase()));return{filteredDevices:x,osVersions:u,osVersion:r,setOsVersion:o,deviceSearch:i,setDeviceSearch:a,versionedDevices:v,resetMode:l,setResetMode:f,appliedResetMode:d,consumeResetMode:g,fullResetSupported:m}}function Ls(){const[t]=An(),e=t.get("perf")==="1",[r,o]=s.useState(e);return s.useEffect(()=>{if(!e){o(!1);return}o(!0);const i=a=>{a.ctrlKey&&a.shiftKey&&a.key==="P"&&o(l=>!l)};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[e]),{perfMode:e,visible:r}}const Is=["video/mp4;codecs=avc1","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];function Mn({sessionId:t,buildId:e,onRecordingUploaded:r}){const[o,i]=s.useState("idle"),a=s.useRef(null),l=s.useRef(r);s.useEffect(()=>{l.current=r},[r]);const f=s.useRef(!1),d=s.useRef(null),h=s.useRef([]),m=s.useRef(""),g=s.useRef(0),x=s.useRef(null),u=s.useCallback(function N(){var k;f.current&&((k=x.current)==null||k.call(x),g.current=requestAnimationFrame(N))},[]),v=s.useCallback(N=>{const k=a.current;if(!k)return;const j=k.getContext("2d");j&&(j.fillStyle="#000",j.fillRect(0,0,k.width,k.height));const _=Is.find(L=>MediaRecorder.isTypeSupported(L))??"";if(!_)return;m.current=_,h.current=[];const T=new MediaRecorder(k.captureStream(30),{mimeType:_});T.ondataavailable=L=>{L.data.size>0&&h.current.push(L.data)},d.current=T,T.start(1e3),x.current=N,f.current=!0,g.current=requestAnimationFrame(u),i("recording")},[u]),w=s.useCallback(async()=>{var L;i("uploading"),f.current=!1,cancelAnimationFrame(g.current);const N=d.current;if(!N){i("idle");return}await new Promise(M=>{const C=setTimeout(M,5e3);N.onstop=()=>{clearTimeout(C),M()};try{N.stop()}catch{clearTimeout(C),M()}}),d.current=null;const k=m.current,j=k.includes("mp4")?".mp4":".webm",_=new Blob(h.current,{type:k});h.current=[];const T=new FormData;T.append("file",_,`tapflow-${Date.now()}${j}`);try{const M=new URLSearchParams({sessionId:t});e&&M.set("buildId",String(e));const C=await fetch(`/api/v1/recordings/upload?${M}`,{method:"POST",credentials:"include",body:T}),$=await C.json();if(C.ok&&$.url){const K=document.createElement("a");K.href=$.url,K.download="",K.click(),(L=l.current)==null||L.call(l),i("done"),setTimeout(()=>i("idle"),2e3)}else i("idle")}catch{i("idle")}},[t,e]);return s.useEffect(()=>{if(o!=="recording")return;const N=()=>{document.visibilityState==="hidden"&&w()};return document.addEventListener("visibilitychange",N),()=>{var k;document.removeEventListener("visibilitychange",N),f.current&&(f.current=!1,cancelAnimationFrame(g.current),(k=d.current)==null||k.stop(),d.current=null)}},[o,w]),{recordState:o,recordCanvasRef:a,startClientRecording:v,stopClientRecording:w}}function Un(){const t=s.useRef(0),[e,r]=s.useState(0);return s.useEffect(()=>{const o=setInterval(()=>{r(t.current),t.current=0},1e3);return()=>clearInterval(o)},[]),{fps:e,frameCount:t}}function ut({className:t,...e}){return n.jsx("kbd",{"data-slot":"kbd",className:ee("bg-muted text-muted-foreground pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium","[&_svg:not([class*='size-'])]:size-3","[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10",t),...e})}function qt({className:t,...e}){return n.jsx("kbd",{"data-slot":"kbd-group",className:ee("inline-flex items-center gap-1",t),...e})}function St({label:t,keys:e}){return n.jsxs("span",{className:"flex items-center gap-3",children:[t,n.jsx(qt,{children:e.map(r=>n.jsx(ut,{children:r},r))})]})}const hn="text-muted-foreground hover:text-muted-foreground",pn="text-destructive hover:text-destructive";function Ms(t){switch(t){case"awaiting-app":return" Launch an app through tapflow so it is told too.";case"not-armed":return" Restart the device so tapflow can set it up.";case"state-unconfirmed":return" tapflow could not confirm the change — try again.";case"unsupported-device":return" The device did not change when tapflow asked — try again, or use another device.";case"filter-unavailable":return" This Mac is not set up to take devices off the network — see the network control guide.";case"enforcement-lost":return" It went back on the network on its own.";case"hooks-not-installed":return" tapflow cannot tell this app it is off the network.";default:return" tapflow cannot change it right now."}}function Us({position:t,steerable:e,reason:r}){const o=r==="awaiting-app",i=!e&&r==="state-unconfirmed"?" animate-pulse":"",a=e?"":Ms(r);switch(t){case"offline":return{Icon:ms,className:(e||o?"text-amber-500 hover:text-amber-500":pn)+i,status:`Device is offline.${a}`};case"online":return{Icon:Bt,className:(e||o?"":pn)+i,status:`Device is on the network.${a}`};case"waiting":return{Icon:Bt,className:`${hn} animate-pulse`,status:"Checking the network state."};case"unknown":return{Icon:Bt,className:hn,status:"No network state has been reported."}}}function $s({position:t,steerable:e,reason:r}){const o=t==="offline"?"Bring device online":t==="online"?"Take device offline":"Toggle device network",i=t==="online"||t==="offline",a=r==="state-unconfirmed"||r==="unsupported-device";return e||!i||r==="awaiting-app"?o:a?`Retry: ${o.toLowerCase()}`:`${o} — unavailable`}function $n({joined:t,onScreenshot:e,onRecordToggle:r,recordState:o,onRotate:i,onDeepLink:a,navigationSlot:l,deviceSlot:f,launchSlot:d,network:h,reboot:m}){const g=s.useId(),x=s.useId(),[u,v]=s.useState(!1);return t?n.jsxs(Vt,{delayDuration:400,children:[n.jsxs("div",{className:"flex flex-col items-center gap-0.5 rounded-2xl border bg-background/90 backdrop-blur-sm px-1.5 py-2.5 shrink-0 mt-3",children:[n.jsxs("div",{role:"group","aria-label":"Navigation",className:"flex flex-col items-center gap-0.5",children:[d,l,n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Open a deeplink",onClick:a,children:n.jsx(In,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:n.jsx(St,{label:"Deeplink",keys:["⌘","K"]})})]})]}),n.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"w-4 h-px bg-border my-1"}),n.jsxs("div",{role:"group","aria-label":"Device",className:"flex flex-col items-center gap-0.5",children:[f,n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Rotate the device",onClick:i,children:n.jsx(ys,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:n.jsx(St,{label:"Rotate",keys:["⌘","⇧","O"]})})]}),m&&(()=>{const w=m.pending?"Restarting the device":"Restart the device";return n.jsxs(n.Fragment,{children:[n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":w,"aria-busy":m.pending,"aria-disabled":m.pending,"aria-describedby":x,onClick:()=>{m.pending||v(!0)},children:m.pending?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(bs,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:w})]}),n.jsx("span",{id:x,role:"status",className:"sr-only",children:m.pending?"Restarting the device.":""})]})})()]}),n.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"w-4 h-px bg-border my-1"}),n.jsxs("div",{role:"group","aria-label":"Capture",className:"flex flex-col items-center gap-0.5",children:[n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Take a screenshot",onClick:e,children:n.jsx(Qr,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:n.jsx(St,{label:"Screenshot",keys:["⌘","S"]})})]}),n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:ee("h-8 w-8",o==="recording"&&"text-red-500 hover:text-red-500"),"aria-label":o==="recording"?"Stop recording":o==="uploading"?"Processing the recording":o==="done"?"Recording saved":"Start recording",disabled:o==="uploading"||o==="done",onClick:r,children:o==="uploading"?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):o==="recording"?n.jsx(ks,{className:"h-4 w-4 fill-current"}):n.jsx(Cs,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:o==="idle"?n.jsx(St,{label:"Start recording",keys:["⌘","⇧","Y"]}):o==="recording"?n.jsx(St,{label:"Stop recording",keys:["⌘","⇧","Y"]}):o==="done"?"Recording saved":"Processing…"})]})]}),h&&n.jsxs(n.Fragment,{children:[n.jsx("div",{role:"separator","aria-orientation":"horizontal",className:"w-4 h-px bg-border my-1"}),n.jsx("div",{role:"group","aria-label":"Environment",className:"flex flex-col items-center gap-0.5",children:h&&(()=>{const{Icon:w,className:N,status:k}=Us(h),j=$s(h),_=h.position==="waiting"||h.position==="unknown"||!h.steerable;return n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:ee("h-8 w-8",N),"aria-label":j,"aria-busy":h.pending,"aria-disabled":h.pending,"aria-describedby":g,onClick:()=>{h.pending||h.onToggle()},children:h.pending?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(w,{className:"h-4 w-4"})})}),n.jsx("span",{id:g,role:"status",className:"sr-only",children:h.pending?"Changing the network state.":k}),n.jsx(je,{side:"left",children:_?`${j} — ${k}`:j})]})})()})]})]}),m&&n.jsx(Ar,{open:u,onOpenChange:v,children:n.jsxs(_r,{children:[n.jsxs(Pr,{children:[n.jsx(Dr,{children:"Restart this device?"}),n.jsx(Lr,{children:"Anything open on the device closes, and whatever you had set up on screen is gone. Installed apps and their data stay. The device takes a moment to come back."})]}),n.jsxs(Ir,{children:[n.jsx(Mr,{children:"Cancel"}),n.jsx(Ur,{onClick:()=>{v(!1),m.onReboot()},children:"Restart"})]})]})})]}):null}const Os=3e3,Fs=8e3;function On({sessionId:t,send:e,supported:r,deviceReady:o,handlerRef:i,onError:a}){const[l,f]=s.useState("waiting"),[d,h]=s.useState(!0),[m,g]=s.useState(void 0),x=s.useRef(void 0),[u,v]=s.useState(!1),w=s.useRef(null),N=s.useRef(new Set),k=s.useRef(a);s.useEffect(()=>{k.current=a},[a]);const j=s.useRef(o);s.useEffect(()=>{j.current=o},[o]);const _=s.useRef(o);s.useEffect(()=>{f("waiting"),h(!0),g(void 0),x.current=void 0,v(!1),w.current=null,_.current=j.current,N.current.clear()},[t]),s.useEffect(()=>{var C;if(o){_.current=!0,f("waiting");return}f(_.current?"unknown":"waiting"),h(!0),g(void 0),x.current=void 0,w.current&&((C=k.current)==null||C.call(k,"The device became unavailable before it answered. Its network state is unchanged as far as tapflow can tell."),N.current.add(w.current)),v(!1),w.current=null},[o]),s.useEffect(()=>{if(r)return i.current=C=>{var K,V;if(C.type==="network:error"){C.requestId===w.current&&(w.current=null,v(!1),(K=k.current)==null||K.call(k,C.message));return}if(C.type!=="network:state"||!j.current||C.requestId!==void 0&&N.current.has(C.requestId))return;const $=C.payload.available?void 0:C.payload.reason;f(C.payload.offline?"offline":"online"),h(C.payload.available),g($),$==="enforcement-lost"&&x.current!=="enforcement-lost"&&((V=k.current)==null||V.call(k,"The device went back on the network before you took it off. Anything checked while it was offline needs checking again.")),x.current=$,C.requestId!==void 0&&C.requestId===w.current&&(w.current=null,v(!1))},()=>{i.current=void 0}},[i,r]),s.useEffect(()=>{if(!r||!o||l!=="waiting")return;const C=setTimeout(()=>f($=>$==="waiting"?"unknown":$),Os);return()=>clearTimeout(C)},[r,o,l]);const T=s.useCallback(()=>{if(!r||u)return;const C=X();w.current=C,v(!0),e({type:"network:set",sessionId:t,requestId:C,payload:{offline:l!=="offline"}})},[l,u,e,t,r]),[L,M]=s.useState(null);return s.useEffect(()=>{M(u?w.current:null)},[u]),s.useEffect(()=>{if(L===null)return;const C=setTimeout(()=>{var $;w.current===L&&(w.current=null,v(!1),($=k.current)==null||$.call(k,"The device did not answer. Its network state is unchanged as far as tapflow can tell."))},Fs);return()=>clearTimeout(C)},[L]),{position:l,steerable:d,reason:m,pending:u,toggle:T}}class Xt{constructor(e){this.bytes=e,this.bitPos=0}get position(){return this.bitPos}bit(){const e=this.bitPos>>3,r=7-(this.bitPos&7);return this.bitPos++,e>=this.bytes.length?0:this.bytes[e]>>r&1}bits(e){let r=0;for(let o=0;o<e;o++)r=r<<1|this.bit();return r>>>0}flag(){return this.bit()===1}ue(){let e=0;for(;this.bit()===0&&e<32;)e++;return e===0?0:(1<<e)-1+this.bits(e)}se(){const e=this.ue();return e&1?Math.ceil(e/2):-Math.ceil(e/2)}}class Bs{constructor(){this.bitsArr=[]}bit(e){this.bitsArr.push(e&1)}ue(e){const r=e+1,o=Math.floor(Math.log2(r));for(let i=0;i<o;i++)this.bit(0);for(let i=o;i>=0;i--)this.bit(r>>i&1)}toBytes(){const e=[];for(let r=0;r<this.bitsArr.length;r+=8){let o=0;for(let i=0;i<8;i++)o=o<<1|(this.bitsArr[r+i]??0);e.push(o)}return new Uint8Array(e)}}function Fn(t){const e=[];let r=0;for(let o=1;o<t.length;o++){const i=t[o];if(r>=2&&i===3){r=0;continue}e.push(i),r=i===0?r+1:0}return new Uint8Array(e)}function Hs(t){const e=[];let r=0;for(const o of t)r>=2&&o<=3&&(e.push(3),r=0),e.push(o),r=o===0?r+1:0;return new Uint8Array(e)}const zs=new Set([100,110,122,244,44,83,86,118,128,138,139,134,135]);function mn(t){const e=t.ue()+1;t.bits(4),t.bits(4);for(let r=0;r<e;r++)t.ue(),t.ue(),t.flag();t.bits(5),t.bits(5),t.bits(5),t.bits(5)}function Bn(t){const e=t.bits(8);t.bits(8);const r=t.bits(8);if(t.ue(),zs.has(e)){const g=t.ue();if(g===3&&t.flag(),t.ue(),t.ue(),t.flag(),t.flag()){const x=g!==3?8:12;for(let u=0;u<x;u++)if(t.flag()){const v=u<6?16:64;let w=8,N=8;for(let k=0;k<v;k++)N!==0&&(N=(w+t.se()+256)%256),w=N===0?w:N}}}t.ue();const o=t.ue();if(o===0)t.ue();else if(o===1){t.flag(),t.se(),t.se();const g=t.ue();for(let x=0;x<g;x++)t.se()}const i=t.ue();t.flag(),t.ue(),t.ue(),t.flag()||t.flag(),t.flag(),t.flag()&&(t.ue(),t.ue(),t.ue(),t.ue());const a={profileIdc:e,levelIdc:r,numRefFrames:i,bitstreamRestriction:!1,maxNumReorderFrames:null,maxDecFrameBuffering:null};if(!t.flag())return{...a,vuiPresent:!1,restrictionFlagPos:-1};t.flag()&&t.bits(8)===255&&(t.bits(16),t.bits(16)),t.flag()&&t.flag(),t.flag()&&(t.bits(3),t.flag(),t.flag()&&(t.bits(8),t.bits(8),t.bits(8))),t.flag()&&(t.ue(),t.ue()),t.flag()&&(t.bits(32),t.bits(32),t.flag());const f=t.flag();f&&mn(t);const d=t.flag();d&&mn(t),(f||d)&&t.flag(),t.flag();const h=t.position;return t.flag()?(t.flag(),t.ue(),t.ue(),t.ue(),t.ue(),{...a,vuiPresent:!0,bitstreamRestriction:!0,maxNumReorderFrames:t.ue(),maxDecFrameBuffering:t.ue(),restrictionFlagPos:h}):{...a,vuiPresent:!0,restrictionFlagPos:h}}function Ws(t){const e=Bn(new Xt(Fn(t)));return{profileIdc:e.profileIdc,levelIdc:e.levelIdc,vuiPresent:e.vuiPresent,bitstreamRestriction:e.bitstreamRestriction,maxNumReorderFrames:e.maxNumReorderFrames,maxDecFrameBuffering:e.maxDecFrameBuffering}}function Vs(t){const e=Fn(t),r=Bn(new Xt(e));if(!r.vuiPresent||r.restrictionFlagPos<0||r.bitstreamRestriction)return null;const o=new Bs,i=new Xt(e);for(let a=0;a<r.restrictionFlagPos;a++)o.bit(i.bit());return o.bit(1),o.bit(1),o.ue(0),o.ue(0),o.ue(0),o.ue(0),o.ue(0),o.ue(r.numRefFrames),o.bit(1),Uint8Array.from([t[0],...Hs(o.toBytes())])}function qs(t){const e=[],r=t.length;let o=-1,i=0;for(;i+2<r;){const a=i+3<r&&t[i]===0&&t[i+1]===0&&t[i+2]===0&&t[i+3]===1,l=t[i]===0&&t[i+1]===0&&t[i+2]===1;a||l?(o>=0&&e.push(t.subarray(o,i)),i+=a?4:3,o=i):i++}return o>=0&&e.push(t.subarray(o,r)),e}class Xs{constructor(e){this.onFrame=e,this.decoder=null,this.sps=null,this.pps=null,this.frameCount=0,this.submitAt=new Map,this.spsLogged=!1}setDecodeSampler(e){this.decodeSampler=e}decode(e){const r=[];let o=!1;for(const h of qs(new Uint8Array(e))){const m=h[0]&31;if(m===7){const g=!this.sps||h.length!==this.sps.length||h.some((x,u)=>x!==this.sps[u]);this.sps=h,g&&this.decoder&&(this.decoder.close(),this.decoder=null)}else m===8?this.pps=h:m>=1&&m<=5&&(m===5&&(o=!0),r.push(h))}if(o&&this.sps&&this.pps&&!this.decoder&&this.initDecoder(this.sps,this.pps),!this.decoder||r.length===0)return;let i=0;for(const h of r)i+=4+h.length;const a=new Uint8Array(i),l=new DataView(a.buffer);let f=0;for(const h of r)l.setUint32(f,h.length,!1),f+=4,a.set(h,f),f+=h.length;const d=Math.round(this.frameCount++*(1e6/30));if(this.decodeSampler&&(this.submitAt.set(d,performance.now()),this.submitAt.size>120)){const h=this.submitAt.keys().next().value;h!==void 0&&this.submitAt.delete(h)}try{this.decoder.decode(new EncodedVideoChunk({type:o?"key":"delta",timestamp:d,data:a}))}catch{}}sampleDecode(e){var o;if(!this.decodeSampler)return;const r=this.submitAt.get(e.timestamp);r!==void 0&&(this.submitAt.delete(e.timestamp),this.decodeSampler({decodeMs:performance.now()-r,queueSize:((o=this.decoder)==null?void 0:o.decodeQueueSize)??0}))}close(){var e;(e=this.decoder)==null||e.close(),this.decoder=null}logSpsVui(e){if(!(this.spsLogged||!this.decodeSampler)){this.spsLogged=!0;try{console.log("[sps-vui]",JSON.stringify(Ws(e)))}catch(r){console.warn("[sps-vui] parse failed",r)}}}initDecoder(e,r){this.logSpsVui(e);const o=Vs(e)??e,i=o[0]===0?o.subarray(4):o,a=`avc1.${i[1].toString(16).padStart(2,"0")}${i[2].toString(16).padStart(2,"0")}${i[3].toString(16).padStart(2,"0")}`,l=this.buildAVCC(o,r);this.decoder=new VideoDecoder({output:f=>{this.sampleDecode(f),this.onFrame(f)},error:f=>console.error("[WebCodecsCore]",f)}),this.decoder.configure({codec:a,description:l,optimizeForLatency:!0})}buildAVCC(e,r){const o=e[0]===0?e.subarray(4):e,i=r[0]===0?r.subarray(4):r,a=new Uint8Array(8+o.length+1+2+i.length);let l=0;return a[l++]=1,a[l++]=o[1],a[l++]=o[2],a[l++]=o[3],a[l++]=255,a[l++]=225,a[l++]=o.length>>8&255,a[l++]=o.length&255,a.set(o,l),l+=o.length,a[l++]=1,a[l++]=i.length>>8&255,a[l++]=i.length&255,a.set(i,l),a}}const Ks=`#version 300 es
107
+ in vec2 a_pos;
108
+ out vec2 v_uv;
109
+ void main() {
110
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
111
+ gl_Position = vec4(a_pos, 0.0, 1.0);
112
+ }`,Ys=`#version 300 es
113
+ precision mediump float;
114
+ in vec2 v_uv;
115
+ uniform sampler2D u_tex;
116
+ out vec4 out_color;
117
+ void main() {
118
+ out_color = texture(u_tex, v_uv);
119
+ }`;function Gs(t){const e=t.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!e)return null;const r=(m,g)=>{const x=e.createShader(m);return e.shaderSource(x,g),e.compileShader(x),x},o=e.createProgram(),i=r(e.VERTEX_SHADER,Ks),a=r(e.FRAGMENT_SHADER,Ys);e.attachShader(o,i),e.attachShader(o,a),e.linkProgram(o),e.deleteShader(i),e.deleteShader(a),e.useProgram(o);const l=e.createVertexArray();e.bindVertexArray(l);const f=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,f),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),e.STATIC_DRAW);const d=e.getAttribLocation(o,"a_pos");e.enableVertexAttribArray(d),e.vertexAttribPointer(d,2,e.FLOAT,!1,0,0),e.bindVertexArray(null);const h=e.createTexture();return e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,h),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(e.getUniformLocation(o,"u_tex"),0),{gl:e,program:o,tex:h,vao:l}}class Js{constructor(e){this.canvas=e,this.state=null}init(){return this.state=Gs(this.canvas),this.state!==null}drawFrame(e){const r=this.state;if(!r)return e.close(),null;const o=e.displayWidth,i=e.displayHeight;try{return(this.canvas.width!==o||this.canvas.height!==i)&&(this.canvas.width=o,this.canvas.height=i,r.gl.viewport(0,0,o,i)),r.gl.activeTexture(r.gl.TEXTURE0),r.gl.bindTexture(r.gl.TEXTURE_2D,r.tex),r.gl.texImage2D(r.gl.TEXTURE_2D,0,r.gl.RGBA,r.gl.RGBA,r.gl.UNSIGNED_BYTE,e),r.gl.bindVertexArray(r.vao),r.gl.drawArrays(r.gl.TRIANGLES,0,6),r.gl.bindVertexArray(null),r.gl.bindTexture(r.gl.TEXTURE_2D,null),{width:o,height:i}}finally{e.close()}}dispose(){const e=this.state;e&&(e.gl.deleteTexture(e.tex),e.gl.deleteVertexArray(e.vao),e.gl.deleteProgram(e.program),this.state=null)}}function Qs(t){const e=new Js(t);return e.init(),e}class Zs{constructor(e=Qs){this._size=null,this.canvas=document.createElement("canvas"),this.renderer=e(this.canvas),this.core=new Xs(r=>this.render(r))}get surface(){return this.canvas}get size(){return this._size}onResize(e){this.resizeCb=e}onDecodedFrame(e){this.decodedCb=e,this.core.setDecodeSampler(r=>{this.lastSample=r})}decode(e){this.core.decode(e)}close(){this.core.close(),this.renderer.dispose()}render(e){var o,i;const r=this.renderer.drawFrame(e);r&&((o=this.decodedCb)==null||o.call(this,performance.now(),this.lastSample),this.lastSample=void 0,(!this._size||this._size.width!==r.width||this._size.height!==r.height)&&(this._size=r,(i=this.resizeCb)==null||i.call(this,r)))}}const eo=`#version 300 es
120
+ in vec2 a_pos;
121
+ out vec2 v_uv;
122
+ void main() {
123
+ v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
124
+ gl_Position = vec4(a_pos, 0.0, 1.0);
125
+ }`,to=`#version 300 es
126
+ precision mediump float;
127
+ in vec2 v_uv;
128
+ uniform sampler2D u_texY;
129
+ uniform sampler2D u_texU;
130
+ uniform sampler2D u_texV;
131
+ out vec4 out_color;
132
+ void main() {
133
+ float Y = (texture(u_texY, v_uv).r - 0.0627451) * 1.1643836; // (y-16/255)*255/219
134
+ float U = (texture(u_texU, v_uv).r - 0.5019608) * 1.1383929; // (u-128/255)*255/224
135
+ float V = (texture(u_texV, v_uv).r - 0.5019608) * 1.1383929;
136
+ float r = Y + 1.5748 * V;
137
+ float g = Y - 0.1873 * U - 0.4681 * V;
138
+ float b = Y + 1.8556 * U;
139
+ out_color = vec4(r, g, b, 1.0);
140
+ }`;function Ht(t,e,r,o){const i=t.createTexture();return t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.uniform1i(t.getUniformLocation(o,r),e),i}function no(t){const e=t.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!e)return null;const r=(x,u)=>{const v=e.createShader(x);return e.shaderSource(v,u),e.compileShader(v),v},o=e.createProgram(),i=r(e.VERTEX_SHADER,eo),a=r(e.FRAGMENT_SHADER,to);e.attachShader(o,i),e.attachShader(o,a),e.linkProgram(o),e.deleteShader(i),e.deleteShader(a),e.useProgram(o);const l=e.createVertexArray();e.bindVertexArray(l);const f=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,f),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),e.STATIC_DRAW);const d=e.getAttribLocation(o,"a_pos");e.enableVertexAttribArray(d),e.vertexAttribPointer(d,2,e.FLOAT,!1,0,0),e.bindVertexArray(null),e.pixelStorei(e.UNPACK_ALIGNMENT,1);const h=Ht(e,0,"u_texY",o),m=Ht(e,1,"u_texU",o),g=Ht(e,2,"u_texV",o);return{gl:e,program:o,texY:h,texU:m,texV:g,vao:l}}class ro{constructor(e){this.canvas=e,this.state=null}init(){return this.state=no(this.canvas),this.state!==null}drawI420(e,r,o){const i=this.state;if(!i)return null;const{gl:a}=i,l=r+1>>1,f=o+1>>1,d=r*o,h=l*f,m=e.subarray(0,d),g=e.subarray(d,d+h),x=e.subarray(d+h,d+2*h);(this.canvas.width!==r||this.canvas.height!==o)&&(this.canvas.width=r,this.canvas.height=o,a.viewport(0,0,r,o));const u=(v,w,N,k,j)=>{a.activeTexture(a.TEXTURE0+v),a.bindTexture(a.TEXTURE_2D,w),a.texImage2D(a.TEXTURE_2D,0,a.R8,N,k,0,a.RED,a.UNSIGNED_BYTE,j)};return u(0,i.texY,r,o,m),u(1,i.texU,l,f,g),u(2,i.texV,l,f,x),a.bindVertexArray(i.vao),a.drawArrays(a.TRIANGLES,0,6),a.bindVertexArray(null),{width:r,height:o}}dispose(){const e=this.state;e&&(e.gl.deleteTexture(e.texY),e.gl.deleteTexture(e.texU),e.gl.deleteTexture(e.texV),e.gl.deleteVertexArray(e.vao),e.gl.deleteProgram(e.program),this.state=null)}}const so=0;function oo(t){const e=new ro(t);return e.init(),e}function ao(){return new Worker(new URL("/assets/tinyh264.worker-DiJ50Hai.js",import.meta.url),{type:"module"})}class io{constructor(e=oo,r=ao){this.ready=!1,this.pending=[],this._size=null,this.canvas=document.createElement("canvas"),this.renderer=e(this.canvas),this.worker=r(),this.worker.onmessage=o=>this.onMessage(o.data)}get surface(){return this.canvas}get size(){return this._size}onResize(e){this.resizeCb=e}onDecodedFrame(e){this.decodedCb=e}decode(e){if(!this.ready){this.pending.push(e);return}this.post(e)}close(){this.worker.terminate(),this.renderer.dispose()}post(e){this.worker.postMessage({type:"decode",data:e,offset:0,length:e.byteLength,renderStateId:so},[e])}onMessage(e){var o,i;if(e.type==="decoderReady"){this.ready=!0;for(const a of this.pending)this.post(a);this.pending.length=0;return}const r=this.renderer.drawI420(new Uint8Array(e.data),e.width,e.height);r&&((o=this.decodedCb)==null||o.call(this,performance.now()),(!this._size||this._size.width!==r.width||this._size.height!==r.height)&&(this._size=r,(i=this.resizeCb)==null||i.call(this,r)))}}function Jt(){const t=typeof window<"u";let e=!1;try{e=!!document.createElement("canvas").getContext("webgl2")}catch{e=!1}return{secureContext:t&&window.isSecureContext===!0,webCodecs:t&&"VideoDecoder"in window,webgl2:e,wasm:typeof WebAssembly<"u"&&typeof Worker<"u"}}function co(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2?new Zs:t.wasm&&t.webgl2?new io:null}function lo(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2||t.wasm&&t.webgl2}function uo(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2?"high":t.wasm&&t.webgl2?"standard":"unsupported"}const fo="https://www.tapflow.dev/reference/configuration#https-secure-context";function ho({open:t,onOpenChange:e}){return n.jsx(_n,{open:t,onOpenChange:e,children:n.jsxs(Pn,{className:"sm:max-w-[440px]",children:[n.jsxs($r,{children:[n.jsx(Dn,{children:"Streaming in Standard mode"}),n.jsxs(Or,{className:"space-y-3 pt-1",children:[n.jsx("span",{className:"block",children:"This screen is running in Standard mode. For a faster, smoother picture, switch to Smooth."}),n.jsx("span",{className:"block",children:"Smooth needs the relay served over HTTPS. If you didn't set up tapflow, ask whoever did."})]})]}),n.jsxs(Fr,{children:[n.jsx(ie,{variant:"outline",onClick:()=>window.open(fo,"_blank","noopener,noreferrer"),children:"How to enable"}),n.jsx(ie,{onClick:()=>e(!1),children:"Got it"})]})]})})}const gn="tapflow.perfModeNoticeDismissed";function po(t,e){return t==="standard"&&!e}const mo={high:"Smooth",standard:"Standard",unsupported:null};function go(t){const{connected:e,joined:r,bootError:o,deviceReady:i,installing:a,installError:l,agentAway:f}=t;return e?r?f?"The agent went away — waiting for it to come back…":o?`Boot failed: ${o.length>40?o.slice(0,40)+"…":o}`:i?a?"Installing app…":l?`Install failed: ${l}`:null:"Starting device…":"Joining session…":"Connecting…"}function Qt(t){const{joined:e,fps:r,keyboardActive:o}=t,i=go(t),a=r>15,l=a?"#10b981":"#94a3b8",f=a?"Active":"Idle",d=s.useMemo(()=>uo(),[]),h=mo[d],[m,g]=s.useState(!1);s.useEffect(()=>{let u=!1;try{u=localStorage.getItem(gn)==="1"}catch{}po(d,u)&&g(!0)},[d]);const x=u=>{if(g(u),!u)try{localStorage.setItem(gn,"1")}catch{}};return n.jsxs("div",{className:"w-[300px] shrink-0 mt-3 rounded-xl border bg-background px-4 py-4 flex flex-col gap-3",children:[n.jsxs("div",{className:ee("flex items-center",o?"text-emerald-500":"text-muted-foreground"),style:{gap:6},children:[n.jsx(Ss,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"text-[12px] font-medium",children:"Focus"})]}),e&&n.jsxs("div",{className:"flex items-center gap-[12px]",children:[n.jsxs("div",{className:"flex items-center gap-[4px]",children:[n.jsx("span",{className:"h-2 w-2 rounded-full shrink-0 mr-1",style:{background:l}}),n.jsx("span",{className:"text-[12px] font-mono text-foreground/75",children:r}),n.jsx("span",{className:"text-[12px] text-muted-foreground",children:"fps"}),n.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:"·"}),n.jsx("span",{className:ee("text-[11px]",a?"text-emerald-500":"text-muted-foreground/60"),children:f})]}),h&&n.jsxs(n.Fragment,{children:[n.jsx(Cn,{orientation:"vertical",className:"h-3"}),d==="standard"?n.jsx("button",{type:"button",onClick:()=>g(!0),className:"text-[11px] text-foreground/70 hover:text-foreground underline-offset-2 hover:underline",children:h}):n.jsx("span",{className:"text-[11px] text-muted-foreground",children:h})]})]}),n.jsx("div",{role:"status",className:i?void 0:"sr-only",children:i&&n.jsx("p",{className:"text-[12px] text-muted-foreground leading-relaxed break-all",children:i})}),n.jsx(ho,{open:m,onOpenChange:x})]})}function Hn({open:t,onOpenChange:e,openUrl:r}){const[o,i]=s.useState(""),a=s.useRef(null);s.useEffect(()=>{t?setTimeout(()=>{var f;return(f=a.current)==null?void 0:f.focus()},0):i("")},[t]);const l=()=>{o.trim()&&(r(o.trim()),e(!1))};return n.jsx(_n,{open:t,onOpenChange:e,children:n.jsxs(Pn,{className:"w-[500px] max-w-[500px] h-[52px] !rounded-[18px] p-[10px] border border-border bg-background shadow-lg overflow-hidden [&>button]:hidden","aria-describedby":void 0,children:[n.jsx(Dn,{className:"sr-only",children:"Open Deeplink"}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("div",{className:"flex-1 h-[32px] flex items-center gap-2 pl-[4px] pb-[1px]",children:[n.jsx(kr,{className:"h-4 w-4 text-muted-foreground shrink-0","aria-hidden":"true"}),n.jsx("input",{ref:a,"aria-label":"Deeplink URL",className:"flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground min-w-0",placeholder:"myapp://home...",value:o,onChange:f=>i(f.target.value),onKeyDown:f=>{f.key==="Enter"&&l()}})]}),n.jsx(ie,{size:"sm",disabled:!o.trim(),onClick:l,className:"shrink-0 rounded-xl h-8 px-4",children:"Open"})]})]})})}function xo(t,e,r,o,i,a){const{x:l,y:f,width:d,height:h}=i;let m,g;if(a){const x=(t.x-e.left)/e.width;m=(1-(t.y-e.top)/e.height)*r,g=x*o}else m=(t.x-e.left)*(r/e.width),g=(t.y-e.top)*(o/e.height);return m<l||m>l+d||g<f||g>f+h?null:{x:(m-l)/d,y:(g-f)/h}}function bo(t,e,r){const o=(t.x-e.left)/e.width,i=(t.y-e.top)/e.height;return o<0||o>1||i<0||i>1?null:r?{x:i,y:1-o}:{x:o,y:i}}function zn(t){return{f0:{x:1-t.x,y:1-t.y},f1:t}}function vo(t,e){return t>0?Math.min(1,e/t):1}const Kt=22,xn=[84,70,70,69],yo=1,wo=0,Mt=1,Wn=2,So=1,Ro=2,ko=4;function jo(t){if(t.byteLength<Kt)return null;const e=new DataView(t);for(let i=0;i<xn.length;i++)if(e.getUint8(i)!==xn[i])return null;if(e.getUint8(4)!==yo)return null;const r=e.getUint8(5),o=r&ko?Wn:r&So?Mt:wo;return{capturedAt:Number(e.getBigUint64(6)),relayedAt:Number(e.getBigUint64(14)),codec:o,keyframe:o===Mt&&(r&Ro)!==0}}function Vn(t){const{binaryFrameHandlerRef:e,perfHookRef:r,frameCount:o}=t,i=s.useRef(t);s.useLayoutEffect(()=>{i.current=t},[t]),s.useEffect(()=>{let a=null,l=!1,f=!1,d;const h=()=>{if(a)return a;if(l)return null;const m=co();return m?(a=m,m.onResize(g=>i.current.onResize(g)),d=i.current.onDecoderReady(m),m):(l=!0,i.current.onUnsupported(),console.warn("[decoder] none available — set up HTTPS or use a supported browser"),null)};return e.current=(m,g)=>{const x=i.current.onJpegFrame;if(x&&(g==null?void 0:g.codec)!==Mt){x(m,g);return}const u=h();if(u){if(!f){if(!(g!=null&&g.keyframe))return;f=!0}u.decode(m),o.current+=1}},()=>{e.current=void 0,typeof d=="function"&&d(),a==null||a.close(),a==null||a.surface.remove(),a=null}},[e,r,o])}const Co=3e3+5*300,To=Co+500,Pt=8;function Eo(){var t;return window.isSecureContext&&typeof ClipboardItem<"u"&&!!((t=navigator.clipboard)!=null&&t.write)}class Rt extends Error{}function No(t){const e=t.then(r=>new Blob([r],{type:"text/plain"}));return navigator.clipboard.write([new ClipboardItem({"text/plain":e})])}function Zt(t){return!(t.metaKey||t.ctrlKey)||t.altKey?!1:t.code==="KeyV"?!0:!t.shiftKey&&(t.code==="KeyC"||t.code==="KeyX")}const Ao=1024*1024,_o=t=>new TextEncoder().encode(t).length,Po=t=>{var e;return!!((e=t.payload)!=null&&e.unsupported)},Do=t=>{var e,r;return((e=t.payload)==null?void 0:e.sentinelParked)===!1||((r=t.payload)==null?void 0:r.unsupported)===!0};function Lo(){const t=window.getSelection();return!!t&&!t.isCollapsed&&t.toString().length>0}function bn(){const t=document.activeElement;return!!t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable)}function qn({sessionId:t,send:e,active:r,supported:o,handlerRef:i,sendChord:a,onError:l}){const f=s.useRef(new Map),d=s.useRef(null),h=s.useRef(l);s.useLayoutEffect(()=>{h.current=l});const m=s.useCallback(x=>{var u;d.current!==x&&(d.current=x,(u=h.current)==null||u.call(h,x))},[]);s.useEffect(()=>(i.current=x=>{if(!x.requestId)return;const u=f.current.get(x.requestId);u&&(f.current.delete(x.requestId),u(x))},()=>{i.current=void 0}),[i]);const g=s.useCallback((...[x,u])=>{const v=X();return new Promise(w=>{const N=setTimeout(()=>{f.current.delete(v),w(null)},To);f.current.set(v,k=>{clearTimeout(N),w(k)}),e({type:x,sessionId:t,requestId:v,payload:u})})},[e,t]);s.useEffect(()=>{if(!r||!o)return;const x=async v=>{if(v.code==="KeyV"||!Zt(v))return;const w=v.code==="KeyX";if(bn()||Lo()||(v.preventDefault(),v.repeat))return;if(!Eo()){a(w?"KeyX":"KeyC",Pt),m("Copied on the device. Serving the dashboard over HTTPS also brings it to your clipboard.");return}let N,k;const j=new Promise((M,C)=>{N=M,k=C});j.catch(()=>{});const _=No(j).catch(M=>{M instanceof Rt||m(M instanceof Error&&M.name==="NotAllowedError"?"Your browser blocked the clipboard write":"Could not write to your clipboard")}),T=await g("clipboard:read",{press:w?"cut":"copy"});if(!T){k(new Rt("timeout")),m("The device is taking too long — try again");return}if(T.type==="clipboard:error"){k(new Rt(T.message||"read failed")),m(T.message||"Clipboard read failed"),Do(T)&&a(w?"KeyX":"KeyC",Pt);return}if(T.type!=="clipboard:data"){k(new Rt("unexpected reply")),m("Clipboard read failed");return}const{text:L}=T.payload;if(d.current=null,!L){k(new Rt("empty"));return}N(L),await _},u=v=>{var N;if(bn())return;const w=((N=v.clipboardData)==null?void 0:N.getData("text"))??"";if(v.preventDefault(),!w){a("KeyV",Pt);return}if(_o(w)>Ao){m("That text is too large to send to the device");return}g("clipboard:write",{text:w,pasteAfter:!0}).then(k=>{if(!k){m("The device is taking too long — try again");return}if(k.type==="clipboard:write-done"){d.current=null;return}if(k.type!=="clipboard:error"){m("Clipboard write failed");return}m(k.message||"Clipboard write failed"),Po(k)&&a("KeyV",Pt)})};return document.addEventListener("keydown",x),document.addEventListener("paste",u),()=>{document.removeEventListener("keydown",x),document.removeEventListener("paste",u)}},[r,o,g,a,m])}const He=13,ct=8,vn=16,Io=.02,Mo=100;function Uo({sessionId:t,buildId:e,send:r,openUrl:o,launchApp:i,connected:a,joined:l,deviceReady:f,installing:d,installed:h,installError:m,bootError:g,launching:x,chrome:u,binaryFrameHandlerRef:v,clipboardHandlerRef:w,clipboardSupported:N,networkHandlerRef:k,networkSupported:j,onRecordingUploaded:_,swKeyboardVisible:T,swKeyboardPending:L,onKbdToggle:M,rebootPending:C,onReboot:$,viewerRootRef:K,perfHookRef:V}){const O=s.useRef(null),G=s.useRef(null),ue=s.useRef(null),{fps:_e,frameCount:Me}=Un(),ge=s.useRef(0),{recordState:xe,recordCanvasRef:J,startClientRecording:Te,stopClientRecording:Ue}=Mn({sessionId:t,buildId:e,onRecordingUploaded:_}),$e=s.useRef(0),[Pe,De]=s.useState(!1),[U,q]=s.useState(!1),[B,we]=s.useState(!1),[ce,be]=s.useState(!1),[Le,Y]=s.useState(null),[Oe,ht]=s.useState(null),[Ke,se]=s.useState(!1),[ne,le]=s.useState(null),Z=s.useRef(ne);s.useEffect(()=>{Z.current=ne},[ne]);const de=s.useRef(null),pe=s.useRef(null),fe=s.useRef(!1),he=s.useRef(!1),ve=s.useRef(0),oe=s.useRef(null),me=s.useRef(null),ye=s.useRef("idle"),Se=s.useRef(null),Fe=s.useRef(null),Ie=s.useRef(null);s.useEffect(()=>{Ie.current=u},[u]),s.useEffect(()=>{const c=new Image;c.onload=()=>{Fe.current=c},c.src=`data:image/png;base64,${u.framePng}`},[u.framePng]),Vn({binaryFrameHandlerRef:v,perfHookRef:V,frameCount:Me,onUnsupported:()=>{},onResize:c=>{const b=O.current;if(b&&(b.width!==c.width||b.height!==c.height)&&(b.width=c.width,b.height=c.height,!Ie.current)){const p=J.current;p&&(p.width=c.width,p.height=c.height)}q(!0)},onDecoderReady:c=>{var y;const b=c.surface,p=O.current;b.style.position="absolute",p&&(b.style.left=p.style.left,b.style.top=p.style.top,b.style.width=p.style.width,b.style.height=p.style.height,b.style.borderRadius=p.style.borderRadius),b.style.objectFit="fill",b.style.zIndex="3",b.style.pointerEvents="none",(y=G.current)==null||y.appendChild(b);let D=null;const E=()=>{const A=O.current,I=A==null?void 0:A.getContext("2d");if(A&&I&&c.size)try{I.drawImage(c.surface,0,0,A.width,A.height)}catch{}D=requestAnimationFrame(E)};return D=requestAnimationFrame(E),()=>{D!==null&&cancelAnimationFrame(D)}},onJpegFrame:c=>{const b=performance.now();ge.current&&b-ge.current,ge.current=b;const p=$e.current;createImageBitmap(new Blob([c],{type:"image/jpeg"})).then(D=>{if(performance.now()-b,$e.current!==p){D.close();return}const E=O.current,y=E==null?void 0:E.getContext("2d");if(!E||!y){D.close();return}if((E.width!==D.width||E.height!==D.height)&&(E.width=D.width,E.height=D.height,!Ie.current)){const I=J.current;I&&(I.width=D.width,I.height=D.height)}const A=performance.now();y.drawImage(D,0,0),performance.now()-A,D.close(),q(!0),Me.current+=1}).catch(()=>{})}}),s.useEffect(()=>{const c=J.current,b=G.current;c&&b&&(c.width=b.clientWidth,c.height=b.clientHeight)},[u,J]);const S=s.useCallback(()=>{const c=J.current,b=O.current;if(!c||!b)return;const p=c.getContext("2d");if(!p)return;const D=Ie.current;if(p.clearRect(0,0,c.width,c.height),D){Fe.current&&p.drawImage(Fe.current,0,0,c.width,c.height);const A=Math.round(D.screenCornerRadius/2*(c.height/(D.compositeHeight/2)));p.save(),p.beginPath(),A>0?p.roundRect(b.offsetLeft,b.offsetTop,b.clientWidth,b.clientHeight,A):p.rect(b.offsetLeft,b.offsetTop,b.clientWidth,b.clientHeight),p.clip(),p.drawImage(b,b.offsetLeft,b.offsetTop,b.clientWidth,b.clientHeight),p.restore()}else p.drawImage(b,0,0,c.width,c.height);const E=Z.current;if(E)for(const A of[E.f0,E.f1]){const I=D?b.offsetLeft+A.x*b.clientWidth:A.x*c.width,Q=D?b.offsetTop+A.y*b.clientHeight:A.y*c.height;fe.current?(p.beginPath(),p.arc(I,Q,ct,0,Math.PI*2),p.fillStyle="rgba(255,255,255,0.92)",p.fill(),p.strokeStyle="rgba(0,0,0,0.2)",p.lineWidth=1,p.stroke()):(p.beginPath(),p.arc(I,Q,He,0,Math.PI*2),p.strokeStyle="rgba(0,0,0,0.3)",p.lineWidth=3,p.stroke(),p.beginPath(),p.arc(I,Q,He,0,Math.PI*2),p.strokeStyle="rgba(255,255,255,0.65)",p.lineWidth=1.5,p.stroke())}const y=me.current;if(y){const A=ye.current,I=Se.current;if(p.save(),A==="down")p.beginPath(),p.arc(y.x,y.y,ct,0,Math.PI*2),p.fillStyle="rgba(255,255,255,0.92)",p.fill(),p.strokeStyle="rgba(0,0,0,0.2)",p.lineWidth=1,p.stroke();else if(A==="release"&&I){const Q=Math.min((performance.now()-I.startTime)/350,1);p.beginPath(),p.arc(y.x,y.y,ct+26*Q,0,Math.PI*2),p.strokeStyle=`rgba(255,255,255,${(1-Q)*.55})`,p.lineWidth=1.5,p.stroke(),Q>=1&&(ye.current="idle",Se.current=null)}else p.beginPath(),p.arc(y.x,y.y,He,0,Math.PI*2),p.strokeStyle="rgba(0,0,0,0.3)",p.lineWidth=3,p.stroke(),p.beginPath(),p.arc(y.x,y.y,He,0,Math.PI*2),p.strokeStyle="rgba(255,255,255,0.65)",p.lineWidth=1.5,p.stroke();p.restore()}},[J]),z=s.useCallback(()=>{const c=O.current;if(!c)return;const b=document.createElement("canvas"),p=b.getContext("2d");p&&(b.width=c.width,b.height=c.height,p.drawImage(c,0,0),b.toBlob(D=>{if(!D)return;const E=URL.createObjectURL(D),y=document.createElement("a");y.href=E,y.download=`tapflow-${Date.now()}.png`,y.click(),URL.revokeObjectURL(E)},"image/png"))},[]),re=s.useCallback(()=>{if(xe==="idle"){const c=J.current;if(!c)return;const b=G.current;if(b&&b.clientWidth>0)c.width=b.clientWidth,c.height=b.clientHeight;else{const p=O.current;if(p&&p.width>0)c.width=p.width,c.height=p.height;else return}Te(S)}else xe==="recording"&&Ue()},[xe,Te,Ue,S,J]),ae=s.useCallback(()=>{r({type:"input:rotate",sessionId:t}),we(c=>!c)},[r,t]),H=s.useRef(B);s.useEffect(()=>{H.current=B},[B]),s.useEffect(()=>()=>{H.current&&r({type:"input:rotate",sessionId:t})},[]);const Ee=s.useCallback((c,b)=>{r({type:"input:key",sessionId:t,requestId:X(),payload:{code:c,modifiers:b}})},[r,t]);qn({sessionId:t,send:r,active:ce,supported:N,handlerRef:w,sendChord:Ee,onError:c=>Ce.error(c)});const tt=On({sessionId:t,send:r,supported:j,deviceReady:f,handlerRef:k,onError:c=>Ce.error(c)});s.useEffect(()=>{const c=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),b=y=>{if(y.code==="AltLeft"||y.code==="AltRight"){he.current=!0;return}if(y.metaKey){const I=document.activeElement;if(!I||I.tagName!=="INPUT"&&I.tagName!=="TEXTAREA"){if(!y.shiftKey&&y.code==="KeyK"){y.preventDefault(),De(!0);return}if(!y.shiftKey&&y.code==="KeyS"){y.preventDefault(),z();return}if(y.shiftKey&&y.code==="KeyY"){y.preventDefault(),re();return}if(y.shiftKey&&y.code==="KeyO"){y.preventDefault(),ae();return}if(y.shiftKey&&y.code==="KeyU"){y.preventDefault(),r({type:"input:button",sessionId:t,requestId:X(),payload:{name:"home"}});return}if(y.shiftKey&&y.code==="KeyK"){y.preventDefault(),L||M();return}}}if(!ce||c.has(y.code)||N&&Zt(y))return;y.preventDefault();const A=(y.shiftKey?2:0)|(y.ctrlKey?1:0)|(y.metaKey?8:0);r({type:"input:key",sessionId:t,requestId:X(),payload:{code:y.code,modifiers:A}})},p=()=>{fe.current&&(fe.current=!1,se(!1),r({type:"input:pinch:end",sessionId:t,requestId:X()})),he.current=!1,le(null)},D=y=>{(y.code==="AltLeft"||y.code==="AltRight")&&p()},E=()=>{he.current&&p()};return window.addEventListener("keydown",b),window.addEventListener("keyup",D),window.addEventListener("blur",E),()=>{window.removeEventListener("keydown",b),window.removeEventListener("keyup",D),window.removeEventListener("blur",E)}},[ce,N,r,t,z,re,ae,M,L]),s.useEffect(()=>{if(!ce)return;const c=b=>{const p=G.current??O.current;p&&!p.contains(b.target)&&be(!1)};return document.addEventListener("pointerdown",c),()=>document.removeEventListener("pointerdown",c)},[ce]);const ze=s.useCallback(c=>{const b=(B?ue.current:null)??G.current;if(!b)return null;const p=b.getBoundingClientRect(),D=u.compositeWidth/2,E=u.compositeHeight/2,y=u.screenRect.x/2,A=u.screenRect.y/2,I=u.screenRect.width/2,Q=u.screenRect.height/2;return xo({x:c.clientX,y:c.clientY},p,D,E,{x:y,y:A,width:I,height:Q},B)},[u,B]),nt=s.useCallback(c=>{const b=ze(c);return b?zn(b):null},[ze]),pt=s.useCallback(c=>{const b=B?ue.current:G.current;if(!b)return null;const p=b.getBoundingClientRect();let D,E;if(B){const A=p.height-(c.clientY-p.top),I=c.clientX-p.left;D=A*(u.compositeWidth/p.height),E=I*(u.compositeHeight/p.width)}else D=(c.clientX-p.left)*(u.compositeWidth/p.width),E=(c.clientY-p.top)*(u.compositeHeight/p.height);const y=u.screenRect;if(D>=y.x&&D<=y.x+y.width&&E>=y.y&&E<=y.y+y.height)return null;for(const A of u.buttons){const I=D-A.normalOffset.x,Q=E-A.normalOffset.y;if(I*I+Q*Q<Mo**2)return A.name}return null},[u,B]),rt=s.useCallback(c=>{const b=O.current,p=J.current;return b&&b.clientWidth>0?{x:b.offsetLeft+c.x*b.clientWidth,y:b.offsetTop+c.y*b.clientHeight}:{x:c.x*((p==null?void 0:p.width)??1),y:c.y*((p==null?void 0:p.height)??1)}},[J]),Ne=s.useCallback(c=>{if(be(!0),he.current){const y=nt(c);if(!y)return;fe.current=!0,se(!0),c.target.setPointerCapture(c.pointerId),le(y),r({type:"input:pinch:start",sessionId:t,payload:y});return}const b=pt(c);if(b){de.current=b,Y(b),c.target.setPointerCapture(c.pointerId),r({type:"input:button",sessionId:t,requestId:X(),payload:{name:b,phase:"down"}});return}const p=ze(c);if(!p)return;pe.current=p,c.target.setPointerCapture(c.pointerId),me.current=rt(p),ye.current="down",Se.current=null;const D=c.currentTarget.getBoundingClientRect(),E=oe.current;E&&(E.style.display="block",E.style.left=`${c.clientX-D.left}px`,E.style.top=`${c.clientY-D.top}px`,E.style.width=`${ct*2}px`,E.style.height=`${ct*2}px`,E.style.background="rgba(255,255,255,0.92)",E.style.border="1.5px solid rgba(0,0,0,0.2)",E.style.boxShadow="0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"),r({type:"input:touch:start",sessionId:t,payload:p})},[pt,ze,nt,rt,r,t]),Nt=s.useCallback(c=>{if(c.buttons===0){if(ht(pt(c)),he.current){le(nt(c)),me.current=null;const A=oe.current;A&&(A.style.display="none")}else{le(null);const A=ze(c);me.current=A?rt(A):null,ye.current!=="down"&&(ye.current="idle");const I=oe.current;if(I)if(A){const Q=c.currentTarget.getBoundingClientRect();I.style.display="block",I.style.left=`${c.clientX-Q.left}px`,I.style.top=`${c.clientY-Q.top}px`,I.style.width=`${He*2}px`,I.style.height=`${He*2}px`,I.style.background="transparent",I.style.border="1.5px solid rgba(255,255,255,0.6)",I.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"}else I.style.display="none"}return}if(fe.current){const A=nt(c);if(!A)return;const I=performance.now();if(I-ve.current<vn)return;ve.current=I,le(A),r({type:"input:pinch:move",sessionId:t,payload:A});return}if(de.current||!pe.current)return;const b=ze(c);if(!b)return;const p=b.x-pe.current.x,D=b.y-pe.current.y;if(Math.sqrt(p*p+D*D)<Io)return;const E=performance.now();if(E-ve.current<vn)return;ve.current=E,me.current=rt(b);const y=oe.current;if(y&&y.style.display!=="none"){const A=c.currentTarget.getBoundingClientRect();y.style.left=`${c.clientX-A.left}px`,y.style.top=`${c.clientY-A.top}px`}r({type:"input:touch:move",sessionId:t,payload:b})},[pt,ze,nt,rt,r,t]),Ye=s.useCallback(()=>{if(fe.current){fe.current=!1,se(!1),le(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}if(pe.current=null,de.current){r({type:"input:button",sessionId:t,requestId:X(),payload:{name:de.current,phase:"up"}}),de.current=null,setTimeout(()=>Y(null),100);return}ye.current="release",Se.current={startTime:performance.now()};const c=oe.current;c&&(c.style.width=`${He*2}px`,c.style.height=`${He*2}px`,c.style.background="transparent",c.style.border="1.5px solid rgba(255,255,255,0.6)",c.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),st=s.useCallback(()=>{if(fe.current){fe.current=!1,se(!1),le(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}if(pe.current=null,de.current){r({type:"input:button",sessionId:t,requestId:X(),payload:{name:de.current,phase:"up"}}),de.current=null,Y(null);return}ye.current="release",Se.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),$t=s.useCallback(()=>{ht(null),le(null),me.current=null;const c=oe.current;c&&(c.style.display="none")},[]),Ge=u.compositeWidth/2,At=u.compositeHeight/2,mt=vo(At,750),ot=Math.round(Ge*mt),at=Math.round(At*mt),gt=u.screenRect.x/u.compositeWidth*100,xt=u.screenRect.y/u.compositeHeight*100,it=u.screenRect.width/u.compositeWidth*100,bt=u.screenRect.height/u.compositeHeight*100,vt=Math.round(u.screenCornerRadius/2*mt),Ot=n.jsx(n.Fragment,{children:n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Home",onClick:()=>r({type:"input:button",sessionId:t,requestId:X(),payload:{name:"home"}}),children:n.jsx(Ln,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:n.jsxs("span",{className:"flex items-center gap-3",children:["Home ",n.jsxs(qt,{children:[n.jsx(ut,{children:"⌘"}),n.jsx(ut,{children:"⇧"}),n.jsx(ut,{children:"U"})]})]})})]})}),R=s.useId(),P=n.jsxs(n.Fragment,{children:[n.jsx("span",{id:R,role:"status",className:"sr-only",children:L?"Changing the software keyboard.":T?"The software keyboard is up.":"The software keyboard is down."}),n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":L?"Software keyboard — changing it":"Software keyboard","aria-pressed":T,"aria-busy":L,"aria-disabled":L,"aria-describedby":R,onClick:()=>{L||M()},"data-active":T,children:L?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(is,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:L?n.jsx("span",{children:"Software keyboard — changing it"}):n.jsxs("span",{className:"flex items-center gap-3",children:["Software keyboard ",n.jsxs(qt,{children:[n.jsx(ut,{children:"⌘"}),n.jsx(ut,{children:"⇧"}),n.jsx(ut,{children:"K"})]})]})})]})]}),W=h&&e?n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:x,"aria-label":"Launch app",onClick:i,children:x?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(En,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:x?"Launching…":"Launch app"})]}):null;return n.jsxs("div",{ref:K,tabIndex:-1,role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16 outline-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded-md",children:[n.jsx("canvas",{ref:J,style:{display:"none"}}),n.jsx(Hn,{open:Pe,onOpenChange:De,openUrl:o}),n.jsx($n,{joined:l,onDeepLink:()=>De(!0),onScreenshot:z,onRecordToggle:re,recordState:xe,onRotate:ae,navigationSlot:Ot,deviceSlot:P,launchSlot:W,network:j?{position:tt.position,steerable:tt.steerable,reason:tt.reason,pending:tt.pending,onToggle:tt.toggle}:void 0,reboot:{pending:C,onReboot:$}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsxs("div",{ref:ue,style:{width:B?at:ot,height:B?ot:at,position:"relative",flexShrink:0},children:[n.jsxs("div",{ref:G,className:`relative ${Oe?"cursor-pointer":"cursor-default"}`,style:{width:ot,height:at,...B?{position:"absolute",top:(ot-at)/2,left:(at-ot)/2,transform:"rotate(-90deg)",transformOrigin:"center center"}:{}},onPointerDown:Ne,onPointerMove:Nt,onPointerUp:Ye,onPointerCancel:st,onPointerLeave:$t,children:[n.jsx("img",{src:`data:image/png;base64,${u.framePng}`,style:{position:"absolute",top:0,left:0,zIndex:2,width:"100%",height:"100%",display:"block",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),n.jsx("canvas",{ref:O,style:{position:"absolute",zIndex:3,left:`${gt}%`,top:`${xt}%`,width:`${it}%`,height:`${bt}%`,borderRadius:vt>0?`${vt}px`:void 0,backgroundColor:"#010101",cursor:"none",visibility:U?"visible":"hidden"}}),!U&&n.jsx("div",{className:"absolute animate-pulse bg-zinc-700",style:{zIndex:3,left:`${gt}%`,top:`${xt}%`,width:`${it}%`,height:`${bt}%`,borderRadius:vt>0?`${vt}px`:void 0}}),ne&&(()=>{const c=gt/100,b=xt/100,p=it/100,D=bt/100,E=(y,A)=>({left:`${(c+y*p)*100}%`,top:`${(b+A*D)*100}%`});return n.jsx(n.Fragment,{children:[ne.f0,ne.f1].map((y,A)=>n.jsx("div",{style:{position:"absolute",zIndex:10,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease",...Ke?{width:ct*2,height:ct*2,background:"rgba(255,255,255,0.92)",border:"1.5px solid rgba(0,0,0,0.2)",boxShadow:"0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"}:{width:He*2,height:He*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"},...E(y.x,y.y)}},A))})})(),l&&_e===0&&n.jsx("div",{style:{position:"absolute",zIndex:8,left:`${gt}%`,top:`${xt}%`,width:`${it}%`,height:`${bt}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n.jsx("span",{style:{color:"white",fontSize:"0.875rem"},children:"Waiting for first frame..."})}),u.buttons.map(c=>{const b=Le===c.name,p=Oe===c.name,D=c.anchor==="bottom",E=c.anchor==="top",y=D?(c.normalOffset.y-c.buttonH/2)/u.compositeHeight*100:E?c.rolloverOffset.y/u.compositeHeight*100:(c.normalOffset.y-c.buttonH/2)/u.compositeHeight*100,A=c.buttonH/u.compositeHeight*100,I=c.buttonW/u.compositeWidth*100,Q=c.buttonW/2,Je=(c.rolloverOffset.x-Q)/u.compositeWidth*100,wt=(2*c.rolloverOffset.x-c.normalOffset.x-Q)/u.compositeWidth*100,We=c.rolloverOffset.x/u.compositeWidth*100,Be=D?(c.normalOffset.y-c.buttonH/2)/u.compositeHeight*100:E?c.rolloverOffset.y/u.compositeHeight*100:(c.normalOffset.y-c.buttonH/2)/u.compositeHeight*100,Ve=E?(2*c.rolloverOffset.y-c.normalOffset.y)/u.compositeHeight*100:0,_t=c.onTop?4:1;return n.jsxs(s.Fragment,{children:[c.buttonPng&&n.jsx("img",{src:`data:image/png;base64,${c.buttonPng}`,style:{position:"absolute",zIndex:_t,top:`${E&&p?Ve:y}%`,left:`${E?Je:p?wt:Je}%`,width:`${I}%`,height:`${A}%`,transition:E?"top 0.15s ease":"left 0.15s ease",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),b&&c.pressedPng&&c.pressedRect&&n.jsx("img",{src:`data:image/png;base64,${c.pressedPng}`,style:{position:"absolute",zIndex:c.onTop?3:1,left:`${E?Je:p?wt:Je}%`,top:`${E&&p?Ve:y}%`,width:`${c.pressedRect.width/u.compositeWidth*100}%`,height:`${c.pressedRect.height/u.compositeHeight*100}%`,pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),p&&n.jsx("div",{className:"bg-foreground/85 text-background text-[11px] px-[7px] py-1.5 rounded-lg whitespace-nowrap pointer-events-none",style:{position:"absolute",zIndex:5,left:`${We}%`,top:`${Be}%`,transform:"translate(-50%, calc(-100% - 8px))"},children:c.accessibilityTitle})]},c.name)})]}),n.jsx("div",{ref:oe,style:{display:"none",position:"absolute",zIndex:20,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease, box-shadow 0.1s ease"}})]}),n.jsx(Qt,{joined:l,fps:_e,connected:a,deviceReady:f,bootError:g,installing:d,installError:m,keyboardActive:ce})]})]})}const lt=13,kt=8,yn=16,$o=.02,zt=720;function Oo({sessionId:t,buildId:e,send:r,openUrl:o,launchApp:i,connected:a,joined:l,deviceReady:f,installing:d,installed:h,installError:m,bootError:g,launching:x,androidButtons:u,binaryFrameHandlerRef:v,clipboardHandlerRef:w,clipboardSupported:N,networkHandlerRef:k,networkSupported:j,onRecordingUploaded:_,rebootPending:T,onReboot:L,viewerRootRef:M,screenWidth:C,screenHeight:$,cornerRadius:K,perfHookRef:V}){const O=s.useRef(null),G=s.useRef(null),ue=s.useRef(null),{fps:_e,frameCount:Me}=Un(),{recordState:ge,recordCanvasRef:xe,startClientRecording:J,stopClientRecording:Te}=Mn({sessionId:t,buildId:e,onRecordingUploaded:_}),[Ue,$e]=s.useState(!1),[Pe,De]=s.useState(!1),[U,q]=s.useState(!1),B=s.useRef(null),[we,ce]=s.useState(null),[be,Le]=s.useState(!1),[Y,Oe]=s.useState(!1),[ht,Ke]=s.useState(!1),[se,ne]=s.useState(null),le=s.useRef(se);s.useEffect(()=>{le.current=se},[se]);const Z=s.useRef(!1),de=s.useRef(!1),pe=s.useRef(null),fe=s.useRef(0),he=s.useRef(null),ve=s.useRef(null),oe=s.useRef("idle"),me=s.useRef(null);Vn({binaryFrameHandlerRef:v,perfHookRef:V,frameCount:Me,onUnsupported:()=>q(!0),onResize:R=>{De(!0);const P=B.current;(!P||P.width!==R.width||P.height!==R.height)&&(B.current=R,ce(R))},onDecoderReady:R=>{var W;ue.current=R;const P=R.surface;P.style.display="block",P.style.width="100%",P.style.height="100%",P.style.objectFit="fill",(W=O.current)==null||W.appendChild(P)}});const ye=s.useCallback(()=>{var wt;const R=xe.current,P=(wt=ue.current)==null?void 0:wt.surface,W=B.current;if(!R||!P||!W)return;const c=R.getContext("2d");if(!c)return;const b=W.width,p=W.height,D=R.width>R.height!=b>p;c.save(),D&&(c.translate(R.width,0),c.rotate(Math.PI/2)),c.drawImage(P,0,0,b,p);const E=Math.max(b,p),y=E>zt?E/zt:1,A=lt*y,I=kt*y,Q=le.current;if(Q)for(const We of[Q.f0,Q.f1]){const Be=We.x*b,Ve=We.y*p;Z.current?(c.beginPath(),c.arc(Be,Ve,I,0,Math.PI*2),c.fillStyle="rgba(255,255,255,0.92)",c.fill(),c.strokeStyle="rgba(0,0,0,0.2)",c.lineWidth=y,c.stroke()):(c.beginPath(),c.arc(Be,Ve,A,0,Math.PI*2),c.strokeStyle="rgba(0,0,0,0.3)",c.lineWidth=3*y,c.stroke(),c.beginPath(),c.arc(Be,Ve,A,0,Math.PI*2),c.strokeStyle="rgba(255,255,255,0.65)",c.lineWidth=1.5*y,c.stroke())}const Je=ve.current;if(Je){const We=Je.x*b,Be=Je.y*p,Ve=oe.current,_t=me.current;if(Ve==="down")c.beginPath(),c.arc(We,Be,I,0,Math.PI*2),c.fillStyle="rgba(255,255,255,0.92)",c.fill(),c.strokeStyle="rgba(0,0,0,0.2)",c.lineWidth=y,c.stroke();else if(Ve==="release"&&_t){const Ft=Math.min((performance.now()-_t.startTime)/350,1);c.beginPath(),c.arc(We,Be,I+26*y*Ft,0,Math.PI*2),c.strokeStyle=`rgba(255,255,255,${(1-Ft)*.55})`,c.lineWidth=1.5*y,c.stroke(),Ft>=1&&(oe.current="idle",me.current=null)}else c.beginPath(),c.arc(We,Be,A,0,Math.PI*2),c.strokeStyle="rgba(0,0,0,0.3)",c.lineWidth=3*y,c.stroke(),c.beginPath(),c.arc(We,Be,A,0,Math.PI*2),c.strokeStyle="rgba(255,255,255,0.65)",c.lineWidth=1.5*y,c.stroke()}c.restore()},[xe]),Se=s.useCallback(()=>{var b;const R=(b=ue.current)==null?void 0:b.surface,P=B.current;if(!R||!P)return;const W=document.createElement("canvas"),c=W.getContext("2d");c&&(W.width=P.width,W.height=P.height,c.drawImage(R,0,0,P.width,P.height),W.toBlob(p=>{if(!p)return;const D=URL.createObjectURL(p),E=document.createElement("a");E.href=D,E.download=`tapflow-${Date.now()}.png`,E.click(),URL.revokeObjectURL(D)},"image/png"))},[]),Fe=s.useCallback(()=>{if(ge==="idle"){const R=xe.current;if(!R)return;const P=B.current;if(!P)return;const W=ae.current;R.width=W?P.height:P.width,R.height=W?P.width:P.height,J(ye)}else ge==="recording"&&Te()},[ge,J,Te,ye,xe]),Ie=s.useCallback(()=>{r({type:"input:rotate",sessionId:t}),Le(R=>!R)},[r,t]),S=s.useRef(be);s.useEffect(()=>{S.current=be},[be]),s.useEffect(()=>()=>{S.current&&r({type:"input:rotate",sessionId:t})},[]);const z=s.useCallback((R,P)=>{r({type:"input:key",sessionId:t,requestId:X(),payload:{code:R,modifiers:P}})},[r,t]);qn({sessionId:t,send:r,active:Y,supported:N,handlerRef:w,sendChord:z,onError:R=>Ce.error(R)});const re=On({sessionId:t,send:r,supported:j,deviceReady:f,handlerRef:k,onError:R=>Ce.error(R)});s.useEffect(()=>{const R=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),P=p=>{if(p.code==="AltLeft"||p.code==="AltRight"){de.current=!0;return}if(p.metaKey){const E=document.activeElement;if(!E||E.tagName!=="INPUT"&&E.tagName!=="TEXTAREA"){if(!p.shiftKey&&p.code==="KeyK"){p.preventDefault(),$e(!0);return}if(!p.shiftKey&&p.code==="KeyS"){p.preventDefault(),Se();return}if(p.shiftKey&&p.code==="KeyY"){p.preventDefault(),Fe();return}if(p.shiftKey&&p.code==="KeyO"){p.preventDefault(),Ie();return}}}if(!Y||R.has(p.code)||N&&Zt(p))return;p.preventDefault();const D=(p.shiftKey?2:0)|(p.ctrlKey?1:0)|(p.metaKey?8:0);r({type:"input:key",sessionId:t,requestId:X(),payload:{code:p.code,modifiers:D}})},W=()=>{Z.current&&(Z.current=!1,Ke(!1),r({type:"input:pinch:end",sessionId:t,requestId:X()})),de.current=!1,ne(null)},c=p=>{(p.code==="AltLeft"||p.code==="AltRight")&&W()},b=()=>{de.current&&W()};return window.addEventListener("keydown",P),window.addEventListener("keyup",c),window.addEventListener("blur",b),()=>{window.removeEventListener("keydown",P),window.removeEventListener("keyup",c),window.removeEventListener("blur",b)}},[Y,N,r,t,Se,Fe,Ie]),s.useEffect(()=>{if(!Y)return;const R=P=>{const W=G.current??O.current;W&&!W.contains(P.target)&&Oe(!1)};return document.addEventListener("pointerdown",R),()=>document.removeEventListener("pointerdown",R)},[Y]);const ae=s.useRef(!1),H=s.useCallback(R=>{const P=O.current;if(!P)return null;const W=P.getBoundingClientRect();return bo({x:R.clientX,y:R.clientY},W,ae.current)},[]),Ee=s.useCallback(R=>{const P=H(R);return P?zn(P):null},[H]),tt=s.useCallback(R=>{if(de.current){const b=Ee(R);if(!b)return;Z.current=!0,Ke(!0),R.target.setPointerCapture(R.pointerId);const p=he.current;p&&(p.style.display="none"),ne(b),r({type:"input:pinch:start",sessionId:t,payload:b});return}const P=H(R);if(!P)return;Oe(!0),pe.current=P,R.target.setPointerCapture(R.pointerId);const W=R.currentTarget.getBoundingClientRect();ve.current=P,oe.current="down",me.current=null;const c=he.current;c&&(c.style.display="block",c.style.left=`${R.clientX-W.left}px`,c.style.top=`${R.clientY-W.top}px`,c.style.width=`${kt*2}px`,c.style.height=`${kt*2}px`,c.style.background="rgba(255,255,255,0.92)",c.style.border="1.5px solid rgba(0,0,0,0.2)",c.style.boxShadow="0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"),r({type:"input:touch:start",sessionId:t,payload:P})},[H,Ee,r,t]),ze=s.useCallback(R=>{if(R.buttons===0){if(de.current){ne(Ee(R)),ve.current=null;const I=he.current;I&&(I.style.display="none");return}const E=H(R),y=R.currentTarget.getBoundingClientRect(),A=he.current;E?(ve.current=E,oe.current!=="down"&&(oe.current="idle"),A&&(A.style.display="block",A.style.left=`${R.clientX-y.left}px`,A.style.top=`${R.clientY-y.top}px`,A.style.width=`${lt*2}px`,A.style.height=`${lt*2}px`,A.style.background="transparent",A.style.border="1.5px solid rgba(255,255,255,0.6)",A.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)")):(ve.current=null,A&&(A.style.display="none"));return}if(Z.current){const E=Ee(R);if(!E)return;const y=performance.now();if(y-fe.current<yn)return;fe.current=y,ne(E),r({type:"input:pinch:move",sessionId:t,payload:E});return}if(!pe.current)return;const P=H(R);if(!P)return;const W=P.x-pe.current.x,c=P.y-pe.current.y;if(Math.sqrt(W*W+c*c)<$o)return;const b=performance.now();if(b-fe.current<yn)return;fe.current=b;const p=R.currentTarget.getBoundingClientRect();ve.current=P;const D=he.current;D&&D.style.display!=="none"&&(D.style.left=`${R.clientX-p.left}px`,D.style.top=`${R.clientY-p.top}px`),r({type:"input:touch:move",sessionId:t,payload:P})},[H,Ee,r,t]),nt=s.useCallback(()=>{if(Z.current){Z.current=!1,Ke(!1),ne(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}pe.current=null,oe.current="release",me.current={startTime:performance.now()};const R=he.current;R&&(R.style.width=`${lt*2}px`,R.style.height=`${lt*2}px`,R.style.background="transparent",R.style.border="1.5px solid rgba(255,255,255,0.6)",R.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),pt=s.useCallback(()=>{if(Z.current){Z.current=!1,Ke(!1),ne(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}pe.current=null,oe.current="release",me.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),rt=s.useCallback(()=>{ne(null),ve.current=null;const R=he.current;R&&(R.style.display="none")},[]),Ne=we??(C&&$?{width:C,height:$}:null),Nt=Ne?Math.min(1,zt/Math.max(Ne.width,Ne.height)):.3,Ye=Ne?Math.round(Ne.width*Nt):324,st=Ne?Math.round(Ne.height*Nt):720,$t=Ne?Ne.width>Ne.height:!1,Ge=be&&!$t;s.useLayoutEffect(()=>{ae.current=Ge},[Ge]);const At=Ge?st:Ye,cn=Ge?Ye:st,mt=K!=null?Math.round(K*Ye):22,ot=Ge?{position:"absolute",width:Ye,height:st,top:(Ye-st)/2,left:(st-Ye)/2,transform:"rotate(90deg)",transformOrigin:"center center",visibility:Pe?"visible":"hidden",cursor:"none"}:{visibility:Pe?"visible":"hidden",cursor:"none"},at=["home","back","recent_apps"],gt=["volume_up","volume_down","power"],xt=R=>R==="back"?n.jsx(Kr,{className:"h-4 w-4"}):R==="recent_apps"?n.jsx(hr,{className:"h-4 w-4"}):R==="volume_up"?n.jsx(As,{className:"h-4 w-4"}):R==="volume_down"?n.jsx(Es,{className:"h-4 w-4"}):R==="power"?n.jsx(hs,{className:"h-4 w-4"}):n.jsx(Ln,{className:"h-4 w-4"}),it=R=>n.jsx(n.Fragment,{children:R.map(P=>u==null?void 0:u.find(W=>W.name===P)).filter(P=>P!==void 0).map(P=>n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":P.accessibilityTitle,onClick:()=>r({type:"input:button",sessionId:t,requestId:X(),payload:{name:P.name}}),children:xt(P.name)})}),n.jsx(je,{side:"left",children:P.accessibilityTitle})]},P.name))}),bt=it(at),vt=it(gt),Ot=h&&e?n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:x||d,"aria-label":"Launch app",onClick:i,children:x?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(En,{className:"h-4 w-4"})})}),n.jsx(je,{side:"left",children:x?"Launching…":d?"Installing…":"Launch app"})]}):null;return n.jsxs("div",{ref:M,tabIndex:-1,role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16 outline-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded-md",children:[n.jsx("canvas",{ref:xe,style:{display:"none"}}),n.jsx(Hn,{open:Ue,onOpenChange:$e,openUrl:o}),n.jsx($n,{joined:l,onDeepLink:()=>$e(!0),onScreenshot:Se,onRecordToggle:Fe,recordState:ge,onRotate:Ie,navigationSlot:bt,deviceSlot:vt,launchSlot:Ot,network:j?{position:re.position,steerable:re.steerable,reason:re.reason,pending:re.pending,onToggle:re.toggle}:void 0,reboot:{pending:T,onReboot:L}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{style:{background:"#1c1c1e",borderRadius:`${mt+12}px`,padding:"12px",flexShrink:0,boxShadow:"0 8px 32px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06)"},children:n.jsx("div",{ref:G,className:"relative",style:{width:At,height:cn,backgroundColor:"#010101",borderRadius:`${mt}px`,overflow:"hidden"},children:U?n.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-4 text-center",children:n.jsxs("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"0.875rem"},children:["이 환경에서는 스트리밍을 표시할 수 없습니다.",n.jsx("br",{}),"Chrome/Edge 또는 HTTPS 환경에서 다시 시도해 주세요."]})}):n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:O,className:Ge?void 0:"block w-full h-full",style:ot,onPointerDown:tt,onPointerMove:ze,onPointerUp:nt,onPointerCancel:pt,onPointerLeave:rt}),!Pe&&n.jsx("div",{className:"absolute inset-0 animate-pulse bg-zinc-700"}),!Pe&&f&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:n.jsx("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"0.875rem"},children:"Waiting for stream…"})}),n.jsx("div",{ref:he,style:{display:"none",position:"absolute",zIndex:20,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease, box-shadow 0.1s ease"}}),se&&n.jsx(n.Fragment,{children:[se.f0,se.f1].map((R,P)=>n.jsx("div",{style:{position:"absolute",zIndex:10,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease",left:`${R.x*100}%`,top:`${R.y*100}%`,...ht?{width:kt*2,height:kt*2,background:"rgba(255,255,255,0.92)",border:"1.5px solid rgba(0,0,0,0.2)",boxShadow:"0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"}:{width:lt*2,height:lt*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"}}},P))})]})})}),n.jsx(Qt,{joined:l,fps:_e,connected:a,deviceReady:f,bootError:g,installing:d,installError:m,keyboardActive:Y})]})]})}function Fo(t,e){const r=new DataView(t),o=Math.floor(t.byteLength/2),i=Math.floor(o/e),a=[];for(let l=0;l<e;l++)a.push(new Float32Array(i));for(let l=0;l<i;l++)for(let f=0;f<e;f++){const d=r.getInt16((l*e+f)*2,!0);a[f][l]=d/32768}return a}const Bo=44100,Wt=2,wn=.06,Ho=.3;function zo(){const t=s.useRef(null),e=s.useRef(0),r=s.useCallback(()=>{if(t.current)return t.current;const i=window.AudioContext??window.webkitAudioContext;return i?(t.current=new i,t.current):null},[]),o=s.useCallback(i=>{var x;const a=r();if(!a)return;a.state==="suspended"&&a.resume();const l=Fo(i,Wt),f=((x=l[0])==null?void 0:x.length)??0;if(f===0)return;const d=a.createBuffer(Wt,f,Bo);for(let u=0;u<Wt;u++)d.getChannelData(u).set(l[u]);const h=a.createBufferSource();h.buffer=d,h.connect(a.destination);const m=a.currentTime;let g=e.current;(g<m+.005||g>m+Ho+wn)&&(g=m+wn),h.start(g),e.current=g+d.duration},[r]);return s.useEffect(()=>()=>{var i;(i=t.current)==null||i.close(),t.current=null},[]),{pushFrame:o}}const Wo=2e4;function Vo({sessionId:t,deviceId:e,deviceReady:r,send:o,handlerRef:i,onShutdownComplete:a,onError:l}){const[f,d]=s.useState(!1),h=s.useRef(null),m=s.useRef(a),g=s.useRef(l);s.useEffect(()=>{m.current=a},[a]),s.useEffect(()=>{g.current=l},[l]),s.useEffect(()=>{d(!1),h.current=null},[t]),s.useEffect(()=>{r||(d(!1),h.current=null)},[r]),s.useEffect(()=>(i.current=w=>{if(w.requestId===h.current){if(h.current=null,d(!1),w.type==="device:shutdown-error"){g.current(`The device was not restarted. ${w.message}`);return}m.current()}},()=>{i.current=void 0}),[i]);const[x,u]=s.useState(null);s.useEffect(()=>{u(f?h.current:null)},[f]),s.useEffect(()=>{if(x===null)return;const w=setTimeout(()=>{h.current===x&&(d(!1),g.current("The device has not answered the restart yet. If its answer arrives tapflow will finish restarting it; if nothing changes, press Restart again."))},Wo);return()=>clearTimeout(w)},[x]);const v=s.useCallback(()=>{if(f)return;const w=X();h.current=w,d(!0),o({type:"device:shutdown",sessionId:t,requestId:w,payload:{deviceId:e}})},[f,o,t,e]);return{pending:f,reboot:v}}const Sn={"channel-unavailable":{title:"Input is not reaching this device",action:"Rejoin the session to continue."},"not-booted":{title:"The device is not running",action:"Start it again to continue testing."},"dispatch-failed":{title:"The device rejected that input",action:"Try once more. If it keeps failing, restart the device."},unsupported:{title:"That input is not supported on this device",action:"Everything else still works — this one has no equivalent here."},malformed:{title:"tapflow sent a malformed input",action:"This is a bug in tapflow — please report it with what you were doing."},"channel-starting":null,"no-gesture":null,"not-session-owner":{title:"This session is no longer yours",action:"Go back and open the device again — another tester may have taken it. Nothing you just did reached the device."}};function qo(t){const e=t!==void 0&&Object.hasOwn(Sn,t)?t:"channel-unavailable";return{key:e,notice:Sn[e]}}function Xo({sessionId:t,deviceId:e,buildId:r,resetMode:o,onRecordingUploaded:i,onSessionEnded:a}){const l=s.useRef(()=>{}),f=s.useRef(!1),d=s.useRef({pending:0,appInstalled:!1});Ls();const h=s.useRef(null),m=s.useRef(null),g=s.useRef([]);s.useRef({onFrameBegin:()=>{var S;return(S=h.current)==null?void 0:S.onFrameBegin()},onFrameEnd:S=>{var ae,H;const z=g.current.shift()??null,re=z?{...S,capturedAt:z.capturedAt,relayedAt:z.relayedAt}:S;(ae=h.current)==null||ae.onFrameEnd(re),(H=m.current)==null||H.call(m,re)}});const[x,u]=s.useState(!1),[v,w]=s.useState(!1),[N,k]=s.useState(!1),[j,_]=s.useState(null),[T,L]=s.useState(!1),[M,C]=s.useState(!1),[$,K]=s.useState(null),[V,O]=s.useState(null),[G,ue]=s.useState(!1),[_e,Me]=s.useState([]),ge=s.useRef(new Set),xe=s.useRef(null),J=s.useRef(new Set),Te=s.useRef(new Set),Ue=s.useRef(new Set),[$e,Pe]=s.useState(!1),De=8e3,[U,q]=s.useState(!1),B=s.useRef(null);s.useEffect(()=>()=>{B.current&&clearTimeout(B.current)},[]);const we=s.useRef(void 0),ce=s.useRef(void 0),be=s.useRef(void 0),Le=s.useRef(void 0),Y=s.useCallback(S=>{const z=X();ge.current.add(z),xe.current=z,l.current({type:"device:boot",sessionId:t,requestId:z,payload:{deviceId:e,resetMode:S,acceptH264:lo(),secureContext:window.isSecureContext}})},[t,e]),{pushFrame:Oe}=zo(),ht=s.useCallback(S=>{var z,re,ae;if(!("sessionId"in S&&S.sessionId!==t)){if(S.type==="session:joined"){d.current={pending:0,appInstalled:!1},u(!0),w(!1),Me(S.capabilities??[]);const H=f.current?"app-only":o;f.current=!0,ge.current.clear(),Y(H)}if(S.type==="session:agent-away"){w(!0),_(null),k(!1);return}if(S.type==="session:terminated"){a==null||a(S.reason);return}if(S.type==="session:rebound"){k(!1),_(null),L(!1),K(null),O(null),ue(!1),q(!1),B.current&&clearTimeout(B.current),Pe(!1),g.current=[],Me(S.capabilities);const H=v;w(!1),d.current={pending:d.current.pending+1,appInstalled:d.current.pending>0?d.current.appInstalled:M},f.current=!0,Y("app-only"),H||Ce.info("The agent restarted — reconnecting to the device.");return}if(S.type==="device:boot-error"){if(S.requestId!==void 0&&S.requestId!==xe.current||v)return;d.current={pending:0,appInstalled:!1},O(S.message)}if(S.type==="input:error"){if(v)return;const{key:H,notice:Ee}=qo(S.reason);S.reason!==void 0&&S.reason!==H&&console.debug(`[tapflow] unrecognised input:error reason "${S.reason}", treated as ${H}`),Ee?Ce.error(Ee.title,{id:`input:${t}:${H}`,description:S.message?`${Ee.action} (${S.message})`:Ee.action,duration:6e3}):console.debug(`[tapflow] input refused, shown nowhere: ${H}${S.message?` — ${S.message}`:""}`)}if(S.type==="device:booting"&&(k(!1),L(!1),C(!1),K(null),O(null),Te.current.clear(),Ue.current.clear(),_(null)),S.type==="device:ready"){if(k(!0),S.requestId!==void 0&&!ge.current.delete(S.requestId))return;if(d.current.pending>0){const{appInstalled:H}=d.current;if(d.current={pending:d.current.pending-1,appInstalled:H},H){C(!0);return}}if(r){L(!0);const H=X();Te.current.add(H),l.current({type:"app:install",sessionId:t,requestId:H,buildId:r})}}if(S.type==="app:install-done"||S.type==="app:install-error"){if(!Te.current.delete(S.requestId))return;L(!1),S.type==="app:install-done"?C(!0):K(S.message)}if(S.type==="app:launch-done"||S.type==="app:launch-error"){if(!Ue.current.delete(S.requestId))return;ue(!1)}if(S.type==="session:chrome"&&_(S.payload),S.type==="keyboard:toggled"){const{visible:H}=S.payload;Pe(H),q(!1),B.current&&clearTimeout(B.current)}if(S.type==="network:state"||S.type==="network:error"){(z=be.current)==null||z.call(be,S);return}if(S.type==="device:shutdown-done"||S.type==="device:shutdown-error"){(re=Le.current)==null||re.call(Le,S);return}if((S.type==="clipboard:data"||S.type==="clipboard:write-done"||S.type==="clipboard:error")&&((ae=ce.current)==null||ae.call(ce,S)),S.type==="open-url:done"||S.type==="open-url:error"){if(!J.current.delete(S.requestId))return;S.type==="open-url:done"?Ce.success("Deeplink opened"):Ce.error(S.message)}if(S.type==="error")switch(S.reason){case"session-not-found":a==null||a("agent-disconnected");return;case"session-busy":a==null||a("busy-elsewhere");return;case"agent-resources-exhausted":a==null||a("mac-overloaded");return}}},[t,r,a,o,M,v,Y]),Ke=s.useCallback(S=>{var H;const z=jo(S);if(z&&z.codec===Wn){Oe(S.slice(Kt));return}z&&z.codec===Mt||g.current.push(z);const re=z?S.slice(Kt):S,ae=z?{codec:z.codec,keyframe:z.keyframe,capturedAt:z.capturedAt,relayedAt:z.relayedAt}:void 0;(H=we.current)==null||H.call(we,re,ae)},[Oe]),{send:se,connected:ne}=Nn(ht,Ke);s.useLayoutEffect(()=>{l.current=se}),s.useEffect(()=>{ne&&se({type:"session:start",sessionId:t})},[ne,se,t]);const le=j!==null&&"framePng"in j?j:null,Z=j!==null&&!("framePng"in j)?j:null,de=()=>{q(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{q(!1),Ce.error("The device did not answer. The software keyboard is where it was, as far as tapflow can tell.")},De),se({type:"input:keyboard:toggle",sessionId:t})},pe=s.useCallback(S=>{const z=X();J.current.add(z),l.current({type:"open-url",sessionId:t,requestId:z,payload:{url:S}})},[t]),fe=s.useCallback(()=>{if(r===void 0)return;const S=X();Ue.current.add(S),ue(!0),l.current({type:"app:launch",sessionId:t,requestId:S,buildId:r})},[t,r]),{pending:he,reboot:ve}=Vo({sessionId:t,deviceId:e,deviceReady:N,send:se,handlerRef:Le,onShutdownComplete:s.useCallback(()=>{Y("app-only")},[Y]),onError:s.useCallback(S=>{Ce.error(S)},[])}),oe=s.useRef(null),me=s.useRef(null),ye=s.useRef(!1),Se=s.useRef(!1);s.useEffect(()=>{var ae;const S=!!(le??Z),z=ye.current&&!S,re=!ye.current&&S;if(ye.current=S,z){const H=oe.current;if(!H||document.activeElement!==document.body)return;H.focus(),Se.current=!0;return}if(re&&Se.current){if(Se.current=!1,document.activeElement!==document.body)return;(ae=me.current)==null||ae.focus()}},[le,Z]);const Fe={sessionId:t,buildId:r,send:se,openUrl:pe,launchApp:fe,connected:ne,joined:x,deviceReady:N,installing:T,installed:M,installError:$,bootError:V,launching:G,binaryFrameHandlerRef:we,clipboardHandlerRef:ce,clipboardSupported:_e.includes("clipboard"),networkHandlerRef:be,networkSupported:_e.includes("network-control"),onRecordingUploaded:i,swKeyboardVisible:$e,swKeyboardPending:U,onKbdToggle:de,rebootPending:he,onReboot:ve,viewerRootRef:me};if(!le&&!Z)return n.jsxs("div",{ref:oe,tabIndex:-1,role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16 outline-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded-md",children:[n.jsx("div",{"aria-hidden":"true",className:"flex flex-col items-center gap-0.5 rounded-2xl border bg-background/90 px-1.5 py-2.5 shrink-0 mt-3 opacity-40",children:Array.from({length:5}).map((S,z)=>n.jsx("div",{className:"h-8 w-8 rounded-md bg-muted animate-pulse"},z))}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{"aria-hidden":"true",style:{background:"#1c1c1e",borderRadius:"34px",padding:"12px",flexShrink:0},children:n.jsx("div",{className:"animate-pulse bg-zinc-700",style:{width:324,height:720,borderRadius:"22px"}})}),n.jsx(Qt,{joined:x,fps:0,connected:ne,deviceReady:N,bootError:V,installing:T,installError:$,keyboardActive:!1,agentAway:v})]})]});const Ie=void 0;return n.jsxs(n.Fragment,{children:[le&&n.jsx(Uo,{...Fe,chrome:le,perfHookRef:Ie}),Z&&n.jsx(Oo,{...Fe,androidButtons:Z.buttons,screenWidth:Z.screenWidth,screenHeight:Z.screenHeight,cornerRadius:Z.cornerRadius,perfHookRef:Ie}),!1]})}const Xn=s.forwardRef(({className:t,...e},r)=>n.jsx("textarea",{className:ee("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:r,...e}));Xn.displayName="Textarea";var Ko=Object.defineProperty,F=(t,e)=>Ko(t,"name",{value:e,configurable:!0});function Kn(t,e){return s.useReducer((r,o)=>e[r][o]??r,t)}F(Kn,"useStateMachine");var Yn="ScrollArea",[Gn,Ha]=Tn(Yn),[Yo,Ae]=Gn(Yn),Go=s.forwardRef(F(function(e,r){const{__scopeScrollArea:o,type:i="hover",dir:a,scrollHideDelay:l=600,...f}=e,[d,h]=s.useState(null),[m,g]=s.useState(null),[x,u]=s.useState(null),[v,w]=s.useState(null),[N,k]=s.useState(null),[j,_]=s.useState(0),[T,L]=s.useState(0),[M,C]=s.useState(!1),[$,K]=s.useState(!1),V=Ze(r,h),O=mr(a);return n.jsx(Yo,{scope:o,type:i,dir:O,scrollHideDelay:l,scrollArea:d,viewport:m,onViewportChange:g,content:x,onContentChange:u,scrollbarX:v,onScrollbarXChange:w,scrollbarXEnabled:M,onScrollbarXEnabledChange:C,scrollbarY:N,onScrollbarYChange:k,scrollbarYEnabled:$,onScrollbarYEnabledChange:K,onCornerWidthChange:_,onCornerHeightChange:L,children:n.jsx(et.div,{dir:O,...f,ref:V,style:{position:"relative","--radix-scroll-area-corner-width":j+"px","--radix-scroll-area-corner-height":T+"px",...e.style}})})},"ScrollArea")),Jo="ScrollAreaViewport",Qo=s.forwardRef(F(function(e,r){const{__scopeScrollArea:o,children:i,nonce:a,...l}=e,f=Ae(Jo,o),d=s.useRef(null),h=Ze(r,d,f.onViewportChange);return n.jsxs(n.Fragment,{children:[n.jsx(Zo,{nonce:a}),n.jsx(et.div,{"data-radix-scroll-area-viewport":"",...l,ref:h,style:{overflowX:f.scrollbarXEnabled?"scroll":"hidden",overflowY:f.scrollbarYEnabled?"scroll":"hidden",...e.style},children:n.jsx("div",{ref:f.onContentChange,style:{minWidth:"100%",display:"table"},children:i})})]})},"ScrollAreaViewport")),Zo=s.memo(F(function({nonce:e}){return n.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:e})},"ScrollAreaViewportStyle"),(t,e)=>t.nonce===e.nonce),Xe="ScrollAreaScrollbar",Jn=s.forwardRef(F(function(e,r){const{forceMount:o,...i}=e,a=Ae(Xe,e.__scopeScrollArea),{onScrollbarXEnabledChange:l,onScrollbarYEnabledChange:f}=a,d=e.orientation==="horizontal";return s.useEffect(()=>(d?l(!0):f(!0),()=>{d?l(!1):f(!1)}),[d,l,f]),a.type==="hover"?n.jsx(ea,{...i,ref:r,forceMount:o}):a.type==="scroll"?n.jsx(ta,{...i,ref:r,forceMount:o}):a.type==="auto"?n.jsx(Qn,{...i,ref:r,forceMount:o}):a.type==="always"?n.jsx(en,{...i,ref:r,"data-state":"visible"}):null},"ScrollAreaScrollbar")),ea=s.forwardRef(F(function(e,r){const{forceMount:o,...i}=e,a=Ae(Xe,e.__scopeScrollArea),[l,f]=s.useState(!1);return s.useEffect(()=>{const d=a.scrollArea;let h=0;if(d){const m=F(()=>{window.clearTimeout(h),f(!0)},"handlePointerEnter"),g=F(()=>{h=window.setTimeout(()=>f(!1),a.scrollHideDelay)},"handlePointerLeave");return d.addEventListener("pointerenter",m),d.addEventListener("pointerleave",g),()=>{window.clearTimeout(h),d.removeEventListener("pointerenter",m),d.removeEventListener("pointerleave",g)}}},[a.scrollArea,a.scrollHideDelay]),n.jsx(Ut,{present:o||l,children:n.jsx(Qn,{"data-state":l?"visible":"hidden",...i,ref:r})})},"ScrollAreaScrollbarHover")),ta=s.forwardRef(F(function(e,r){const{forceMount:o,...i}=e,a=Ae(Xe,e.__scopeScrollArea),l=e.orientation==="horizontal",f=Et(()=>h("SCROLL_END"),100),[d,h]=Kn("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return s.useEffect(()=>{if(d==="idle"){const m=window.setTimeout(()=>h("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(m)}},[d,a.scrollHideDelay,h]),s.useEffect(()=>{const m=a.viewport,g=l?"scrollLeft":"scrollTop";if(m){let x=m[g];const u=F(()=>{const v=m[g];x!==v&&(h("SCROLL"),f()),x=v},"handleScroll");return m.addEventListener("scroll",u),()=>m.removeEventListener("scroll",u)}},[a.viewport,l,h,f]),n.jsx(Ut,{present:o||d!=="hidden",children:n.jsx(en,{"data-state":d==="hidden"?"hidden":"visible",...i,ref:r,onPointerEnter:qe(e.onPointerEnter,()=>h("POINTER_ENTER")),onPointerLeave:qe(e.onPointerLeave,()=>h("POINTER_LEAVE"))})})},"ScrollAreaScrollbarScroll")),Qn=s.forwardRef(F(function(e,r){const o=Ae(Xe,e.__scopeScrollArea),{forceMount:i,...a}=e,[l,f]=s.useState(!1),d=e.orientation==="horizontal",h=Et(()=>{if(o.viewport){const m=o.viewport.offsetWidth<o.viewport.scrollWidth,g=o.viewport.offsetHeight<o.viewport.scrollHeight;f(d?m:g)}},10);return ft(o.viewport,h),ft(o.content,h),n.jsx(Ut,{present:i||l,children:n.jsx(en,{"data-state":l?"visible":"hidden",...a,ref:r})})},"ScrollAreaScrollbarAuto")),en=s.forwardRef(F(function(e,r){const{orientation:o="vertical",...i}=e,a=Ae(Xe,e.__scopeScrollArea),l=s.useRef(null),f=s.useRef(0),[d,h]=s.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),m=tn(d.viewport,d.content),g={...i,sizes:d,onSizesChange:h,hasThumb:m>0&&m<1,onThumbChange:F(u=>l.current=u,"onThumbChange"),onThumbPointerUp:F(()=>f.current=0,"onThumbPointerUp"),onThumbPointerDown:F(u=>f.current=u,"onThumbPointerDown")};function x(u,v){return nr(u,f.current,d,v)}return F(x,"getScrollPosition"),o==="horizontal"?n.jsx(na,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&l.current){const u=a.viewport.scrollLeft,v=Gt(u,d,a.dir);l.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:u=>{a.viewport&&(a.viewport.scrollLeft=u)},onDragScroll:u=>{a.viewport&&(a.viewport.scrollLeft=x(u,a.dir))}}):o==="vertical"?n.jsx(ra,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&l.current){const u=a.viewport.scrollTop,v=Gt(u,d);l.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:u=>{a.viewport&&(a.viewport.scrollTop=u)},onDragScroll:u=>{a.viewport&&(a.viewport.scrollTop=x(u))}}):null},"ScrollAreaScrollbarVisible")),na=s.forwardRef(F(function(e,r){const{sizes:o,onSizesChange:i,...a}=e,l=Ae(Xe,e.__scopeScrollArea),[f,d]=s.useState(),h=s.useRef(null),m=Ze(r,h,l.onScrollbarXChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(er,{"data-orientation":"horizontal",...a,ref:m,sizes:o,style:{bottom:0,left:l.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:l.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Tt(o)+"px",...e.style},onThumbPointerDown:g=>e.onThumbPointerDown(g.x),onDragScroll:g=>e.onDragScroll(g.x),onWheelScroll:(g,x)=>{if(l.viewport){const u=l.viewport.scrollLeft+g.deltaX;e.onWheelScroll(u),rn(u,x)&&g.preventDefault()}},onResize:()=>{h.current&&l.viewport&&f&&i({content:l.viewport.scrollWidth,viewport:l.viewport.offsetWidth,scrollbar:{size:h.current.clientWidth,paddingStart:Ct(f.paddingLeft),paddingEnd:Ct(f.paddingRight)}})}})},"ScrollAreaScrollbarX")),ra=s.forwardRef(F(function(e,r){const{sizes:o,onSizesChange:i,...a}=e,l=Ae(Xe,e.__scopeScrollArea),[f,d]=s.useState(),h=s.useRef(null),m=Ze(r,h,l.onScrollbarYChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(er,{"data-orientation":"vertical",...a,ref:m,sizes:o,style:{top:0,right:l.dir==="ltr"?0:void 0,left:l.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Tt(o)+"px",...e.style},onThumbPointerDown:g=>e.onThumbPointerDown(g.y),onDragScroll:g=>e.onDragScroll(g.y),onWheelScroll:(g,x)=>{if(l.viewport){const u=l.viewport.scrollTop+g.deltaY;e.onWheelScroll(u),rn(u,x)&&g.preventDefault()}},onResize:()=>{h.current&&l.viewport&&f&&i({content:l.viewport.scrollHeight,viewport:l.viewport.offsetHeight,scrollbar:{size:h.current.clientHeight,paddingStart:Ct(f.paddingTop),paddingEnd:Ct(f.paddingBottom)}})}})},"ScrollAreaScrollbarY")),[sa,Zn]=Gn(Xe),er=s.forwardRef(F(function(e,r){const{__scopeScrollArea:o,sizes:i,hasThumb:a,onThumbChange:l,onThumbPointerUp:f,onThumbPointerDown:d,onThumbPositionChange:h,onDragScroll:m,onWheelScroll:g,onResize:x,...u}=e,v=Ae(Xe,o),[w,N]=s.useState(null),k=Ze(r,N),j=s.useRef(null),_=s.useRef(""),T=v.viewport,L=i.content-i.viewport,M=dt(g),C=dt(h),$=Et(x,10);function K(V){if(j.current){const O=V.clientX-j.current.left,G=V.clientY-j.current.top;m({x:O,y:G})}}return F(K,"handleDragScroll"),s.useEffect(()=>{const V=F(O=>{const G=O.target;(w==null?void 0:w.contains(G))&&M(O,L)},"handleWheel");return document.addEventListener("wheel",V,{passive:!1}),()=>document.removeEventListener("wheel",V,{passive:!1})},[T,w,L,M]),s.useEffect(C,[i,C]),ft(w,$),ft(v.content,$),n.jsx(sa,{scope:o,scrollbar:w,hasThumb:a,onThumbChange:dt(l),onThumbPointerUp:dt(f),onThumbPositionChange:C,onThumbPointerDown:dt(d),children:n.jsx(et.div,{...u,ref:k,style:{position:"absolute",...u.style},onPointerDown:qe(e.onPointerDown,V=>{V.button===0&&(V.target.setPointerCapture(V.pointerId),j.current=w.getBoundingClientRect(),_.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),K(V))}),onPointerMove:qe(e.onPointerMove,K),onPointerUp:qe(e.onPointerUp,V=>{const O=V.target;O.hasPointerCapture(V.pointerId)&&O.releasePointerCapture(V.pointerId),document.body.style.webkitUserSelect=_.current,v.viewport&&(v.viewport.style.scrollBehavior=""),j.current=null})})})},"ScrollAreaScrollbarImpl")),Yt="ScrollAreaThumb",oa=s.forwardRef(F(function(e,r){const{forceMount:o,...i}=e,a=Zn(Yt,e.__scopeScrollArea);return n.jsx(Ut,{present:o||a.hasThumb,children:n.jsx(aa,{ref:r,...i})})},"ScrollAreaThumb")),aa=s.forwardRef(F(function(e,r){const{__scopeScrollArea:o,style:i,...a}=e,l=Ae(Yt,o),f=Zn(Yt,o),{onThumbPositionChange:d}=f,h=Ze(r,f.onThumbChange),m=s.useRef(void 0),g=Et(()=>{m.current&&(m.current(),m.current=void 0)},100);return s.useEffect(()=>{const x=l.viewport;if(x){const u=F(()=>{if(g(),!m.current){const v=la(x,d);m.current=v,d()}},"handleScroll");return d(),x.addEventListener("scroll",u),()=>x.removeEventListener("scroll",u)}},[l.viewport,g,d]),n.jsx(et.div,{"data-state":f.hasThumb?"visible":"hidden",...a,ref:h,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...i},onPointerDownCapture:qe(e.onPointerDownCapture,x=>{const v=x.target.getBoundingClientRect(),w=x.clientX-v.left,N=x.clientY-v.top;f.onThumbPointerDown({x:w,y:N})}),onPointerUp:qe(e.onPointerUp,f.onThumbPointerUp)})},"ScrollAreaThumbImpl")),tr="ScrollAreaCorner",ia=s.forwardRef(F(function(e,r){const o=Ae(tr,e.__scopeScrollArea),i=!!(o.scrollbarX&&o.scrollbarY);return o.type!=="scroll"&&i?n.jsx(ca,{...e,ref:r}):null},"ScrollAreaCorner")),ca=s.forwardRef(F(function(e,r){const{__scopeScrollArea:o,...i}=e,a=Ae(tr,o),[l,f]=s.useState(0),[d,h]=s.useState(0),m=!!(l&&d),{onCornerWidthChange:g,onCornerHeightChange:x}=a;return ft(a.scrollbarX,()=>{var v;const u=((v=a.scrollbarX)==null?void 0:v.offsetHeight)||0;a.onCornerHeightChange(u),h(u)}),ft(a.scrollbarY,()=>{var v;const u=((v=a.scrollbarY)==null?void 0:v.offsetWidth)||0;a.onCornerWidthChange(u),f(u)}),s.useEffect(()=>()=>{g(0),x(0)},[g,x]),m?n.jsx(et.div,{...i,ref:r,style:{width:l,height:d,position:"absolute",right:a.dir==="ltr"?0:void 0,left:a.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null},"ScrollAreaCornerImpl"));function Ct(t){return t?parseInt(t,10):0}F(Ct,"toInt");function tn(t,e){const r=t/e;return isNaN(r)?0:r}F(tn,"getThumbRatio");function Tt(t){const e=tn(t.viewport,t.content),r=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,o=(t.scrollbar.size-r)*e;return Math.max(o,18)}F(Tt,"getThumbSize");function nr(t,e,r,o="ltr"){const i=Tt(r),a=i/2,l=e||a,f=i-l,d=r.scrollbar.paddingStart+l,h=r.scrollbar.size-r.scrollbar.paddingEnd-f,m=r.content-r.viewport,g=o==="ltr"?[0,m]:[m*-1,0];return nn([d,h],g)(t)}F(nr,"getScrollPositionFromPointer");function Gt(t,e,r="ltr"){const o=Tt(e),i=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=e.scrollbar.size-i,l=e.content-e.viewport,f=a-o,d=r==="ltr"?[0,l]:[l*-1,0],h=Br(t,d);return nn([0,l],[0,f])(h)}F(Gt,"getThumbOffsetFromScroll");function nn(t,e){return r=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const o=(e[1]-e[0])/(t[1]-t[0]);return e[0]+o*(r-t[0])}}F(nn,"linearScale");function rn(t,e){return t>0&&t<e}F(rn,"isScrollingWithinScrollbarBounds");var la=F((t,e=()=>{})=>{let r={left:t.scrollLeft,top:t.scrollTop},o=0;return F((function i(){const a={left:t.scrollLeft,top:t.scrollTop},l=r.left!==a.left,f=r.top!==a.top;(l||f)&&e(),r=a,o=window.requestAnimationFrame(i)}),"loop")(),()=>window.cancelAnimationFrame(o)},"addUnlinkedScrollListener");function Et(t,e){const r=dt(t),o=s.useRef(0);return s.useEffect(()=>()=>window.clearTimeout(o.current),[]),s.useCallback(()=>{window.clearTimeout(o.current),o.current=window.setTimeout(r,e)},[r,e])}F(Et,"useDebounceCallback");function ft(t,e){const r=dt(e);pr(()=>{let o=0;if(t){const i=new ResizeObserver(()=>{cancelAnimationFrame(o),o=window.requestAnimationFrame(r)});return i.observe(t),()=>{window.cancelAnimationFrame(o),i.unobserve(t)}}},[t,r])}F(ft,"useResizeObserver");var rr=Go,ua=Qo,da=ia;const sr=s.forwardRef(({className:t,children:e,...r},o)=>n.jsxs(rr,{ref:o,className:ee("relative overflow-hidden",t),...r,children:[n.jsx(ua,{className:"h-full w-full rounded-[inherit]",children:e}),n.jsx(or,{}),n.jsx(da,{})]}));sr.displayName=rr.displayName;const or=s.forwardRef(({className:t,orientation:e="vertical",...r},o)=>n.jsx(Jn,{ref:o,orientation:e,className:ee("flex touch-none select-none transition-colors",e==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",e==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...r,children:n.jsx(oa,{className:"relative flex-1 rounded-full bg-border"})}));or.displayName=Jn.displayName;function ar(t){return/[Zz]|[+-]\d{2}/.test(t)?new Date(t):new Date(t.replace(" ","T")+"Z")}function fa(t){const e=new Map;for(const i of t){const a=ar(i.created_at).toDateString();e.has(a)||e.set(a,[]),e.get(a).push(i)}const r=new Date().toDateString(),o=new Date(Date.now()-864e5).toDateString();return Array.from(e.entries()).map(([i,a])=>{let l;if(i===r)l="Today";else if(i===o)l="Yesterday";else{const f=new Date(i);l=f.toLocaleDateString(void 0,{month:"short",day:"numeric",...f.getFullYear()!==new Date().getFullYear()?{year:"numeric"}:{}})}return{label:l,items:a}})}function ha(t){return ar(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}const pa=5*1024*1024,ma=["image/png","image/jpeg","image/webp"];function ga({buildId:t}){const[e,r]=s.useState([]),[o,i]=s.useState(""),[a,l]=s.useState(null),[f,d]=s.useState(!1),[h,m]=s.useState(""),g=s.useRef(null),x=s.useRef({}),u=s.useCallback(()=>{fetch(`/api/v1/comments?build_id=${t}`,{credentials:"include"}).then(j=>j.ok?j.json():[]).then(r)},[t]);s.useEffect(()=>{u()},[u]),s.useEffect(()=>{const j=window.location.hash;if(!j.startsWith("#comment-"))return;const _=Number(j.replace("#comment-","")),T=x.current[_];if(!T)return;T.scrollIntoView({behavior:"smooth"});const L=document.documentElement.classList.contains("dark");T.style.backgroundColor=L?"rgb(0 112 243 / 0.18)":"#d3e5ff",setTimeout(()=>{T.style.backgroundColor=""},2e3)},[e]);function v(j){const _=`${location.origin}${location.pathname}${location.search}#comment-${j}`;navigator.clipboard.writeText(_).then(()=>Ce.success("Link copied")).catch(()=>Ce.error("Could not copy link"))}function w(j){if(m(""),!ma.includes(j.type)){m("Only png, jpg, webp allowed");return}if(j.size>pa){m("Max 5MB");return}l(j)}async function N(j){if(j.preventDefault(),!o.trim()&&!a)return;d(!0);const _=new FormData;_.append("build_id",String(t)),_.append("body",o),a&&_.append("attachment",a),(await fetch("/api/v1/comments",{method:"POST",credentials:"include",body:_})).ok&&(i(""),l(null),u()),d(!1)}const k=fa(e);return n.jsxs("div",{className:"flex h-full flex-col gap-3 px-1",children:[n.jsx(sr,{className:"flex-1 rounded-md border",children:n.jsx("div",{className:"p-3",children:e.length===0?n.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No comments yet."}):n.jsx("div",{className:"flex flex-col",children:k.map(({label:j,items:_})=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 py-3",children:[n.jsx("div",{className:"h-px flex-1 bg-border"}),n.jsx("span",{className:"text-[11px] font-medium text-muted-foreground px-1 select-none",children:j}),n.jsx("div",{className:"h-px flex-1 bg-border"})]}),n.jsx("div",{className:"flex flex-col gap-4",children:_.map(T=>n.jsxs("div",{id:`comment-${T.id}`,ref:L=>{x.current[T.id]=L},className:"group flex gap-2.5 rounded-md px-2 py-1.5 transition-all",children:[n.jsx("div",{className:"mt-0.5 shrink-0",children:n.jsx(gr,{name:T.author,avatarUrl:T.authorAvatarUrl,size:28})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-semibold leading-none",children:T.author}),n.jsx("span",{className:"text-[11px] text-muted-foreground leading-none",children:ha(T.created_at)}),n.jsx(ie,{variant:"ghost",size:"icon",className:"h-4 w-4 ml-0.5 opacity-0 group-hover:opacity-50 hover:!opacity-100 group-focus-within:opacity-50 focus-visible:!opacity-100 transition-opacity","aria-label":"Copy link to comment",onClick:()=>v(T.id),children:n.jsx(In,{className:"h-3 w-3","aria-hidden":"true"})})]}),n.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap mt-1",children:T.body}),T.attachments.map(L=>{const M=decodeURIComponent(L.file_path.split("/").pop()??"image");return n.jsx("a",{href:L.file_path,target:"_blank",rel:"noreferrer",className:"mt-1.5 block","aria-label":`Open ${M} in a new tab`,children:n.jsx("img",{src:L.file_path,alt:M,className:"max-h-48 rounded border object-contain"})},L.id)})]})]},T.id))})]},j))})})}),n.jsx("div",{className:"pb-1",children:n.jsx("form",{onSubmit:N,children:n.jsxs("div",{className:"rounded-md border border-input bg-background ring-offset-background transition-shadow focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[n.jsx(Xn,{"aria-label":"Comment",placeholder:"Leave a comment…",value:o,onChange:j=>i(j.target.value),className:"min-h-16 resize-none border-0 bg-transparent shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 text-sm"}),(a||h)&&n.jsxs("div",{className:"px-3 -mt-1 pb-1",children:[a&&n.jsx("p",{className:"text-xs text-muted-foreground",children:a.name}),h&&n.jsx("p",{className:"text-xs text-destructive",children:h})]}),n.jsxs("div",{className:"flex items-center gap-2 px-2 py-2",children:[n.jsx(ie,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground","aria-label":"Attach image",onClick:()=>{var j;return(j=g.current)==null?void 0:j.click()},children:n.jsx(os,{className:"h-4 w-4","aria-hidden":"true"})}),n.jsx("input",{ref:g,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:j=>{var T;const _=(T=j.target.files)==null?void 0:T[0];_&&w(_)}}),n.jsx("div",{className:"flex-1"}),n.jsx(ie,{type:"submit",size:"icon",className:"h-7 w-7 rounded-full","aria-label":"Post comment",disabled:f||!o.trim()&&!a,children:n.jsx(Gr,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})})})]})}function xa(t){return t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ba(t){return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function va(t){const e=new Date(t).getTime()-Date.now();if(e<=0)return{label:"Expired",urgent:!0};const r=Math.floor(e/36e5);return r<1?{label:"< 1 hour left",urgent:!0}:r<24?{label:`Expires in ${r}h`,urgent:r<6}:{label:`Expires in ${Math.floor(r/24)}d`,urgent:!1}}function ya({buildId:t,refreshKey:e}){const[r,o]=s.useState([]),[i,a]=s.useState(!0),[l,f]=s.useState(!1);return s.useEffect(()=>{a(!0),f(!1);const d=setTimeout(()=>f(!0),250);return fetch(`/api/v1/recordings?buildId=${t}`,{credentials:"include"}).then(h=>h.ok?h.json():[]).then(h=>o(h)).catch(()=>o([])).finally(()=>{clearTimeout(d),a(!1)}),()=>clearTimeout(d)},[t,e]),i?l?n.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading recordings…"}):null:r.length===0?n.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No recordings yet."}):n.jsx("div",{className:"flex flex-col gap-2",children:r.map(d=>{const h=va(d.expiresAt);return n.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2 text-sm",children:[n.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:ba(d.createdAt)}),n.jsxs("span",{className:`text-xs ${h.urgent?"text-destructive":"text-muted-foreground"}`,children:[h.label," · ",xa(d.fileSize)]})]}),n.jsx(ie,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 ml-2",title:"Download",onClick:()=>{const m=document.createElement("a");m.href=d.url,m.download="",m.click()},children:n.jsx(es,{className:"h-3.5 w-3.5"})})]},d.id)})})}function wa({buildId:t,recordingsRefreshKey:e=0}){return n.jsxs(Tr,{defaultValue:"comments",className:"flex h-full flex-col",children:[n.jsx("div",{className:"shrink-0 px-1",children:n.jsxs(Er,{className:"w-full",children:[n.jsxs(un,{value:"comments",className:"flex-1 gap-1.5",children:[n.jsx(ds,{className:"h-3.5 w-3.5"}),"Comments"]}),n.jsxs(un,{value:"recordings",className:"flex-1 gap-1.5",children:[n.jsx(ns,{className:"h-3.5 w-3.5"}),"Recordings"]})]})}),n.jsx(dn,{value:"comments",className:"mt-3 min-h-0 flex-1 overflow-hidden",children:n.jsx(ga,{buildId:t})}),n.jsx(dn,{value:"recordings",className:"mt-3 min-h-0 flex-1 overflow-y-auto",children:n.jsx(ya,{buildId:t,refreshKey:e})})]})}const ir=s.forwardRef(({...t},e)=>n.jsx("nav",{ref:e,"aria-label":"breadcrumb",...t}));ir.displayName="Breadcrumb";const cr=s.forwardRef(({className:t,...e},r)=>n.jsx("ol",{ref:r,className:ee("flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",t),...e}));cr.displayName="BreadcrumbList";const jt=s.forwardRef(({className:t,...e},r)=>n.jsx("li",{ref:r,className:ee("inline-flex items-center gap-1.5",t),...e}));jt.displayName="BreadcrumbItem";const Dt=s.forwardRef(({asChild:t,className:e,...r},o)=>{const i=t?xr:"a";return n.jsx(i,{ref:o,className:ee("transition-colors hover:text-foreground cursor-pointer",e),...r})});Dt.displayName="BreadcrumbLink";const Lt=s.forwardRef(({className:t,...e},r)=>n.jsx("span",{ref:r,role:"link","aria-disabled":"true","aria-current":"page",className:ee("font-medium text-foreground",t),...e}));Lt.displayName="BreadcrumbPage";const It=({children:t,className:e,...r})=>n.jsx("li",{role:"presentation","aria-hidden":"true",className:ee("[&>svg]:h-3.5 [&>svg]:w-3.5",e),...r,children:t??n.jsx(br,{})});It.displayName="BreadcrumbSeparator";var Sa=Object.defineProperty,Qe=(t,e)=>Sa(t,"name",{value:e,configurable:!0}),sn="Switch",[Ra,za]=Tn(sn),[ka,on]=Ra(sn);function lr(t){const{__scopeSwitch:e,checked:r,children:o,defaultChecked:i,disabled:a,form:l,name:f,onCheckedChange:d,required:h,value:m="on",internal_do_not_use_render:g}=t,[x,u]=yr({prop:r,defaultProp:i??!1,onChange:d,caller:sn}),[v,w]=s.useState(null),[N,k]=s.useState(null),j=s.useRef(!1),[_,T]=s.useReducer(C=>C+1,0),L=v?!!l||!!v.closest("form"):!0,M={checked:x,setChecked:u,disabled:a,control:v,setControl:w,name:f,form:l,value:m,hasConsumerStoppedPropagationRef:j,userInteractionCount:_,onUserInteraction:T,required:h,defaultChecked:i,isFormControl:L,bubbleInput:N,setBubbleInput:k};return n.jsx(ka,{scope:e,...M,children:dr(g)?g(M):o})}Qe(lr,"SwitchProvider");var ja="SwitchTrigger",Ca=s.forwardRef(Qe(function({__scopeSwitch:e,onClick:r,...o},i){const{control:a,form:l,value:f,disabled:d,checked:h,required:m,setControl:g,setChecked:x,hasConsumerStoppedPropagationRef:u,onUserInteraction:v,isFormControl:w,bubbleInput:N}=on(ja,e),k=Ze(i,g),j=s.useRef(h);return s.useEffect(()=>{const _=l?a==null?void 0:a.ownerDocument.getElementById(l):a==null?void 0:a.form;if(_ instanceof HTMLFormElement){const T=Qe(()=>x(j.current),"reset");return _.addEventListener("reset",T),()=>_.removeEventListener("reset",T)}},[a,l,x]),n.jsx(et.button,{type:"button",role:"switch","aria-checked":h,"aria-required":m,"data-state":an(h),"data-disabled":d?"":void 0,disabled:d,value:f,...o,ref:k,onClick:qe(r,_=>{v(),x(T=>!T),N&&w&&(u.current=_.isPropagationStopped(),u.current||_.stopPropagation())})})},"SwitchTrigger")),ur=s.forwardRef(Qe(function(e,r){const{__scopeSwitch:o,name:i,checked:a,defaultChecked:l,required:f,disabled:d,value:h,onCheckedChange:m,form:g,...x}=e;return n.jsx(lr,{__scopeSwitch:o,checked:a,defaultChecked:l,disabled:d,required:f,onCheckedChange:m,name:i,form:g,value:h,internal_do_not_use_render:({isFormControl:u})=>n.jsxs(n.Fragment,{children:[n.jsx(Ca,{...x,ref:r,__scopeSwitch:o}),u&&n.jsx(Aa,{__scopeSwitch:o})]})})},"Switch")),Ta="SwitchThumb",Ea=s.forwardRef(Qe(function(e,r){const{__scopeSwitch:o,...i}=e,a=on(Ta,o);return n.jsx(et.span,{"data-state":an(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:r})},"SwitchThumb")),Na="SwitchBubbleInput",Aa=s.forwardRef(Qe(function({__scopeSwitch:e,onClick:r,...o},i){const{control:a,hasConsumerStoppedPropagationRef:l,userInteractionCount:f,checked:d,defaultChecked:h,required:m,disabled:g,name:x,value:u,form:v,bubbleInput:w,setBubbleInput:N}=on(Na,e),k=Ze(i,N),j=vr(a),_=s.useRef(!1),T=s.useRef(d),L=s.useRef(f);s.useEffect(()=>{const C=w;if(!C)return;const $=window.HTMLInputElement.prototype,V=Object.getOwnPropertyDescriptor($,"checked").set,O=f!==L.current;L.current=f;const G=T.current!==d;T.current=d;const ue=!(O&&l.current);if(G&&V){_.current=!O;const _e=new Event("click",{bubbles:ue});V.call(C,d),C.dispatchEvent(_e),_.current=!1}},[w,d,l,f]);const M=s.useRef(d);return n.jsx(et.input,{type:"checkbox","aria-hidden":!0,defaultChecked:h??M.current,required:m,disabled:g,name:x,value:u,form:v,...o,tabIndex:-1,ref:k,onClick:qe(r,C=>{_.current&&C.stopPropagation()}),style:{...o.style,...j,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"SwitchBubbleInput"));function dr(t){return typeof t=="function"}Qe(dr,"isFunction");function an(t){return t?"checked":"unchecked"}Qe(an,"getState");const fr=s.forwardRef(({className:t,...e},r)=>n.jsx(ur,{className:ee("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...e,ref:r,children:n.jsx(Ea,{className:ee("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));fr.displayName=ur.displayName;const Rn=70,kn=80;function _a(t,e){if(!t||e)return"unknown";const r=t.memUsedMB/t.memTotalMB*100;return t.cpuPercent>kn||r>kn?"overloaded":t.cpuPercent>=Rn||r>=Rn?"warning":"healthy"}const Pa={"agent-disconnected":{title:"The agent disconnected — this session ended.",description:"Pick the Mac again to start a new session."},"busy-elsewhere":{title:"This device is already open in another browser session.",description:"Someone else may be testing it. If you reloaded while your connection was down it is your own tab, and that clears within about 45 seconds."},"mac-overloaded":{title:"That Mac is too busy to start a session.",description:"Pick a different Mac, or wait for it to settle."}};function Wa(){const[t]=An(),e=Nr(),r=t.get("id"),{build:o}=_s(r),[i,a]=s.useState(0),l=(o==null?void 0:o.platform)??"ios",{sessions:f,selectedAgent:d,setSelectedAgent:h,activeSessionId:m,deviceId:g,booting:x,status:u,connected:v,agentGroups:w,startDevice:N,resetDevice:k,handleBack:j,handleBackToMacs:_,handleSessionEnded:T}=Ps(l),L=w.find(U=>U.agentName===d),{osVersions:M,osVersion:C,setOsVersion:$,deviceSearch:K,setDeviceSearch:V,versionedDevices:O,resetMode:G,setResetMode:ue,appliedResetMode:_e,consumeResetMode:Me,fullResetSupported:ge}=Ds(L,l),J=f.flatMap(U=>U.devices).find(U=>U.id===g),Te=J?`${J.name}${J.osVersion?` · ${J.osVersion}`:""}`:"",Ue=s.useCallback(()=>a(U=>U+1),[]),$e=s.useCallback(U=>{Me(),N(U)},[Me,N]),Pe=s.useCallback(U=>{const q=Pa[U];Ce.error(q.title,{description:q.description}),T()},[T]),{setNode:De}=wr();return s.useEffect(()=>{if(o)return De(n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(ir,{children:n.jsxs(cr,{children:[n.jsx(jt,{children:n.jsx(Dt,{asChild:!0,children:n.jsx("button",{onClick:()=>e(`/app-center?appId=${o.app_id}`),children:o.name})})}),n.jsx(It,{}),n.jsx(jt,{children:d?n.jsx(Dt,{asChild:!0,children:n.jsx("button",{onClick:_,children:ln(o)})}):n.jsx(Lt,{children:ln(o)})}),d&&n.jsxs(n.Fragment,{children:[n.jsx(It,{}),n.jsx(jt,{children:m?n.jsx(Dt,{asChild:!0,children:n.jsx("button",{onClick:j,children:d})}):n.jsx(Lt,{children:d})})]}),m&&n.jsxs(n.Fragment,{children:[n.jsx(It,{}),n.jsx(jt,{children:n.jsx(Lt,{children:Te})})]})]})}),!d&&o.status_label&&n.jsx(qr,{tone:jr[o.status_label],children:o.status_label})]})),()=>De(null)},[o,d,m,Te,e,j,_,De]),n.jsxs("div",{className:"flex h-full min-h-0 gap-6 p-6",children:[n.jsx("div",{className:"flex flex-col gap-3 flex-1 min-w-0 min-h-0",children:n.jsx("div",{className:"flex-1 min-h-0 overflow-auto -ml-1 pl-1 -mr-4 pr-4",children:m?n.jsx("div",{className:"min-h-full flex items-center justify-center py-6 px-8 min-w-max",children:n.jsx(Xo,{sessionId:m,deviceId:g,buildId:o==null?void 0:o.id,resetMode:_e,onRecordingUploaded:Ue,onSessionEnded:Pe})}):d?n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:_,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"← All Macs"}),n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select device"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Cr,{placeholder:"Search device…",value:K,onChange:V}),M.length>0&&n.jsxs(Hr,{value:C||"__all__",onValueChange:U=>{$(U==="__all__"?"":U),k()},children:[n.jsx(zr,{className:"h-8 w-36 shrink-0",children:n.jsx(Wr,{})}),n.jsxs(Vr,{children:[n.jsx(fn,{value:"__all__",children:"Any version"}),M.map(U=>n.jsx(fn,{value:U,children:U},U))]})]}),ge&&n.jsx(Vt,{children:n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx(Sr,{htmlFor:"reset-mode",className:"text-sm cursor-pointer whitespace-nowrap",children:"Full reset"}),n.jsx("span",{id:"reset-mode-desc",className:"sr-only",children:"When on, erases all data on the next device you pick"}),n.jsx(fr,{id:"reset-mode","aria-describedby":"reset-mode-desc",checked:G==="full-erase",onCheckedChange:U=>ue(U?"full-erase":"app-only")})]})}),n.jsx(je,{children:G==="full-erase"?"Erase all data on the next device you pick":"Keep existing data"})]})})]}),O.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:v?"No devices available for this OS.":"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:O.map(U=>{const q=U.status==="booted",B=U.busy,we=B?"In use":q?"Booted":"Available",ce=B?"bg-amber-400":q?"bg-emerald-400":"bg-muted-foreground/40";return n.jsxs("button",{disabled:B||x||!v,onClick:()=>$e(U),className:ee("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px]","hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("span",{className:"text-sm font-medium leading-tight",children:U.name}),U.osVersion&&n.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:U.osVersion}),n.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[n.jsx("span",{className:ee("inline-block h-1.5 w-1.5 rounded-full",ce)}),we]})]},U.id)})}),u&&n.jsx("p",{className:"text-sm text-muted-foreground",children:u})]}):n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select Mac"}),w.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:v?`No agents available for ${l}.`:"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:w.map(U=>{const q=U.resources,B=q?Date.now()-q.reportedAt>3e4:!1,we=U.devices.filter(Oe=>Oe.platform===l).length,ce=(q==null?void 0:q.cpuPercent)??0,be=q?q.memUsedMB/q.memTotalMB*100:0,Le=_a(q,B),Y=Le==="overloaded";return n.jsx(Vt,{children:n.jsxs(Re,{children:[n.jsx(ke,{asChild:!0,children:n.jsx("span",{tabIndex:Y?0:void 0,className:Y?"cursor-not-allowed":void 0,children:n.jsxs("button",{disabled:Y,"aria-disabled":Y,onClick:()=>h(U.agentName??null),className:ee("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px] w-full",Y?"pointer-events-none":"hover:bg-accent"),children:[n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(Da,{health:Le}),n.jsx("span",{className:"text-sm font-medium leading-tight truncate",children:U.agentName??"Unknown"})]}),B&&n.jsx("span",{className:"shrink-0 text-[10px] font-medium text-amber-500",children:"Stale"})]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[n.jsxs("span",{children:[we," device",we!==1?"s":""]}),q&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:[q.slotsAvailable,"/",q.slotsTotal," slots"]})]})]}),q&&!B&&n.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[n.jsx(jn,{label:"CPU",percent:ce,colorClass:"bg-blue-400"}),n.jsx(jn,{label:"RAM",percent:be,colorClass:"bg-violet-400"})]})]})})}),Y&&n.jsx(je,{children:"This Mac is currently overloaded. Try again later."})]})},U.agentName)})})]})})}),r&&n.jsxs(n.Fragment,{children:[n.jsx(Cn,{orientation:"vertical",className:"h-auto"}),n.jsx("div",{className:"w-80 shrink-0 h-full",children:n.jsx(wa,{buildId:Number(r),recordingsRefreshKey:i})})]})]})}function Da({health:t}){const e={unknown:"bg-muted-foreground/40",healthy:"bg-emerald-400",warning:"bg-amber-400",overloaded:"bg-red-500"}[t];return n.jsx("span",{"data-testid":"resource-health-dot",className:ee("inline-block h-2 w-2 shrink-0 rounded-full",e)})}function jn({label:t,percent:e,colorClass:r}){return n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[n.jsx("span",{children:t}),n.jsxs("span",{children:[e.toFixed(0),"%"]})]}),n.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:n.jsx("div",{className:ee("h-full rounded-full transition-all",r),style:{width:`${Math.min(100,e)}%`}})})]})}export{Wa as QASession};
@@ -0,0 +1 @@
1
+ import{i as m,j as s}from"./vendor-react-AJpf4YZ0.js";import{ad as b,a5 as S,C as h,c as p,d as x,b as f,a as k,L as u,I as w,B as C,a2 as P,a3 as j}from"./index-9vdYIm7s.js";import{b as E,c as F}from"./vendor-router-ChFy8CZ1.js";const T=P({password:j().min(8),confirm:j()}).refine(r=>r.password===r.confirm,{message:"Passwords do not match",path:["confirm"]});function I(){const r=E(),[g]=F(),a=g.get("token")??"",[n,t]=m.useState("loading"),{register:o,handleSubmit:v,setError:d,formState:{errors:e,isSubmitting:c}}=b({resolver:S(T),mode:"onBlur"});m.useEffect(()=>{if(!a){t("invalid");return}fetch(`/api/v1/auth/reset-password/verify?token=${a}`).then(i=>i.ok?t("valid"):Promise.reject()).catch(()=>t("invalid"))},[a]);async function N(i){try{const l=await fetch("/api/v1/auth/reset-password",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:a,password:i.password})});if(!l.ok){const y=await l.json();d("root",{message:y.error??"Failed to reset password"});return}r("/login",{replace:!0})}catch{d("root",{message:"Network error. Please try again."})}}return n==="loading"?s.jsx("div",{className:"flex min-h-svh items-center justify-center"}):n==="invalid"?s.jsx("div",{className:"bg-mesh-gradient flex min-h-svh items-center justify-center overflow-hidden p-4",children:s.jsx(h,{level:4,className:"w-full max-w-sm text-center",children:s.jsxs(p,{children:[s.jsx(x,{children:"Link expired"}),s.jsx(f,{children:"This password reset link is invalid or has expired. Ask your admin to send a new one."})]})})}):s.jsx("div",{className:"bg-mesh-gradient flex min-h-svh items-center justify-center overflow-hidden p-4",children:s.jsxs(h,{level:4,className:"w-full max-w-sm",children:[s.jsxs(p,{className:"text-center",children:[s.jsx(x,{children:"Reset password"}),s.jsx(f,{children:"Enter your new password below."})]}),s.jsx(k,{children:s.jsxs("form",{onSubmit:v(N),className:"flex flex-col gap-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx(u,{htmlFor:"password",children:"New password"}),s.jsx(w,{id:"password",type:"password",...o("password")}),e.password&&s.jsx("p",{className:"text-sm text-destructive",children:e.password.message})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(u,{htmlFor:"confirm",children:"Confirm password"}),s.jsx(w,{id:"confirm",type:"password",...o("confirm")}),e.confirm&&s.jsx("p",{className:"text-sm text-destructive",children:e.confirm.message})]}),e.root&&s.jsx("p",{className:"text-sm text-destructive",children:e.root.message}),s.jsx(C,{type:"submit",disabled:c,className:"w-full",children:c?"Saving…":"Set new password"})]})})]})})}export{I as ResetPassword};
@@ -0,0 +1 @@
1
+ import{i as f,j as e}from"./vendor-react-AJpf4YZ0.js";import{ai as g,ad as j,a5 as w,C as v,c as N,d as b,a as y,L as i,I as o,B as C,a2 as S,a3 as l}from"./index-9vdYIm7s.js";import{b as k}from"./vendor-router-ChFy8CZ1.js";const E=S({email:l().email("Enter a valid email"),password:l().min(8,"Password must be at least 8 characters"),confirm:l()}).refine(a=>a.password===a.confirm,{message:"Passwords do not match",path:["confirm"]});function B(){const a=k(),{resolvedTheme:d}=g(),p=d==="dark"?"/logo-dark.svg":"/logo.svg",{register:r,handleSubmit:x,setError:c,formState:{errors:s,isSubmitting:m}}=j({resolver:w(E),mode:"onBlur"});f.useEffect(()=>{fetch("/api/v1/auth/status").then(t=>t.json()).then(({initialized:t})=>{t&&a("/login",{replace:!0})}).catch(()=>{})},[a]);async function h(t){try{const n=await fetch("/api/v1/auth/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t.email,password:t.password})});if(!n.ok){const u=await n.json();c("root",{message:u.error??"Failed to create account"});return}a("/login",{replace:!0})}catch{c("root",{message:"Network error. Please try again."})}}return e.jsx("div",{className:"flex min-h-svh items-center justify-center overflow-hidden p-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-6 w-full max-w-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:p,alt:"tapflow",className:"w-6 h-6"}),e.jsx("span",{className:"text-base font-semibold tracking-tight",children:"tapflow"})]}),e.jsxs(v,{level:4,className:"w-full",children:[e.jsx(N,{className:"text-center",children:e.jsx(b,{className:"text-2xl tracking-display-md",children:"Set up tapflow"})}),e.jsx(y,{children:e.jsxs("form",{onSubmit:x(h),className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(i,{htmlFor:"email",children:"Admin email"}),e.jsx(o,{id:"email",type:"email",placeholder:"admin@yourteam.com",autoComplete:"email",...r("email")}),s.email&&e.jsx("p",{className:"text-sm text-destructive",children:s.email.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(i,{htmlFor:"password",children:"Password"}),e.jsx(o,{id:"password",type:"password",autoComplete:"new-password",...r("password")}),s.password&&e.jsx("p",{className:"text-sm text-destructive",children:s.password.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(i,{htmlFor:"confirm",children:"Confirm password"}),e.jsx(o,{id:"confirm",type:"password",autoComplete:"new-password",...r("confirm")}),s.confirm&&e.jsx("p",{className:"text-sm text-destructive",children:s.confirm.message})]}),s.root&&e.jsx("p",{className:"text-sm text-destructive",children:s.root.message}),e.jsx(C,{type:"submit",size:"lg",disabled:m,className:"w-full mt-1",children:m?"Creating account…":"Create admin account"})]})})]})]})})}export{B as Setup};
@@ -1,6 +1,6 @@
1
- import{W as _,a6 as n,ah as z,a9 as J,a3 as e,B as t,L as D,I as G,h as q,C as U,c as W,d as K,a as X,a8 as j,a4 as I,a7 as u,G as Y}from"./index-DXjMx9hQ.js";import{D as Z,f as ee,a as se,d as ae,e as ie,S as N,i as w,j as T,g as k,h as i}from"./dialog-BxC9v2BL.js";import{A as ne,c as te,f as le,g as re,d as ce,e as oe,b as de,a as me}from"./alert-dialog-DWqGDQTB.js";import{T as he,d as xe,e as A,c as l,a as je,b as r}from"./table-CbATN5Pi.js";/**
2
- * @license lucide-react v0.577.0 - ISC
1
+ import{i as n,j as e}from"./vendor-react-AJpf4YZ0.js";import{W as _,ad as z,a5 as J,B as t,L as D,I as G,h as q,C as U,c as W,d as K,a as X,a4 as j,a2 as I,a3 as u,G as Y}from"./index-9vdYIm7s.js";import{D as Z,f as ee,a as se,d as ae,e as ie,S as N,i as w,j as T,g as k,h as i}from"./dialog-DK9a3b4z.js";import{A as ne,c as te,f as le,g as re,d as ce,e as oe,b as de,a as me}from"./alert-dialog-CgatMXjB.js";import{T as he,d as xe,e as A,c as l,a as je,b as r}from"./table-DW57-o1p.js";import"./vendor-router-ChFy8CZ1.js";/**
2
+ * @license lucide-react v1.33.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const ue=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],ve=_("user-plus",ue),pe=I({email:u().email(),role:u().min(1)}),ge=I({token:u(),emailSent:Y()});function Ce(){const[v,R]=n.useState([]),[E,p]=n.useState({}),[g,f]=n.useState(""),[O,b]=n.useState(!1),[o,d]=n.useState(null),{register:V,handleSubmit:H,control:L,reset:P,formState:{errors:S,isSubmitting:y}}=z({resolver:J(pe),mode:"onBlur",defaultValues:{email:"",role:"QA"}});function m(){fetch("/api/v1/team/members",{credentials:"include"}).then(s=>s.json()).then(R)}n.useEffect(()=>{m()},[]);async function $(s){try{const a=await fetch("/api/v1/team/invite",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s.email,role:s.role})});if(!a.ok)throw new Error(`Server error: ${a.status}`);const h=ge.parse(await a.json()),c=`${location.origin}/invite?token=${h.token}`;f(c),navigator.clipboard.writeText(c).catch(()=>{}),h.emailSent?j.success(`Invite email sent to ${s.email}`):j.warning("Invite link copied — email could not be sent. Check your SMTP settings.")}catch{j.error("Failed to create invite link")}}function F(s){b(s),s||(f(""),P())}async function M(s,a){await fetch(`/api/v1/team/members/${s}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({role:a})}),m()}async function Q(s){const c=(await(await fetch(`/api/v1/team/members/${s}/send-reset`,{method:"POST",credentials:"include"})).json()).emailSent?"Sent":"No SMTP";p(x=>({...x,[s]:c})),setTimeout(()=>p(x=>{const C={...x};return delete C[s],C}),3e3)}async function B(s){await fetch(`/api/v1/team/members/${s}`,{method:"DELETE",credentials:"include"}),d(null),m()}return e.jsxs("div",{className:"flex flex-col gap-6 max-w-[900px] mx-auto w-full p-6",children:[e.jsx(ne,{open:o!==null,onOpenChange:s=>{s||d(null)},children:e.jsxs(te,{children:[e.jsxs(le,{children:[e.jsx(re,{children:"Remove this member?"}),e.jsx(ce,{children:"This member will lose access to the team immediately."})]}),e.jsxs(oe,{children:[e.jsx(de,{children:"Cancel"}),e.jsx(me,{className:"bg-destructive/10 text-destructive hover:bg-destructive/20 border-0",onClick:()=>o!==null&&B(o),children:"Remove"})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Team"}),e.jsxs(Z,{open:O,onOpenChange:F,children:[e.jsx(ee,{asChild:!0,children:e.jsxs(t,{size:"sm",children:[e.jsx(ve,{className:"mr-2 h-4 w-4"}),"Invite member"]})}),e.jsxs(se,{className:"sm:max-w-md",children:[e.jsx(ae,{children:e.jsx(ie,{children:"Invite team member"})}),g?e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Invite link copied to clipboard:"}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all",children:g}),e.jsx(t,{onClick:()=>b(!1),children:"Done"})]}):e.jsxs("form",{onSubmit:H($),className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(D,{htmlFor:"invite-email",children:"Email"}),e.jsx(G,{id:"invite-email",type:"email",...V("email")}),S.email&&e.jsx("p",{className:"text-sm text-destructive",children:S.email.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(D,{htmlFor:"invite-role",children:"Role"}),e.jsx(q,{name:"role",control:L,render:({field:s})=>e.jsxs(N,{value:s.value,onValueChange:s.onChange,children:[e.jsx(w,{id:"invite-role",children:e.jsx(T,{})}),e.jsxs(k,{children:[e.jsx(i,{value:"Admin",children:"Admin"}),e.jsx(i,{value:"Developer",children:"Developer"}),e.jsx(i,{value:"QA",children:"QA"}),e.jsx(i,{value:"Viewer",children:"Viewer"})]})]})})]}),e.jsx(t,{type:"submit",disabled:y,children:y?"Creating link…":"Generate invite link"})]})]})]})]}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsxs(K,{children:["Members (",v.length,")"]})}),e.jsx(X,{className:"px-4 pt-0 pb-2",children:e.jsxs(he,{children:[e.jsx(xe,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Nickname"}),e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Role"}),e.jsx(l,{children:"Joined"}),e.jsx(l,{className:"w-10"})]})}),e.jsx(je,{children:v.map(s=>e.jsxs(A,{className:"hover:bg-transparent",children:[e.jsx(r,{className:"font-medium",children:s.display_name||"—"}),e.jsx(r,{className:"text-muted-foreground text-sm",children:s.email}),e.jsx(r,{children:e.jsxs(N,{value:s.role,onValueChange:a=>M(s.id,a),children:[e.jsx(w,{className:"h-7 w-28",children:e.jsx(T,{})}),e.jsxs(k,{children:[e.jsx(i,{value:"Admin",children:"Admin"}),e.jsx(i,{value:"Developer",children:"Developer"}),e.jsx(i,{value:"QA",children:"QA"}),e.jsx(i,{value:"Viewer",children:"Viewer"})]})]})}),e.jsx(r,{className:"text-muted-foreground text-sm",children:new Date(s.joined_at).toLocaleDateString()}),e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{variant:"secondary",size:"nav",onClick:()=>Q(s.id),children:E[s.id]??"Reset pwd"}),e.jsx(t,{variant:"destructive",size:"nav",onClick:()=>d(s.id),children:"Remove"})]})})]},s.id))})]})})]})]})}export{Ce as TeamSettings};
6
+ */const ue=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],ve=_("user-plus",ue),pe=I({email:u().email(),role:u().min(1)}),ge=I({token:u(),emailSent:Y()});function Ne(){const[v,R]=n.useState([]),[E,p]=n.useState({}),[g,f]=n.useState(""),[O,b]=n.useState(!1),[o,d]=n.useState(null),{register:V,handleSubmit:H,control:L,reset:P,formState:{errors:S,isSubmitting:y}}=z({resolver:J(pe),mode:"onBlur",defaultValues:{email:"",role:"QA"}});function m(){fetch("/api/v1/team/members",{credentials:"include"}).then(s=>s.json()).then(R)}n.useEffect(()=>{m()},[]);async function $(s){try{const a=await fetch("/api/v1/team/invite",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s.email,role:s.role})});if(!a.ok)throw new Error(`Server error: ${a.status}`);const h=ge.parse(await a.json()),c=`${location.origin}/invite?token=${h.token}`;f(c),navigator.clipboard.writeText(c).catch(()=>{}),h.emailSent?j.success(`Invite email sent to ${s.email}`):j.warning("Invite link copied — email could not be sent. Check your SMTP settings.")}catch{j.error("Failed to create invite link")}}function F(s){b(s),s||(f(""),P())}async function M(s,a){await fetch(`/api/v1/team/members/${s}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({role:a})}),m()}async function Q(s){const c=(await(await fetch(`/api/v1/team/members/${s}/send-reset`,{method:"POST",credentials:"include"})).json()).emailSent?"Sent":"No SMTP";p(x=>({...x,[s]:c})),setTimeout(()=>p(x=>{const C={...x};return delete C[s],C}),3e3)}async function B(s){await fetch(`/api/v1/team/members/${s}`,{method:"DELETE",credentials:"include"}),d(null),m()}return e.jsxs("div",{className:"flex flex-col gap-6 max-w-[900px] mx-auto w-full p-6",children:[e.jsx(ne,{open:o!==null,onOpenChange:s=>{s||d(null)},children:e.jsxs(te,{children:[e.jsxs(le,{children:[e.jsx(re,{children:"Remove this member?"}),e.jsx(ce,{children:"This member will lose access to the team immediately."})]}),e.jsxs(oe,{children:[e.jsx(de,{children:"Cancel"}),e.jsx(me,{className:"bg-destructive/10 text-destructive hover:bg-destructive/20 border-0",onClick:()=>o!==null&&B(o),children:"Remove"})]})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Team"}),e.jsxs(Z,{open:O,onOpenChange:F,children:[e.jsx(ee,{asChild:!0,children:e.jsxs(t,{size:"sm",children:[e.jsx(ve,{className:"mr-2 h-4 w-4"}),"Invite member"]})}),e.jsxs(se,{className:"sm:max-w-md",children:[e.jsx(ae,{children:e.jsx(ie,{children:"Invite team member"})}),g?e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Invite link copied to clipboard:"}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all",children:g}),e.jsx(t,{onClick:()=>b(!1),children:"Done"})]}):e.jsxs("form",{onSubmit:H($),className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(D,{htmlFor:"invite-email",children:"Email"}),e.jsx(G,{id:"invite-email",type:"email",...V("email")}),S.email&&e.jsx("p",{className:"text-sm text-destructive",children:S.email.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(D,{htmlFor:"invite-role",children:"Role"}),e.jsx(q,{name:"role",control:L,render:({field:s})=>e.jsxs(N,{value:s.value,onValueChange:s.onChange,children:[e.jsx(w,{id:"invite-role",children:e.jsx(T,{})}),e.jsxs(k,{children:[e.jsx(i,{value:"Admin",children:"Admin"}),e.jsx(i,{value:"Developer",children:"Developer"}),e.jsx(i,{value:"QA",children:"QA"}),e.jsx(i,{value:"Viewer",children:"Viewer"})]})]})})]}),e.jsx(t,{type:"submit",disabled:y,children:y?"Creating link…":"Generate invite link"})]})]})]})]}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsxs(K,{children:["Members (",v.length,")"]})}),e.jsx(X,{className:"px-4 pt-0 pb-2",children:e.jsxs(he,{children:[e.jsx(xe,{children:e.jsxs(A,{children:[e.jsx(l,{children:"Nickname"}),e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Role"}),e.jsx(l,{children:"Joined"}),e.jsx(l,{className:"w-10"})]})}),e.jsx(je,{children:v.map(s=>e.jsxs(A,{className:"hover:bg-transparent",children:[e.jsx(r,{className:"font-medium",children:s.display_name||"—"}),e.jsx(r,{className:"text-muted-foreground text-sm",children:s.email}),e.jsx(r,{children:e.jsxs(N,{value:s.role,onValueChange:a=>M(s.id,a),children:[e.jsx(w,{className:"h-7 w-28",children:e.jsx(T,{})}),e.jsxs(k,{children:[e.jsx(i,{value:"Admin",children:"Admin"}),e.jsx(i,{value:"Developer",children:"Developer"}),e.jsx(i,{value:"QA",children:"QA"}),e.jsx(i,{value:"Viewer",children:"Viewer"})]})]})}),e.jsx(r,{className:"text-muted-foreground text-sm",children:new Date(s.joined_at).toLocaleDateString()}),e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t,{variant:"secondary",size:"nav",onClick:()=>Q(s.id),children:E[s.id]??"Reset pwd"}),e.jsx(t,{variant:"destructive",size:"nav",onClick:()=>d(s.id),children:"Remove"})]})})]},s.id))})]})})]})]})}export{Ne as TeamSettings};
@@ -0,0 +1 @@
1
+ import{i as n,j as e}from"./vendor-react-AJpf4YZ0.js";import{ad as $,a5 as H,B as d,a4 as t,L as k,I as S,C as O,c as z,d as V,b as W,a as M,a2 as J,a3 as A}from"./index-9vdYIm7s.js";import{B as I}from"./badge-B6Nf3A0Y.js";import{A as U,c as q,f as G,g as K,d as Q,e as X,b as Y}from"./alert-dialog-CgatMXjB.js";import{D as Z,f as ee,a as se,d as te,e as ae,S as ne,i as re,j as oe,g as ie,h as B}from"./dialog-DK9a3b4z.js";import{T as le,d as ce,e as w,c as x,a as de,b as i}from"./table-DW57-o1p.js";import{P as xe,T as he}from"./trash-2-CGxISX8x.js";import"./vendor-router-ChFy8CZ1.js";async function me(){const a=window.location.protocol==="https:"?"wss":"ws";if(["localhost","127.0.0.1","[::1]"].includes(window.location.hostname))try{const h=await fetch("/api/v1/relay/host",{credentials:"include"});if(h.ok){const{lanHost:l,port:o}=await h.json();if(l)return`${a}://${l}:${o}`}}catch{}return`${a}://${window.location.host}`}const pe=J({name:A().min(1),expiresDays:A().refine(a=>{const r=parseInt(a,10);return!isNaN(r)&&r>=1&&r<=365},{message:"Must be between 1 and 365"})});function Ne(){const[a,r]=n.useState([]),[h,l]=n.useState(!1),[o,y]=n.useState(""),[c,v]=n.useState("api"),[N,b]=n.useState(""),[u,j]=n.useState(null),{register:T,handleSubmit:E,reset:_,formState:{errors:m,isSubmitting:C}}=$({resolver:H(pe),mode:"onBlur",defaultValues:{name:"",expiresDays:"30"}});function g(){fetch("/api/v1/tokens",{credentials:"include"}).then(s=>s.json()).then(r)}n.useEffect(()=>{g()},[]);async function F(s){try{const p=await fetch("/api/v1/tokens",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,expires_in_days:parseInt(s.expiresDays,10),...c==="agent"?{scope:"agent"}:{}})});if(!p.ok){const f=await p.json().catch(()=>null);t.error((f==null?void 0:f.error)??"Failed to create token");return}const P=await p.json();c==="agent"&&b(await me()),t.success("Token created"),y(P.token),g()}catch{t.error("Network error")}}function R(s){l(s),s||(y(""),v("api"),b(""),_())}async function L(s){try{return(await fetch(`/api/v1/tokens/${s}`,{method:"DELETE",credentials:"include"})).ok?(t.success("Token revoked"),g(),!0):(t.error("Failed to revoke token"),!1)}catch{return t.error("Network error"),!1}}function D(s){return s.expires_at&&new Date(s.expires_at)<new Date}return e.jsxs("div",{className:"flex flex-col gap-6 max-w-[900px] mx-auto w-full p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Personal Access Tokens"}),e.jsxs(Z,{open:h,onOpenChange:R,children:[e.jsx(ee,{asChild:!0,children:e.jsxs(d,{size:"sm",children:[e.jsx(xe,{className:"mr-2 h-4 w-4"}),"New token"]})}),e.jsxs(se,{className:"sm:max-w-md",children:[e.jsx(te,{children:e.jsx(ae,{children:"Create token"})}),o?e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Copy this token now — it won't be shown again."}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all font-mono",children:o}),c==="agent"&&N&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this on the agent Mac to connect it to this relay:"}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all font-mono",children:`tapflow agent start --relay ${N} --token ${o}`})]}),e.jsx(d,{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{t.success("Token copied to clipboard"),l(!1)}).catch(()=>t.error("Failed to copy — copy manually"))},children:"Copy & close"})]}):e.jsxs("form",{onSubmit:E(F),className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"token-name",children:"Name"}),e.jsx(S,{id:"token-name",placeholder:"e.g. ci-deploy",...T("name")}),m.name&&e.jsx("p",{className:"text-sm text-destructive",children:m.name.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"expires",children:"Expires in (days)"}),e.jsx(S,{id:"expires",type:"number",...T("expiresDays")}),m.expiresDays&&e.jsx("p",{className:"text-sm text-destructive",children:m.expiresDays.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"token-type",children:"Type"}),e.jsxs(ne,{value:c,onValueChange:s=>v(s),children:[e.jsx(re,{id:"token-type",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(B,{value:"api",children:"API — CI uploads & API access"}),e.jsx(B,{value:"agent",children:"Agent — connect remote device agents (Admin only)"})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Scope: ",e.jsx(I,{variant:"secondary",children:c==="agent"?"agent":"view, builds:write"})]}),e.jsx(d,{type:"submit",disabled:C,children:C?"Creating…":"Create token"})]})]})]})]}),e.jsxs(O,{children:[e.jsxs(z,{children:[e.jsx(V,{children:"Active tokens"}),e.jsxs(W,{children:["Use these tokens with ",e.jsx("code",{className:"text-xs",children:"Authorization: Bearer <token>"})," for API deployments."]})]}),e.jsx(M,{className:"px-4 pt-0 pb-2",children:e.jsxs(le,{children:[e.jsx(ce,{children:e.jsxs(w,{children:[e.jsx(x,{children:"Name"}),e.jsx(x,{children:"Scope"}),e.jsx(x,{children:"Last used"}),e.jsx(x,{children:"Expires"}),e.jsx(x,{className:"w-10"})]})}),e.jsx(de,{children:a.length===0?e.jsx(w,{children:e.jsx(i,{colSpan:5,className:"h-20 text-center text-muted-foreground",children:"No tokens yet."})}):a.map(s=>e.jsxs(w,{className:"hover:bg-transparent",children:[e.jsx(i,{className:"font-medium",children:s.name}),e.jsx(i,{children:e.jsx(I,{variant:"secondary",children:s.scope})}),e.jsx(i,{className:"text-muted-foreground text-sm",children:s.last_used_at?new Date(s.last_used_at).toLocaleDateString():"Never"}),e.jsx(i,{children:s.expires_at?e.jsx("span",{className:D(s)?"text-destructive text-sm":"text-muted-foreground text-sm",children:D(s)?"Expired":new Date(s.expires_at).toLocaleDateString()}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"Never"})}),e.jsx(i,{children:e.jsx(d,{variant:"destructive",size:"icon",className:"h-7 w-7","aria-label":"Revoke token",onClick:()=>j(s.id),children:e.jsx(he,{className:"h-4 w-4"})})})]},s.id))})]})})]}),e.jsx(U,{open:u!==null,onOpenChange:s=>{s||j(null)},children:e.jsxs(q,{children:[e.jsxs(G,{children:[e.jsx(K,{children:"Revoke token?"}),e.jsx(Q,{children:"Any active API calls using this token will immediately fail."})]}),e.jsxs(X,{children:[e.jsx(Y,{children:"Cancel"}),e.jsx(d,{variant:"destructive",onClick:async()=>{if(u===null)return;await L(u)&&j(null)},children:"Revoke"})]})]})})]})}export{Ne as TokenSettings};
@@ -0,0 +1 @@
1
+ import{i as r,j as o}from"./vendor-react-AJpf4YZ0.js";import{m as O,a9 as u,j as T,K as S,n as b,k as $,i as m,Q as v,l as E,O as h,D as z,o as F,J as g,H as x}from"./index-9vdYIm7s.js";var H=Object.defineProperty,n=(t,e)=>H(t,"name",{value:e,configurable:!0}),k="AlertDialog",[M,pe]=h(k,[v]),c=v(),I=n(t=>{const{__scopeAlertDialog:e,...a}=t,l=c(e);return o.jsx(z,{...l,...a,modal:!0})},"AlertDialog"),J=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,s=c(l);return o.jsx(F,{...s,...i,ref:a})},"AlertDialogTrigger")),K=n(t=>{const{__scopeAlertDialog:e,...a}=t,l=c(e);return o.jsx(O,{...l,...a})},"AlertDialogPortal"),L=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,s=c(l);return o.jsx(E,{...s,...i,ref:a})},"AlertDialogOverlay")),Q="AlertDialogContent",[V,q]=M(Q),B=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,children:i,...s}=e,p=c(l),f=r.useRef(null),P=u(a,f),D=r.useRef(null);return o.jsx(V,{scope:l,cancelRef:D,children:o.jsx(T,{role:"alertdialog",...p,...s,ref:P,onOpenAutoFocus:S(s.onOpenAutoFocus,d=>{var A;d.preventDefault(),(A=D.current)==null||A.focus({preventScroll:!0})}),onPointerDownOutside:d=>d.preventDefault(),onInteractOutside:d=>d.preventDefault(),children:i})})},"AlertDialogContent")),G=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,s=c(l);return o.jsx(b,{...s,...i,ref:a})},"AlertDialogTitle")),U=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,s=c(l);return o.jsx($,{...s,...i,ref:a})},"AlertDialogDescription")),W=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,s=c(l);return o.jsx(m,{...s,...i,ref:a})},"AlertDialogAction")),X="AlertDialogCancel",Y=r.forwardRef(n(function(e,a){const{__scopeAlertDialog:l,...i}=e,{cancelRef:s}=q(X,l),p=c(l),f=u(a,s);return o.jsx(m,{...p,...i,ref:f})},"AlertDialogCancel")),Z=I,ee=J,ae=K,N=L,j=B,y=W,_=Y,C=G,R=U;const fe=Z,De=ee,te=ae,w=r.forwardRef(({className:t,...e},a)=>o.jsx(N,{className:g("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e,ref:a}));w.displayName=N.displayName;const oe=r.forwardRef(({className:t,...e},a)=>o.jsxs(te,{children:[o.jsx(w,{}),o.jsx(j,{ref:a,className:g("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...e})]}));oe.displayName=j.displayName;const le=({className:t,...e})=>o.jsx("div",{className:g("flex flex-col space-y-2 text-center sm:text-left",t),...e});le.displayName="AlertDialogHeader";const re=({className:t,...e})=>o.jsx("div",{className:g("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...e});re.displayName="AlertDialogFooter";const se=r.forwardRef(({className:t,...e},a)=>o.jsx(C,{ref:a,className:g("text-lg font-semibold",t),...e}));se.displayName=C.displayName;const ie=r.forwardRef(({className:t,...e},a)=>o.jsx(R,{ref:a,className:g("text-sm text-muted-foreground",t),...e}));ie.displayName=R.displayName;const ne=r.forwardRef(({className:t,...e},a)=>o.jsx(y,{ref:a,className:g(x(),t),...e}));ne.displayName=y.displayName;const ce=r.forwardRef(({className:t,...e},a)=>o.jsx(_,{ref:a,className:g(x({variant:"outline"}),"mt-2 sm:mt-0",t),...e}));ce.displayName=_.displayName;export{fe as A,ne as a,ce as b,oe as c,ie as d,re as e,le as f,se as g,De as h};
@@ -0,0 +1 @@
1
+ import{j as n}from"./vendor-react-AJpf4YZ0.js";import{J as d,a0 as o}from"./index-9vdYIm7s.js";const s=o("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"},tone:{backlog:"border-transparent bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400",progress:"border-transparent bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300",done:"border-transparent bg-green-50 text-green-700 dark:bg-green-950 dark:text-green-300",rejected:"border-transparent bg-red-50 text-red-700 dark:bg-red-950 dark:text-red-300",ios:"border-transparent bg-sky-50 text-sky-700 dark:bg-sky-950 dark:text-sky-300",android:"border-transparent bg-emerald-50 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300"}},defaultVariants:{variant:"default"}});function g({className:r,variant:e,tone:t,...a}){return n.jsx("div",{className:d(s({variant:e,tone:t}),r),...a})}export{g as B};