@tapflowio/relay 0.21.0 → 0.22.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 (138) hide show
  1. package/dist/RelayServer.d.ts +2 -0
  2. package/dist/RelayServer.d.ts.map +1 -1
  3. package/dist/RelayServer.js +14 -4
  4. package/dist/RelayServer.js.map +1 -1
  5. package/dist/api/team.d.ts +2 -1
  6. package/dist/api/team.d.ts.map +1 -1
  7. package/dist/api/team.js +7 -5
  8. package/dist/api/team.js.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/lib/lanAddress.d.ts +10 -0
  13. package/dist/lib/lanAddress.d.ts.map +1 -1
  14. package/dist/lib/lanAddress.js +13 -0
  15. package/dist/lib/lanAddress.js.map +1 -1
  16. package/dist/lib/proxyConfig.d.ts +4 -2
  17. package/dist/lib/proxyConfig.d.ts.map +1 -1
  18. package/dist/lib/proxyConfig.js +22 -13
  19. package/dist/lib/proxyConfig.js.map +1 -1
  20. package/dist/lib/publicUrl.d.ts +31 -1
  21. package/dist/lib/publicUrl.d.ts.map +1 -1
  22. package/dist/lib/publicUrl.js +51 -9
  23. package/dist/lib/publicUrl.js.map +1 -1
  24. package/dist/server.js +7 -1
  25. package/dist/server.js.map +1 -1
  26. package/package.json +3 -3
  27. package/public/assets/{AppCenter-BkSQFKRv.js → AppCenter-gbsJscjW.js} +1 -1
  28. package/public/assets/AppCenter-gbsJscjW.js.br +0 -0
  29. package/public/assets/AppCenter-gbsJscjW.js.gz +0 -0
  30. package/public/assets/{Default-D1inA8sU.js → Default-2rFTkbo9.js} +1 -1
  31. package/public/assets/Default-2rFTkbo9.js.br +0 -0
  32. package/public/assets/Default-2rFTkbo9.js.gz +0 -0
  33. package/public/assets/{Invite-ChaVEWvP.js → Invite-aN4DXJyM.js} +1 -1
  34. package/public/assets/Invite-aN4DXJyM.js.br +0 -0
  35. package/public/assets/Invite-aN4DXJyM.js.gz +0 -0
  36. package/public/assets/MacResources-D3IlesXU.js +3 -0
  37. package/public/assets/MacResources-D3IlesXU.js.br +0 -0
  38. package/public/assets/MacResources-D3IlesXU.js.gz +0 -0
  39. package/public/assets/{QASession-DICynZa0.js → QASession-U29t9j0E.js} +26 -26
  40. package/public/assets/QASession-U29t9j0E.js.br +0 -0
  41. package/public/assets/QASession-U29t9j0E.js.gz +0 -0
  42. package/public/assets/{ResetPassword-Ut9BFums.js → ResetPassword-DPc5kwQU.js} +1 -1
  43. package/public/assets/ResetPassword-DPc5kwQU.js.br +0 -0
  44. package/public/assets/ResetPassword-DPc5kwQU.js.gz +0 -0
  45. package/public/assets/{Setup-CoHwaxo7.js → Setup-CwPx_e_O.js} +1 -1
  46. package/public/assets/Setup-CwPx_e_O.js.br +0 -0
  47. package/public/assets/Setup-CwPx_e_O.js.gz +0 -0
  48. package/public/assets/Team-DD9li-7M.js +6 -0
  49. package/public/assets/Team-DD9li-7M.js.br +0 -0
  50. package/public/assets/Team-DD9li-7M.js.gz +0 -0
  51. package/public/assets/Tokens-DdMMke73.js +1 -0
  52. package/public/assets/Tokens-DdMMke73.js.br +0 -0
  53. package/public/assets/Tokens-DdMMke73.js.gz +0 -0
  54. package/public/assets/{alert-dialog-Cc_pQpe6.js → alert-dialog-DADd1jHN.js} +1 -1
  55. package/public/assets/alert-dialog-DADd1jHN.js.br +0 -0
  56. package/public/assets/alert-dialog-DADd1jHN.js.gz +0 -0
  57. package/public/assets/{badge-CikXk90N.js → badge-CMf8d5RJ.js} +1 -1
  58. package/public/assets/badge-CMf8d5RJ.js.br +0 -0
  59. package/public/assets/badge-CMf8d5RJ.js.gz +0 -0
  60. package/public/assets/{build-format-DsApFPHy.js → build-format-lp_8kSvq.js} +1 -1
  61. package/public/assets/build-format-lp_8kSvq.js.br +0 -0
  62. package/public/assets/build-format-lp_8kSvq.js.gz +0 -0
  63. package/public/assets/{dialog-B4Wg7TCg.js → dialog-pS8vHXXv.js} +1 -1
  64. package/public/assets/dialog-pS8vHXXv.js.br +0 -0
  65. package/public/assets/dialog-pS8vHXXv.js.gz +0 -0
  66. package/public/assets/index-Bxs7CdEi.css +1 -0
  67. package/public/assets/index-Bxs7CdEi.css.br +0 -0
  68. package/public/assets/index-Bxs7CdEi.css.gz +0 -0
  69. package/public/assets/{index-CBfjqtE-.js → index-Cajf0T-5.js} +2 -2
  70. package/public/assets/index-Cajf0T-5.js.br +0 -0
  71. package/public/assets/index-Cajf0T-5.js.gz +0 -0
  72. package/public/assets/{pencil-DMswV31e.js → pencil-LD1ga-Kk.js} +1 -1
  73. package/public/assets/pencil-LD1ga-Kk.js.br +0 -0
  74. package/public/assets/pencil-LD1ga-Kk.js.gz +0 -0
  75. package/public/assets/publicLink-D6zKS_wu.js +1 -0
  76. package/public/assets/publicLink-D6zKS_wu.js.br +0 -0
  77. package/public/assets/publicLink-D6zKS_wu.js.gz +0 -0
  78. package/public/assets/resource-health-BScurILF.js +1 -0
  79. package/public/assets/resource-health-BScurILF.js.br +0 -0
  80. package/public/assets/resource-health-BScurILF.js.gz +0 -0
  81. package/public/assets/{table-dbLmBL_w.js → table-CL9AvoTp.js} +1 -1
  82. package/public/assets/table-CL9AvoTp.js.br +0 -0
  83. package/public/assets/table-CL9AvoTp.js.gz +0 -0
  84. package/public/assets/{trash-VgeHmI8N.js → trash-mvVp4nwq.js} +1 -1
  85. package/public/assets/trash-mvVp4nwq.js.br +0 -0
  86. package/public/assets/trash-mvVp4nwq.js.gz +0 -0
  87. package/public/assets/vendor-charts-8kVeHLwY.js +5 -0
  88. package/public/assets/vendor-charts-8kVeHLwY.js.br +0 -0
  89. package/public/assets/vendor-charts-8kVeHLwY.js.gz +0 -0
  90. package/public/index.html +2 -2
  91. package/public/index.html.br +0 -0
  92. package/public/index.html.gz +0 -0
  93. package/public/assets/AppCenter-BkSQFKRv.js.br +0 -0
  94. package/public/assets/AppCenter-BkSQFKRv.js.gz +0 -0
  95. package/public/assets/Default-D1inA8sU.js.br +0 -0
  96. package/public/assets/Default-D1inA8sU.js.gz +0 -0
  97. package/public/assets/Invite-ChaVEWvP.js.br +0 -0
  98. package/public/assets/Invite-ChaVEWvP.js.gz +0 -0
  99. package/public/assets/MacResources-CLChFyJW.js +0 -1
  100. package/public/assets/MacResources-CLChFyJW.js.br +0 -0
  101. package/public/assets/MacResources-CLChFyJW.js.gz +0 -0
  102. package/public/assets/QASession-DICynZa0.js.br +0 -0
  103. package/public/assets/QASession-DICynZa0.js.gz +0 -0
  104. package/public/assets/ResetPassword-Ut9BFums.js.br +0 -0
  105. package/public/assets/ResetPassword-Ut9BFums.js.gz +0 -0
  106. package/public/assets/Setup-CoHwaxo7.js.br +0 -0
  107. package/public/assets/Setup-CoHwaxo7.js.gz +0 -0
  108. package/public/assets/Team-DaVY1DGm.js +0 -6
  109. package/public/assets/Team-DaVY1DGm.js.br +0 -0
  110. package/public/assets/Team-DaVY1DGm.js.gz +0 -0
  111. package/public/assets/Tokens-_KZJ7AZ9.js +0 -1
  112. package/public/assets/Tokens-_KZJ7AZ9.js.br +0 -0
  113. package/public/assets/Tokens-_KZJ7AZ9.js.gz +0 -0
  114. package/public/assets/alert-dialog-Cc_pQpe6.js.br +0 -0
  115. package/public/assets/alert-dialog-Cc_pQpe6.js.gz +0 -0
  116. package/public/assets/badge-CikXk90N.js.br +0 -0
  117. package/public/assets/badge-CikXk90N.js.gz +0 -0
  118. package/public/assets/build-format-DsApFPHy.js.br +0 -0
  119. package/public/assets/build-format-DsApFPHy.js.gz +0 -0
  120. package/public/assets/dialog-B4Wg7TCg.js.br +0 -0
  121. package/public/assets/dialog-B4Wg7TCg.js.gz +0 -0
  122. package/public/assets/index-CBfjqtE-.js.br +0 -0
  123. package/public/assets/index-CBfjqtE-.js.gz +0 -0
  124. package/public/assets/index-ClHUQm-F.css +0 -1
  125. package/public/assets/index-ClHUQm-F.css.br +0 -0
  126. package/public/assets/index-ClHUQm-F.css.gz +0 -0
  127. package/public/assets/pencil-DMswV31e.js.br +0 -0
  128. package/public/assets/pencil-DMswV31e.js.gz +0 -0
  129. package/public/assets/table-dbLmBL_w.js.br +0 -0
  130. package/public/assets/table-dbLmBL_w.js.gz +0 -0
  131. package/public/assets/tabs-pPYCRfmT.js +0 -1
  132. package/public/assets/tabs-pPYCRfmT.js.br +0 -0
  133. package/public/assets/tabs-pPYCRfmT.js.gz +0 -0
  134. package/public/assets/trash-VgeHmI8N.js.br +0 -0
  135. package/public/assets/trash-VgeHmI8N.js.gz +0 -0
  136. package/public/assets/vendor-charts-DyX5CBcf.js +0 -5
  137. package/public/assets/vendor-charts-DyX5CBcf.js.br +0 -0
  138. package/public/assets/vendor-charts-DyX5CBcf.js.gz +0 -0
@@ -1,128 +1,128 @@
1
- import{i as s,j as n}from"./vendor-react-AJpf4YZ0.js";import{W as ne,J as te,y as Vt,T as Ce,z as Te,B as ie,x as Ee,S as Cn,a4 as Ne,r as mr,s as Mt,K as Ke,a9 as tt,t as nt,O as Tn,a8 as ht,af as gr,ab as xr,U as br,w as yr,f as vr,ag as wr,aa as Sr,a7 as Rr,L as kr}from"./index-CBfjqtE-.js";import{f as jr,a as Cr,P as En,c as ln,S as Tr,b as Er}from"./build-format-DsApFPHy.js";import{u as Nn,n as X,T as Nr,b as Ar,c as un,a as dn}from"./tabs-pPYCRfmT.js";import{c as An,b as _r}from"./vendor-router-BFibuab1.js";import{A as Pr,c as Dr,f as Lr,g as Ir,d as Mr,e as Ur,b as $r,a as Br}from"./alert-dialog-Cc_pQpe6.js";import{D as _n,a as Pn,d as Fr,e as Dn,b as Or,c as Hr,k as zr,S as Wr,i as Vr,j as qr,g as Xr,h as fn}from"./dialog-B4Wg7TCg.js";import{B as Kr}from"./badge-CikXk90N.js";/**
1
+ import{i as s,j as n}from"./vendor-react-AJpf4YZ0.js";import{W as ne,J as te,y as Vt,T as Ce,z as Te,B as ie,x as Ee,S as jn,a4 as Ne,r as pr,s as Mt,K as Ke,a9 as tt,t as nt,O as Cn,a8 as ht,af as mr,ab as gr,U as xr,w as br,f as yr,ag as vr,aa as wr,a7 as Sr,L as Rr}from"./index-Cajf0T-5.js";import{f as kr,a as jr,P as Tn,c as ln,S as Cr,b as Tr}from"./build-format-lp_8kSvq.js";import{u as En,n as X,T as Er,b as Nr,c as un,a as dn,R as Ar,g as _r}from"./resource-health-BScurILF.js";import{c as Nn,b as Pr}from"./vendor-router-BFibuab1.js";import{A as Dr,c as Lr,f as Ir,g as Mr,d as Ur,e as $r,b as Fr,a as Br}from"./alert-dialog-DADd1jHN.js";import{D as An,a as _n,d as Or,e as Pn,b as Hr,c as zr,k as Wr,S as Vr,i as qr,j as Xr,g as Kr,h as fn}from"./dialog-pS8vHXXv.js";import{l as hn,j as Yr}from"./publicLink-D6zKS_wu.js";import{B as Gr}from"./badge-CMf8d5RJ.js";/**
2
2
  * @license lucide-react v1.41.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 Yr=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Gr=ne("arrow-left",Yr);/**
6
+ */const Jr=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],Qr=ne("arrow-left",Jr);/**
7
7
  * @license lucide-react v1.41.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Jr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Qr=ne("arrow-up",Jr);/**
11
+ */const Zr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],es=ne("arrow-up",Zr);/**
12
12
  * @license lucide-react v1.41.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Zr=[["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"}]],es=ne("camera",Zr);/**
16
+ */const ts=[["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"}]],ns=ne("camera",ts);/**
17
17
  * @license lucide-react v1.41.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const ts=[["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"}]],ns=ne("download",ts);/**
21
+ */const rs=[["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"}]],ss=ne("download",rs);/**
22
22
  * @license lucide-react v1.41.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const rs=[["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"}]],ss=ne("film",rs);/**
26
+ */const os=[["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"}]],as=ne("film",os);/**
27
27
  * @license lucide-react v1.41.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const os=[["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=ne("house",os);/**
31
+ */const is=[["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"}]],Dn=ne("house",is);/**
32
32
  * @license lucide-react v1.41.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const as=[["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"}]],is=ne("image-plus",as);/**
36
+ */const cs=[["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"}]],ls=ne("image-plus",cs);/**
37
37
  * @license lucide-react v1.41.0 - ISC
38
38
  *
39
39
  * This source code is licensed under the ISC license.
40
40
  * See the LICENSE file in the root directory of this source tree.
41
- */const cs=[["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"}]],ls=ne("keyboard",cs);/**
41
+ */const us=[["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"}]],ds=ne("keyboard",us);/**
42
42
  * @license lucide-react v1.41.0 - ISC
43
43
  *
44
44
  * This source code is licensed under the ISC license.
45
45
  * See the LICENSE file in the root directory of this source tree.
46
- */const us=[["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=ne("link-2",us);/**
46
+ */const fs=[["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"}]],Ln=ne("link-2",fs);/**
47
47
  * @license lucide-react v1.41.0 - ISC
48
48
  *
49
49
  * This source code is licensed under the ISC license.
50
50
  * See the LICENSE file in the root directory of this source tree.
51
- */const ds=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],yt=ne("loader-circle",ds);/**
51
+ */const hs=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],yt=ne("loader-circle",hs);/**
52
52
  * @license lucide-react v1.41.0 - ISC
53
53
  *
54
54
  * This source code is licensed under the ISC license.
55
55
  * See the LICENSE file in the root directory of this source tree.
56
- */const fs=[["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"}]],hs=ne("message-square",fs);/**
56
+ */const ps=[["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"}]],ms=ne("message-square",ps);/**
57
57
  * @license lucide-react v1.41.0 - ISC
58
58
  *
59
59
  * This source code is licensed under the ISC license.
60
60
  * See the LICENSE file in the root directory of this source tree.
61
- */const ps=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],ms=ne("power",ps);/**
61
+ */const gs=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],xs=ne("power",gs);/**
62
62
  * @license lucide-react v1.41.0 - ISC
63
63
  *
64
64
  * This source code is licensed under the ISC license.
65
65
  * See the LICENSE file in the root directory of this source tree.
66
- */const gs=[["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"}]],xs=ne("radio-off",gs);/**
66
+ */const bs=[["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"}]],ys=ne("radio-off",bs);/**
67
67
  * @license lucide-react v1.41.0 - ISC
68
68
  *
69
69
  * This source code is licensed under the ISC license.
70
70
  * See the LICENSE file in the root directory of this source tree.
71
- */const bs=[["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"}]],Ot=ne("radio",bs);/**
71
+ */const vs=[["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"}]],Ot=ne("radio",vs);/**
72
72
  * @license lucide-react v1.41.0 - ISC
73
73
  *
74
74
  * This source code is licensed under the ISC license.
75
75
  * See the LICENSE file in the root directory of this source tree.
76
- */const ys=[["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"}]],vs=ne("refresh-cw",ys);/**
76
+ */const ws=[["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"}]],Ss=ne("refresh-cw",ws);/**
77
77
  * @license lucide-react v1.41.0 - ISC
78
78
  *
79
79
  * This source code is licensed under the ISC license.
80
80
  * See the LICENSE file in the root directory of this source tree.
81
- */const ws=[["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"}]],Ss=ne("rotate-cw",ws);/**
81
+ */const Rs=[["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"}]],ks=ne("rotate-cw",Rs);/**
82
82
  * @license lucide-react v1.41.0 - ISC
83
83
  *
84
84
  * This source code is licensed under the ISC license.
85
85
  * See the LICENSE file in the root directory of this source tree.
86
- */const Rs=[["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"}]],ks=ne("scan-line",Rs);/**
86
+ */const js=[["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"}]],Cs=ne("scan-line",js);/**
87
87
  * @license lucide-react v1.41.0 - ISC
88
88
  *
89
89
  * This source code is licensed under the ISC license.
90
90
  * See the LICENSE file in the root directory of this source tree.
91
- */const js=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Cs=ne("square",js);/**
91
+ */const Ts=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Es=ne("square",Ts);/**
92
92
  * @license lucide-react v1.41.0 - ISC
93
93
  *
94
94
  * This source code is licensed under the ISC license.
95
95
  * See the LICENSE file in the root directory of this source tree.
96
- */const Ts=[["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"}]],Es=ne("video",Ts);/**
96
+ */const Ns=[["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"}]],As=ne("video",Ns);/**
97
97
  * @license lucide-react v1.41.0 - ISC
98
98
  *
99
99
  * This source code is licensed under the ISC license.
100
100
  * See the LICENSE file in the root directory of this source tree.
101
- */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"}]],As=ne("volume-1",Ns);/**
101
+ */const _s=[["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"}]],Ps=ne("volume-1",_s);/**
102
102
  * @license lucide-react v1.41.0 - ISC
103
103
  *
104
104
  * This source code is licensed under the ISC license.
105
105
  * See the LICENSE file in the root directory of this source tree.
106
- */const _s=[["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"}]],Ps=ne("volume-2",_s);function Ds(e){const[t,r]=s.useState(null);return s.useEffect(()=>{e&&jr(e).then(r)},[e]),{build:t}}function Ls(e){const[t,r]=s.useState([]),[o,i]=s.useState(null),[a,c]=s.useState(null),[u,d]=s.useState(""),[h,p]=s.useState(!1),[g,x]=s.useState(""),f=s.useCallback(k=>{k.type==="agents:listed"&&r(k.sessions),k.type==="session:joined"&&(p(!1),x("Connected")),k.type==="error"&&(p(!1),x(`Error: ${k.message}`))},[]),{send:b,connected:v}=Nn(f);s.useEffect(()=>{if(!v)return;b({type:"agents:list"});const k=setInterval(()=>b({type:"agents:list"}),5e3);return()=>clearInterval(k)},[v,b]);const T=s.useRef({sessionId:a,deviceId:u});s.useEffect(()=>{T.current={sessionId:a,deviceId:u}},[a,u]),s.useEffect(()=>()=>{const{sessionId:k,deviceId:B}=T.current;k&&B&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:B}})},[b]);const j=t.filter(k=>k.devices.some(B=>B.platform===e)),L=s.useCallback(k=>{d(k.id),p(!0),x("Booting…"),c(k.sessionId)},[]),C=s.useCallback(()=>d(""),[]),N=s.useCallback(()=>{const{sessionId:k,deviceId:B}=T.current;k&&B&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:B}}),c(null),p(!1),x("")},[b]),E=s.useCallback(()=>{const{sessionId:k,deviceId:B}=T.current;k&&B&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:B}}),c(null),i(null),p(!1),x(""),b({type:"agents:list"})},[b]),M=s.useCallback(()=>{c(null),i(null),p(!1),x(""),b({type:"agents:list"})},[b]);return{sessions:t,selectedAgent:o,setSelectedAgent:i,activeSessionId:a,deviceId:u,booting:h,status:g,send:b,connected:v,agentGroups:j,startDevice:L,resetDevice:C,handleBack:N,handleBackToMacs:E,handleSessionEnded:M}}function Is(e,t){const[r,o]=s.useState(""),[i,a]=s.useState(""),[c,u]=s.useState("app-only"),[d,h]=s.useState("app-only"),p=(e==null?void 0:e.capabilities.includes("full-reset"))??!1,g=s.useCallback(()=>{h(p?c:"app-only"),u("app-only")},[c,p]),x=(e==null?void 0:e.devices.filter(v=>v.platform===t))??[],f=[...new Set(x.map(v=>v.osVersion).filter(Boolean))].sort((v,T)=>{const j=N=>N.replace(/^[^\d]*/,"").split(".").map(Number),[L,C]=[j(v),j(T)];for(let N=0;N<Math.max(L.length,C.length);N++){const E=(C[N]??0)-(L[N]??0);if(E!==0)return E}return 0}),b=(r?x.filter(v=>v.osVersion===r):x).filter(v=>!i||v.name.toLowerCase().includes(i.toLowerCase()));return{filteredDevices:x,osVersions:f,osVersion:r,setOsVersion:o,deviceSearch:i,setDeviceSearch:a,versionedDevices:b,resetMode:c,setResetMode:u,appliedResetMode:d,consumeResetMode:g,fullResetSupported:p}}function Ms(){const[e]=An(),t=e.get("perf")==="1",[r,o]=s.useState(t);return s.useEffect(()=>{if(!t){o(!1);return}o(!0);const i=a=>{a.ctrlKey&&a.shiftKey&&a.key==="P"&&o(c=>!c)};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[t]),{perfMode:t,visible:r}}function Mn(e){const t=e.rolloverOffset.x-e.buttonW/2,r=e.anchor==="top"?e.rolloverOffset.y:e.normalOffset.y-e.buttonH/2;return{left:t,top:r,right:t+e.buttonW,bottom:r+e.buttonH}}function Us(e,t,r){const o=Math.max(r.left-e,0,e-r.right),i=Math.max(r.top-t,0,t-r.bottom);return Math.hypot(o,i)}function $s(e,t,r,o){let i=null,a=1/0;for(const c of r){const u=Us(e,t,Mn(c));u<a&&(a=u,i=c.name)}return a<=o?i:null}const Bs=["video/mp4;codecs=avc1","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];function Un({sessionId:e,buildId:t,onRecordingUploaded:r}){const[o,i]=s.useState("idle"),a=s.useRef(null),c=s.useRef(r);s.useEffect(()=>{c.current=r},[r]);const u=s.useRef(!1),d=s.useRef(null),h=s.useRef([]),p=s.useRef(""),g=s.useRef(0),x=s.useRef(null),f=s.useCallback(function T(){var j;u.current&&((j=x.current)==null||j.call(x),g.current=requestAnimationFrame(T))},[]),b=s.useCallback(T=>{const j=a.current;if(!j)return;const L=j.getContext("2d");L&&(L.fillStyle="#000",L.fillRect(0,0,j.width,j.height));const C=Bs.find(E=>MediaRecorder.isTypeSupported(E))??"";if(!C)return;p.current=C,h.current=[];const N=new MediaRecorder(j.captureStream(30),{mimeType:C});N.ondataavailable=E=>{E.data.size>0&&h.current.push(E.data)},d.current=N,N.start(1e3),x.current=T,u.current=!0,g.current=requestAnimationFrame(f),i("recording")},[f]),v=s.useCallback(async()=>{var E;i("uploading"),u.current=!1,cancelAnimationFrame(g.current);const T=d.current;if(!T){i("idle");return}await new Promise(M=>{const k=setTimeout(M,5e3);T.onstop=()=>{clearTimeout(k),M()};try{T.stop()}catch{clearTimeout(k),M()}}),d.current=null;const j=p.current,L=j.includes("mp4")?".mp4":".webm",C=new Blob(h.current,{type:j});h.current=[];const N=new FormData;N.append("file",C,`tapflow-${Date.now()}${L}`);try{const M=new URLSearchParams({sessionId:e});t&&M.set("buildId",String(t));const k=await fetch(`/api/v1/recordings/upload?${M}`,{method:"POST",credentials:"include",body:N}),B=await k.json();if(k.ok&&B.url){const G=document.createElement("a");G.href=B.url,G.download="",G.click(),(E=c.current)==null||E.call(c),i("done"),setTimeout(()=>i("idle"),2e3)}else i("idle")}catch{i("idle")}},[e,t]);return s.useEffect(()=>{if(o!=="recording")return;const T=()=>{document.visibilityState==="hidden"&&v()};return document.addEventListener("visibilitychange",T),()=>{var j;document.removeEventListener("visibilitychange",T),u.current&&(u.current=!1,cancelAnimationFrame(g.current),(j=d.current)==null||j.stop(),d.current=null)}},[o,v]),{recordState:o,recordCanvasRef:a,startClientRecording:b,stopClientRecording:v}}function $n(){const e=s.useRef(0),[t,r]=s.useState(0);return s.useEffect(()=>{const o=setInterval(()=>{r(e.current),e.current=0},1e3);return()=>clearInterval(o)},[]),{fps:t,frameCount:e}}function ft({className:e,...t}){return n.jsx("kbd",{"data-slot":"kbd",className:te("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",e),...t})}function qt({className:e,...t}){return n.jsx("kbd",{"data-slot":"kbd-group",className:te("inline-flex items-center gap-1",e),...t})}function St({label:e,keys:t}){return n.jsxs("span",{className:"flex items-center gap-3",children:[e,n.jsx(qt,{children:t.map(r=>n.jsx(ft,{children:r},r))})]})}const hn="text-muted-foreground hover:text-muted-foreground",pn="text-destructive hover:text-destructive";function Fs(e){switch(e){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 Os({position:e,steerable:t,reason:r}){const o=r==="awaiting-app",i=!t&&r==="state-unconfirmed"?" animate-pulse":"",a=t?"":Fs(r);switch(e){case"offline":return{Icon:xs,className:(t||o?"text-amber-500 hover:text-amber-500":pn)+i,status:`Device is offline.${a}`};case"online":return{Icon:Ot,className:(t||o?"":pn)+i,status:`Device is on the network.${a}`};case"waiting":return{Icon:Ot,className:`${hn} animate-pulse`,status:"Checking the network state."};case"unknown":return{Icon:Ot,className:hn,status:"No network state has been reported."}}}function Hs({position:e,steerable:t,reason:r}){const o=e==="offline"?"Bring device online":e==="online"?"Take device offline":"Toggle device network",i=e==="online"||e==="offline",a=r==="state-unconfirmed"||r==="unsupported-device";return t||!i||r==="awaiting-app"?o:a?`Retry: ${o.toLowerCase()}`:`${o} — unavailable`}function Bn({joined:e,onScreenshot:t,onRecordToggle:r,recordState:o,onRotate:i,onDeepLink:a,navigationSlot:c,deviceSlot:u,launchSlot:d,network:h,reboot:p}){const g=s.useId(),x=s.useId(),f=s.useId(),[b,v]=s.useState(!1);return e?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,c,n.jsxs(Ce,{children:[n.jsx(Te,{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(Ee,{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:[u,n.jsxs(Ce,{children:[n.jsx(Te,{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(Ss,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsx(St,{label:"Rotate",keys:["⌘","⇧","O"]})})]}),p&&(()=>{const T=p.pending?"Restarting the device":"Restart the device";return n.jsxs(n.Fragment,{children:[n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{ref:p.buttonRef,variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":T,"aria-busy":p.pending,"aria-disabled":p.pending,"aria-describedby":x,onClick:()=>{p.pending||v(!0)},children:p.pending?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(vs,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:T})]}),n.jsx("span",{id:x,role:"status",className:"sr-only",children:p.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(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Take a screenshot",onClick:t,children:n.jsx(es,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsx(St,{label:"Screenshot",keys:["⌘","S"]})})]}),n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:te("h-8 w-8 aria-disabled:opacity-50",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","aria-busy":o==="uploading","aria-disabled":o==="uploading"||o==="done","aria-describedby":f,onClick:()=>{(o==="idle"||o==="recording")&&r()},children:o==="uploading"?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):o==="recording"?n.jsx(Cs,{className:"h-4 w-4 fill-current"}):n.jsx(Es,{className:"h-4 w-4"})})}),n.jsx(Ee,{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 the recording"})]}),n.jsx("span",{id:f,role:"status",className:"sr-only",children:o==="recording"?"Recording.":o==="uploading"?"Processing the recording.":o==="done"?"Recording saved.":""})]}),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:T,className:j,status:L}=Os(h),C=Hs(h),N=h.position==="waiting"||h.position==="unknown"||!h.steerable;return n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:te("h-8 w-8",j),"aria-label":C,"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(T,{className:"h-4 w-4"})})}),n.jsx("span",{id:g,role:"status",className:"sr-only",children:h.pending?"Changing the network state.":L}),n.jsx(Ee,{side:"left",children:N?`${C} — ${L}`:C})]})})()})]})]}),p&&n.jsx(Pr,{open:b,onOpenChange:v,children:n.jsxs(Dr,{children:[n.jsxs(Lr,{children:[n.jsx(Ir,{children:"Restart this device?"}),n.jsx(Mr,{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(Ur,{children:[n.jsx($r,{children:"Cancel"}),n.jsx(Br,{onClick:()=>{v(!1),p.onReboot()},children:"Restart"})]})]})})]}):null}const zs=3e3,Ws=8e3;function Fn({sessionId:e,send:t,supported:r,deviceReady:o,handlerRef:i,onError:a}){const[c,u]=s.useState("waiting"),[d,h]=s.useState(!0),[p,g]=s.useState(void 0),x=s.useRef(void 0),[f,b]=s.useState(!1),v=s.useRef(null),T=s.useRef(new Set),j=s.useRef(a);s.useEffect(()=>{j.current=a},[a]);const L=s.useRef(o);s.useEffect(()=>{L.current=o},[o]);const C=s.useRef(o);s.useEffect(()=>{u("waiting"),h(!0),g(void 0),x.current=void 0,b(!1),v.current=null,C.current=L.current,T.current.clear()},[e]),s.useEffect(()=>{var k;if(o){C.current=!0,u("waiting");return}u(C.current?"unknown":"waiting"),h(!0),g(void 0),x.current=void 0,v.current&&((k=j.current)==null||k.call(j,"The device became unavailable before it answered. Its network state is unchanged as far as tapflow can tell."),T.current.add(v.current)),b(!1),v.current=null},[o]),s.useEffect(()=>{if(r)return i.current=k=>{var G,z;if(k.type==="network:error"){k.requestId===v.current&&(v.current=null,b(!1),(G=j.current)==null||G.call(j,k.message));return}if(k.type!=="network:state"||!L.current||k.requestId!==void 0&&T.current.has(k.requestId))return;const B=k.payload.available?void 0:k.payload.reason;u(k.payload.offline?"offline":"online"),h(k.payload.available),g(B),B==="enforcement-lost"&&x.current!=="enforcement-lost"&&((z=j.current)==null||z.call(j,"The device went back on the network before you took it off. Anything checked while it was offline needs checking again.")),x.current=B,k.requestId!==void 0&&k.requestId===v.current&&(v.current=null,b(!1))},()=>{i.current=void 0}},[i,r]),s.useEffect(()=>{if(!r||!o||c!=="waiting")return;const k=setTimeout(()=>u(B=>B==="waiting"?"unknown":B),zs);return()=>clearTimeout(k)},[r,o,c]);const N=s.useCallback(()=>{if(!r||f)return;const k=X();v.current=k,b(!0),t({type:"network:set",sessionId:e,requestId:k,payload:{offline:c!=="offline"}})},[c,f,t,e,r]),[E,M]=s.useState(null);return s.useEffect(()=>{M(f?v.current:null)},[f]),s.useEffect(()=>{if(E===null)return;const k=setTimeout(()=>{var B;v.current===E&&(v.current=null,b(!1),(B=j.current)==null||B.call(j,"The device did not answer. Its network state is unchanged as far as tapflow can tell."))},Ws);return()=>clearTimeout(k)},[E]),{position:c,steerable:d,reason:p,pending:f,toggle:N}}class Xt{constructor(t){this.bytes=t,this.bitPos=0}get position(){return this.bitPos}bit(){const t=this.bitPos>>3,r=7-(this.bitPos&7);return this.bitPos++,t>=this.bytes.length?0:this.bytes[t]>>r&1}bits(t){let r=0;for(let o=0;o<t;o++)r=r<<1|this.bit();return r>>>0}flag(){return this.bit()===1}ue(){let t=0;for(;this.bit()===0&&t<32;)t++;return t===0?0:(1<<t)-1+this.bits(t)}se(){const t=this.ue();return t&1?Math.ceil(t/2):-Math.ceil(t/2)}}class Vs{constructor(){this.bitsArr=[]}bit(t){this.bitsArr.push(t&1)}ue(t){const r=t+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 t=[];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);t.push(o)}return new Uint8Array(t)}}function On(e){const t=[];let r=0;for(let o=1;o<e.length;o++){const i=e[o];if(r>=2&&i===3){r=0;continue}t.push(i),r=i===0?r+1:0}return new Uint8Array(t)}function qs(e){const t=[];let r=0;for(const o of e)r>=2&&o<=3&&(t.push(3),r=0),t.push(o),r=o===0?r+1:0;return new Uint8Array(t)}const Xs=new Set([100,110,122,244,44,83,86,118,128,138,139,134,135]);function mn(e){const t=e.ue()+1;e.bits(4),e.bits(4);for(let r=0;r<t;r++)e.ue(),e.ue(),e.flag();e.bits(5),e.bits(5),e.bits(5),e.bits(5)}function Hn(e){const t=e.bits(8);e.bits(8);const r=e.bits(8);if(e.ue(),Xs.has(t)){const g=e.ue();if(g===3&&e.flag(),e.ue(),e.ue(),e.flag(),e.flag()){const x=g!==3?8:12;for(let f=0;f<x;f++)if(e.flag()){const b=f<6?16:64;let v=8,T=8;for(let j=0;j<b;j++)T!==0&&(T=(v+e.se()+256)%256),v=T===0?v:T}}}e.ue();const o=e.ue();if(o===0)e.ue();else if(o===1){e.flag(),e.se(),e.se();const g=e.ue();for(let x=0;x<g;x++)e.se()}const i=e.ue();e.flag(),e.ue(),e.ue(),e.flag()||e.flag(),e.flag(),e.flag()&&(e.ue(),e.ue(),e.ue(),e.ue());const a={profileIdc:t,levelIdc:r,numRefFrames:i,bitstreamRestriction:!1,maxNumReorderFrames:null,maxDecFrameBuffering:null};if(!e.flag())return{...a,vuiPresent:!1,restrictionFlagPos:-1};e.flag()&&e.bits(8)===255&&(e.bits(16),e.bits(16)),e.flag()&&e.flag(),e.flag()&&(e.bits(3),e.flag(),e.flag()&&(e.bits(8),e.bits(8),e.bits(8))),e.flag()&&(e.ue(),e.ue()),e.flag()&&(e.bits(32),e.bits(32),e.flag());const u=e.flag();u&&mn(e);const d=e.flag();d&&mn(e),(u||d)&&e.flag(),e.flag();const h=e.position;return e.flag()?(e.flag(),e.ue(),e.ue(),e.ue(),e.ue(),{...a,vuiPresent:!0,bitstreamRestriction:!0,maxNumReorderFrames:e.ue(),maxDecFrameBuffering:e.ue(),restrictionFlagPos:h}):{...a,vuiPresent:!0,restrictionFlagPos:h}}function Ks(e){const t=Hn(new Xt(On(e)));return{profileIdc:t.profileIdc,levelIdc:t.levelIdc,vuiPresent:t.vuiPresent,bitstreamRestriction:t.bitstreamRestriction,maxNumReorderFrames:t.maxNumReorderFrames,maxDecFrameBuffering:t.maxDecFrameBuffering}}function Ys(e){const t=On(e),r=Hn(new Xt(t));if(!r.vuiPresent||r.restrictionFlagPos<0||r.bitstreamRestriction)return null;const o=new Vs,i=new Xt(t);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([e[0],...qs(o.toBytes())])}function Gs(e){const t=[],r=e.length;let o=-1,i=0;for(;i+2<r;){const a=i+3<r&&e[i]===0&&e[i+1]===0&&e[i+2]===0&&e[i+3]===1,c=e[i]===0&&e[i+1]===0&&e[i+2]===1;a||c?(o>=0&&t.push(e.subarray(o,i)),i+=a?4:3,o=i):i++}return o>=0&&t.push(e.subarray(o,r)),t}class Js{constructor(t){this.onFrame=t,this.decoder=null,this.sps=null,this.pps=null,this.frameCount=0,this.submitAt=new Map,this.spsLogged=!1}setDecodeSampler(t){this.decodeSampler=t}decode(t){const r=[];let o=!1;for(const h of Gs(new Uint8Array(t))){const p=h[0]&31;if(p===7){const g=!this.sps||h.length!==this.sps.length||h.some((x,f)=>x!==this.sps[f]);this.sps=h,g&&this.decoder&&(this.decoder.close(),this.decoder=null)}else p===8?this.pps=h:p>=1&&p<=5&&(p===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),c=new DataView(a.buffer);let u=0;for(const h of r)c.setUint32(u,h.length,!1),u+=4,a.set(h,u),u+=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(t){var o;if(!this.decodeSampler)return;const r=this.submitAt.get(t.timestamp);r!==void 0&&(this.submitAt.delete(t.timestamp),this.decodeSampler({decodeMs:performance.now()-r,queueSize:((o=this.decoder)==null?void 0:o.decodeQueueSize)??0}))}close(){var t;(t=this.decoder)==null||t.close(),this.decoder=null}logSpsVui(t){if(!(this.spsLogged||!this.decodeSampler)){this.spsLogged=!0;try{console.log("[sps-vui]",JSON.stringify(Ks(t)))}catch(r){console.warn("[sps-vui] parse failed",r)}}}initDecoder(t,r){this.logSpsVui(t);const o=Ys(t)??t,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")}`,c=this.buildAVCC(o,r);this.decoder=new VideoDecoder({output:u=>{this.sampleDecode(u),this.onFrame(u)},error:u=>console.error("[WebCodecsCore]",u)}),this.decoder.configure({codec:a,description:c,optimizeForLatency:!0})}buildAVCC(t,r){const o=t[0]===0?t.subarray(4):t,i=r[0]===0?r.subarray(4):r,a=new Uint8Array(8+o.length+1+2+i.length);let c=0;return a[c++]=1,a[c++]=o[1],a[c++]=o[2],a[c++]=o[3],a[c++]=255,a[c++]=225,a[c++]=o.length>>8&255,a[c++]=o.length&255,a.set(o,c),c+=o.length,a[c++]=1,a[c++]=i.length>>8&255,a[c++]=i.length&255,a.set(i,c),a}}const Qs=`#version 300 es
106
+ */const Ds=[["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"}]],Ls=ne("volume-2",Ds);function Is(t){const[e,r]=s.useState(null);return s.useEffect(()=>{t&&kr(t).then(r)},[t]),{build:e}}function Ms(t){const[e,r]=s.useState([]),[o,i]=s.useState(null),[a,c]=s.useState(null),[u,d]=s.useState(""),[h,p]=s.useState(!1),[g,x]=s.useState(""),f=s.useCallback(k=>{k.type==="agents:listed"&&r(k.sessions),k.type==="session:joined"&&(p(!1),x("Connected")),k.type==="error"&&(p(!1),x(`Error: ${k.message}`))},[]),{send:b,connected:v}=En(f);s.useEffect(()=>{if(!v)return;b({type:"agents:list"});const k=setInterval(()=>b({type:"agents:list"}),5e3);return()=>clearInterval(k)},[v,b]);const T=s.useRef({sessionId:a,deviceId:u});s.useEffect(()=>{T.current={sessionId:a,deviceId:u}},[a,u]),s.useEffect(()=>()=>{const{sessionId:k,deviceId:F}=T.current;k&&F&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:F}})},[b]);const j=e.filter(k=>k.devices.some(F=>F.platform===t)),L=s.useCallback(k=>{d(k.id),p(!0),x("Booting…"),c(k.sessionId)},[]),C=s.useCallback(()=>d(""),[]),N=s.useCallback(()=>{const{sessionId:k,deviceId:F}=T.current;k&&F&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:F}}),c(null),p(!1),x("")},[b]),E=s.useCallback(()=>{const{sessionId:k,deviceId:F}=T.current;k&&F&&b({type:"device:shutdown",sessionId:k,payload:{deviceId:F}}),c(null),i(null),p(!1),x(""),b({type:"agents:list"})},[b]),M=s.useCallback(()=>{c(null),i(null),p(!1),x(""),b({type:"agents:list"})},[b]);return{sessions:e,selectedAgent:o,setSelectedAgent:i,activeSessionId:a,deviceId:u,booting:h,status:g,send:b,connected:v,agentGroups:j,startDevice:L,resetDevice:C,handleBack:N,handleBackToMacs:E,handleSessionEnded:M}}function Us(t,e){const[r,o]=s.useState(""),[i,a]=s.useState(""),[c,u]=s.useState("app-only"),[d,h]=s.useState("app-only"),p=(t==null?void 0:t.capabilities.includes("full-reset"))??!1,g=s.useCallback(()=>{h(p?c:"app-only"),u("app-only")},[c,p]),x=(t==null?void 0:t.devices.filter(v=>v.platform===e))??[],f=[...new Set(x.map(v=>v.osVersion).filter(Boolean))].sort((v,T)=>{const j=N=>N.replace(/^[^\d]*/,"").split(".").map(Number),[L,C]=[j(v),j(T)];for(let N=0;N<Math.max(L.length,C.length);N++){const E=(C[N]??0)-(L[N]??0);if(E!==0)return E}return 0}),b=(r?x.filter(v=>v.osVersion===r):x).filter(v=>!i||v.name.toLowerCase().includes(i.toLowerCase()));return{filteredDevices:x,osVersions:f,osVersion:r,setOsVersion:o,deviceSearch:i,setDeviceSearch:a,versionedDevices:b,resetMode:c,setResetMode:u,appliedResetMode:d,consumeResetMode:g,fullResetSupported:p}}function $s(){const[t]=Nn(),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(c=>!c)};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[e]),{perfMode:e,visible:r}}function In(t){const e=t.rolloverOffset.x-t.buttonW/2,r=t.anchor==="top"?t.rolloverOffset.y:t.normalOffset.y-t.buttonH/2;return{left:e,top:r,right:e+t.buttonW,bottom:r+t.buttonH}}function Fs(t,e,r){const o=Math.max(r.left-t,0,t-r.right),i=Math.max(r.top-e,0,e-r.bottom);return Math.hypot(o,i)}function Bs(t,e,r,o){let i=null,a=1/0;for(const c of r){const u=Fs(t,e,In(c));u<a&&(a=u,i=c.name)}return a<=o?i:null}const Os=["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),c=s.useRef(r);s.useEffect(()=>{c.current=r},[r]);const u=s.useRef(!1),d=s.useRef(null),h=s.useRef([]),p=s.useRef(""),g=s.useRef(0),x=s.useRef(null),f=s.useCallback(function T(){var j;u.current&&((j=x.current)==null||j.call(x),g.current=requestAnimationFrame(T))},[]),b=s.useCallback(T=>{const j=a.current;if(!j)return;const L=j.getContext("2d");L&&(L.fillStyle="#000",L.fillRect(0,0,j.width,j.height));const C=Os.find(E=>MediaRecorder.isTypeSupported(E))??"";if(!C)return;p.current=C,h.current=[];const N=new MediaRecorder(j.captureStream(30),{mimeType:C});N.ondataavailable=E=>{E.data.size>0&&h.current.push(E.data)},d.current=N,N.start(1e3),x.current=T,u.current=!0,g.current=requestAnimationFrame(f),i("recording")},[f]),v=s.useCallback(async()=>{var E;i("uploading"),u.current=!1,cancelAnimationFrame(g.current);const T=d.current;if(!T){i("idle");return}await new Promise(M=>{const k=setTimeout(M,5e3);T.onstop=()=>{clearTimeout(k),M()};try{T.stop()}catch{clearTimeout(k),M()}}),d.current=null;const j=p.current,L=j.includes("mp4")?".mp4":".webm",C=new Blob(h.current,{type:j});h.current=[];const N=new FormData;N.append("file",C,`tapflow-${Date.now()}${L}`);try{const M=new URLSearchParams({sessionId:t});e&&M.set("buildId",String(e));const k=await fetch(`/api/v1/recordings/upload?${M}`,{method:"POST",credentials:"include",body:N}),F=await k.json();if(k.ok&&F.url){const G=document.createElement("a");G.href=F.url,G.download="",G.click(),(E=c.current)==null||E.call(c),i("done"),setTimeout(()=>i("idle"),2e3)}else i("idle")}catch{i("idle")}},[t,e]);return s.useEffect(()=>{if(o!=="recording")return;const T=()=>{document.visibilityState==="hidden"&&v()};return document.addEventListener("visibilitychange",T),()=>{var j;document.removeEventListener("visibilitychange",T),u.current&&(u.current=!1,cancelAnimationFrame(g.current),(j=d.current)==null||j.stop(),d.current=null)}},[o,v]),{recordState:o,recordCanvasRef:a,startClientRecording:b,stopClientRecording:v}}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 ft({className:t,...e}){return n.jsx("kbd",{"data-slot":"kbd",className:te("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:te("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(ft,{children:r},r))})]})}const pn="text-muted-foreground hover:text-muted-foreground",mn="text-destructive hover:text-destructive";function Hs(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 zs({position:t,steerable:e,reason:r}){const o=r==="awaiting-app",i=!e&&r==="state-unconfirmed"?" animate-pulse":"",a=e?"":Hs(r);switch(t){case"offline":return{Icon:ys,className:(e||o?"text-amber-500 hover:text-amber-500":mn)+i,status:`Device is offline.${a}`};case"online":return{Icon:Ot,className:(e||o?"":mn)+i,status:`Device is on the network.${a}`};case"waiting":return{Icon:Ot,className:`${pn} animate-pulse`,status:"Checking the network state."};case"unknown":return{Icon:Ot,className:pn,status:"No network state has been reported."}}}function Ws({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:c,deviceSlot:u,launchSlot:d,network:h,reboot:p}){const g=s.useId(),x=s.useId(),f=s.useId(),[b,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,c,n.jsxs(Ce,{children:[n.jsx(Te,{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(Ln,{className:"h-4 w-4"})})}),n.jsx(Ee,{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:[u,n.jsxs(Ce,{children:[n.jsx(Te,{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(ks,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsx(St,{label:"Rotate",keys:["⌘","⇧","O"]})})]}),p&&(()=>{const T=p.pending?"Restarting the device":"Restart the device";return n.jsxs(n.Fragment,{children:[n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{ref:p.buttonRef,variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":T,"aria-busy":p.pending,"aria-disabled":p.pending,"aria-describedby":x,onClick:()=>{p.pending||v(!0)},children:p.pending?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(Ss,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:T})]}),n.jsx("span",{id:x,role:"status",className:"sr-only",children:p.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(Ce,{children:[n.jsx(Te,{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(ns,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsx(St,{label:"Screenshot",keys:["⌘","S"]})})]}),n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:te("h-8 w-8 aria-disabled:opacity-50",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","aria-busy":o==="uploading","aria-disabled":o==="uploading"||o==="done","aria-describedby":f,onClick:()=>{(o==="idle"||o==="recording")&&r()},children:o==="uploading"?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):o==="recording"?n.jsx(Es,{className:"h-4 w-4 fill-current"}):n.jsx(As,{className:"h-4 w-4"})})}),n.jsx(Ee,{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 the recording"})]}),n.jsx("span",{id:f,role:"status",className:"sr-only",children:o==="recording"?"Recording.":o==="uploading"?"Processing the recording.":o==="done"?"Recording saved.":""})]}),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:T,className:j,status:L}=zs(h),C=Ws(h),N=h.position==="waiting"||h.position==="unknown"||!h.steerable;return n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:te("h-8 w-8",j),"aria-label":C,"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(T,{className:"h-4 w-4"})})}),n.jsx("span",{id:g,role:"status",className:"sr-only",children:h.pending?"Changing the network state.":L}),n.jsx(Ee,{side:"left",children:N?`${C} — ${L}`:C})]})})()})]})]}),p&&n.jsx(Dr,{open:b,onOpenChange:v,children:n.jsxs(Lr,{children:[n.jsxs(Ir,{children:[n.jsx(Mr,{children:"Restart this device?"}),n.jsx(Ur,{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($r,{children:[n.jsx(Fr,{children:"Cancel"}),n.jsx(Br,{onClick:()=>{v(!1),p.onReboot()},children:"Restart"})]})]})})]}):null}const Vs=3e3,qs=8e3;function Fn({sessionId:t,send:e,supported:r,deviceReady:o,handlerRef:i,onError:a}){const[c,u]=s.useState("waiting"),[d,h]=s.useState(!0),[p,g]=s.useState(void 0),x=s.useRef(void 0),[f,b]=s.useState(!1),v=s.useRef(null),T=s.useRef(new Set),j=s.useRef(a);s.useEffect(()=>{j.current=a},[a]);const L=s.useRef(o);s.useEffect(()=>{L.current=o},[o]);const C=s.useRef(o);s.useEffect(()=>{u("waiting"),h(!0),g(void 0),x.current=void 0,b(!1),v.current=null,C.current=L.current,T.current.clear()},[t]),s.useEffect(()=>{var k;if(o){C.current=!0,u("waiting");return}u(C.current?"unknown":"waiting"),h(!0),g(void 0),x.current=void 0,v.current&&((k=j.current)==null||k.call(j,"The device became unavailable before it answered. Its network state is unchanged as far as tapflow can tell."),T.current.add(v.current)),b(!1),v.current=null},[o]),s.useEffect(()=>{if(r)return i.current=k=>{var G,z;if(k.type==="network:error"){k.requestId===v.current&&(v.current=null,b(!1),(G=j.current)==null||G.call(j,k.message));return}if(k.type!=="network:state"||!L.current||k.requestId!==void 0&&T.current.has(k.requestId))return;const F=k.payload.available?void 0:k.payload.reason;u(k.payload.offline?"offline":"online"),h(k.payload.available),g(F),F==="enforcement-lost"&&x.current!=="enforcement-lost"&&((z=j.current)==null||z.call(j,"The device went back on the network before you took it off. Anything checked while it was offline needs checking again.")),x.current=F,k.requestId!==void 0&&k.requestId===v.current&&(v.current=null,b(!1))},()=>{i.current=void 0}},[i,r]),s.useEffect(()=>{if(!r||!o||c!=="waiting")return;const k=setTimeout(()=>u(F=>F==="waiting"?"unknown":F),Vs);return()=>clearTimeout(k)},[r,o,c]);const N=s.useCallback(()=>{if(!r||f)return;const k=X();v.current=k,b(!0),e({type:"network:set",sessionId:t,requestId:k,payload:{offline:c!=="offline"}})},[c,f,e,t,r]),[E,M]=s.useState(null);return s.useEffect(()=>{M(f?v.current:null)},[f]),s.useEffect(()=>{if(E===null)return;const k=setTimeout(()=>{var F;v.current===E&&(v.current=null,b(!1),(F=j.current)==null||F.call(j,"The device did not answer. Its network state is unchanged as far as tapflow can tell."))},qs);return()=>clearTimeout(k)},[E]),{position:c,steerable:d,reason:p,pending:f,toggle:N}}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 Xs{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 Bn(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 Ks(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 Ys=new Set([100,110,122,244,44,83,86,118,128,138,139,134,135]);function gn(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 On(t){const e=t.bits(8);t.bits(8);const r=t.bits(8);if(t.ue(),Ys.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 f=0;f<x;f++)if(t.flag()){const b=f<6?16:64;let v=8,T=8;for(let j=0;j<b;j++)T!==0&&(T=(v+t.se()+256)%256),v=T===0?v:T}}}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 u=t.flag();u&&gn(t);const d=t.flag();d&&gn(t),(u||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 Gs(t){const e=On(new Xt(Bn(t)));return{profileIdc:e.profileIdc,levelIdc:e.levelIdc,vuiPresent:e.vuiPresent,bitstreamRestriction:e.bitstreamRestriction,maxNumReorderFrames:e.maxNumReorderFrames,maxDecFrameBuffering:e.maxDecFrameBuffering}}function Js(t){const e=Bn(t),r=On(new Xt(e));if(!r.vuiPresent||r.restrictionFlagPos<0||r.bitstreamRestriction)return null;const o=new Xs,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],...Ks(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,c=t[i]===0&&t[i+1]===0&&t[i+2]===1;a||c?(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 Zs{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 p=h[0]&31;if(p===7){const g=!this.sps||h.length!==this.sps.length||h.some((x,f)=>x!==this.sps[f]);this.sps=h,g&&this.decoder&&(this.decoder.close(),this.decoder=null)}else p===8?this.pps=h:p>=1&&p<=5&&(p===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),c=new DataView(a.buffer);let u=0;for(const h of r)c.setUint32(u,h.length,!1),u+=4,a.set(h,u),u+=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(Gs(e)))}catch(r){console.warn("[sps-vui] parse failed",r)}}}initDecoder(e,r){this.logSpsVui(e);const o=Js(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")}`,c=this.buildAVCC(o,r);this.decoder=new VideoDecoder({output:u=>{this.sampleDecode(u),this.onFrame(u)},error:u=>console.error("[WebCodecsCore]",u)}),this.decoder.configure({codec:a,description:c,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 c=0;return a[c++]=1,a[c++]=o[1],a[c++]=o[2],a[c++]=o[3],a[c++]=255,a[c++]=225,a[c++]=o.length>>8&255,a[c++]=o.length&255,a.set(o,c),c+=o.length,a[c++]=1,a[c++]=i.length>>8&255,a[c++]=i.length&255,a.set(i,c),a}}const eo=`#version 300 es
107
107
  in vec2 a_pos;
108
108
  out vec2 v_uv;
109
109
  void main() {
110
110
  v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
111
111
  gl_Position = vec4(a_pos, 0.0, 1.0);
112
- }`,Zs=`#version 300 es
112
+ }`,to=`#version 300 es
113
113
  precision mediump float;
114
114
  in vec2 v_uv;
115
115
  uniform sampler2D u_tex;
116
116
  out vec4 out_color;
117
117
  void main() {
118
118
  out_color = texture(u_tex, v_uv);
119
- }`;function eo(e){const t=e.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!t)return null;const r=(p,g)=>{const x=t.createShader(p);return t.shaderSource(x,g),t.compileShader(x),x},o=t.createProgram(),i=r(t.VERTEX_SHADER,Qs),a=r(t.FRAGMENT_SHADER,Zs);t.attachShader(o,i),t.attachShader(o,a),t.linkProgram(o),t.deleteShader(i),t.deleteShader(a),t.useProgram(o);const c=t.createVertexArray();t.bindVertexArray(c);const u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW);const d=t.getAttribLocation(o,"a_pos");t.enableVertexAttribArray(d),t.vertexAttribPointer(d,2,t.FLOAT,!1,0,0),t.bindVertexArray(null);const h=t.createTexture();return t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,h),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,"u_tex"),0),{gl:t,program:o,tex:h,vao:c}}class to{constructor(t){this.canvas=t,this.state=null}init(){return this.state=eo(this.canvas),this.state!==null}drawFrame(t){const r=this.state;if(!r)return t.close(),null;const o=t.displayWidth,i=t.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,t),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{t.close()}}dispose(){const t=this.state;t&&(t.gl.deleteTexture(t.tex),t.gl.deleteVertexArray(t.vao),t.gl.deleteProgram(t.program),this.state=null)}}function no(e){const t=new to(e);return t.init(),t}class ro{constructor(t=no){this._size=null,this.canvas=document.createElement("canvas"),this.renderer=t(this.canvas),this.core=new Js(r=>this.render(r))}get surface(){return this.canvas}get size(){return this._size}onResize(t){this.resizeCb=t}onDecodedFrame(t){this.decodedCb=t,this.core.setDecodeSampler(r=>{this.lastSample=r})}decode(t){this.core.decode(t)}close(){this.core.close(),this.renderer.dispose()}render(t){var o,i;const r=this.renderer.drawFrame(t);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 so=`#version 300 es
119
+ }`;function no(t){const e=t.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!e)return null;const r=(p,g)=>{const x=e.createShader(p);return e.shaderSource(x,g),e.compileShader(x),x},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 c=e.createVertexArray();e.bindVertexArray(c);const u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u),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:c}}class ro{constructor(e){this.canvas=e,this.state=null}init(){return this.state=no(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 so(t){const e=new ro(t);return e.init(),e}class oo{constructor(e=so){this._size=null,this.canvas=document.createElement("canvas"),this.renderer=e(this.canvas),this.core=new Zs(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 ao=`#version 300 es
120
120
  in vec2 a_pos;
121
121
  out vec2 v_uv;
122
122
  void main() {
123
123
  v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
124
124
  gl_Position = vec4(a_pos, 0.0, 1.0);
125
- }`,oo=`#version 300 es
125
+ }`,io=`#version 300 es
126
126
  precision mediump float;
127
127
  in vec2 v_uv;
128
128
  uniform sampler2D u_texY;
@@ -137,4 +137,4 @@ void main() {
137
137
  float g = Y - 0.1873 * U - 0.4681 * V;
138
138
  float b = Y + 1.8556 * U;
139
139
  out_color = vec4(r, g, b, 1.0);
140
- }`;function Ht(e,t,r,o){const i=e.createTexture();return e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,i),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,r),t),i}function ao(e){const t=e.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!t)return null;const r=(x,f)=>{const b=t.createShader(x);return t.shaderSource(b,f),t.compileShader(b),b},o=t.createProgram(),i=r(t.VERTEX_SHADER,so),a=r(t.FRAGMENT_SHADER,oo);t.attachShader(o,i),t.attachShader(o,a),t.linkProgram(o),t.deleteShader(i),t.deleteShader(a),t.useProgram(o);const c=t.createVertexArray();t.bindVertexArray(c);const u=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,u),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW);const d=t.getAttribLocation(o,"a_pos");t.enableVertexAttribArray(d),t.vertexAttribPointer(d,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),t.pixelStorei(t.UNPACK_ALIGNMENT,1);const h=Ht(t,0,"u_texY",o),p=Ht(t,1,"u_texU",o),g=Ht(t,2,"u_texV",o);return{gl:t,program:o,texY:h,texU:p,texV:g,vao:c}}class io{constructor(t){this.canvas=t,this.state=null}init(){return this.state=ao(this.canvas),this.state!==null}drawI420(t,r,o){const i=this.state;if(!i)return null;const{gl:a}=i,c=r+1>>1,u=o+1>>1,d=r*o,h=c*u,p=t.subarray(0,d),g=t.subarray(d,d+h),x=t.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 f=(b,v,T,j,L)=>{a.activeTexture(a.TEXTURE0+b),a.bindTexture(a.TEXTURE_2D,v),a.texImage2D(a.TEXTURE_2D,0,a.R8,T,j,0,a.RED,a.UNSIGNED_BYTE,L)};return f(0,i.texY,r,o,p),f(1,i.texU,c,u,g),f(2,i.texV,c,u,x),a.bindVertexArray(i.vao),a.drawArrays(a.TRIANGLES,0,6),a.bindVertexArray(null),{width:r,height:o}}dispose(){const t=this.state;t&&(t.gl.deleteTexture(t.texY),t.gl.deleteTexture(t.texU),t.gl.deleteTexture(t.texV),t.gl.deleteVertexArray(t.vao),t.gl.deleteProgram(t.program),this.state=null)}}const co=0;function lo(e){const t=new io(e);return t.init(),t}function uo(){return new Worker(new URL("/assets/tinyh264.worker-DiJ50Hai.js",import.meta.url),{type:"module"})}class fo{constructor(t=lo,r=uo){this.ready=!1,this.pending=[],this._size=null,this.canvas=document.createElement("canvas"),this.renderer=t(this.canvas),this.worker=r(),this.worker.onmessage=o=>this.onMessage(o.data)}get surface(){return this.canvas}get size(){return this._size}onResize(t){this.resizeCb=t}onDecodedFrame(t){this.decodedCb=t}decode(t){if(!this.ready){this.pending.push(t);return}this.post(t)}close(){this.worker.terminate(),this.renderer.dispose()}post(t){this.worker.postMessage({type:"decode",data:t,offset:0,length:t.byteLength,renderStateId:co},[t])}onMessage(t){var o,i;if(t.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(t.data),t.width,t.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 e=typeof window<"u";let t=!1;try{t=!!document.createElement("canvas").getContext("webgl2")}catch{t=!1}return{secureContext:e&&window.isSecureContext===!0,webCodecs:e&&"VideoDecoder"in window,webgl2:t,wasm:typeof WebAssembly<"u"&&typeof Worker<"u"}}function ho(e=Jt()){return e.secureContext&&e.webCodecs&&e.webgl2?new ro:e.wasm&&e.webgl2?new fo:null}function po(e=Jt()){return e.secureContext&&e.webCodecs&&e.webgl2||e.wasm&&e.webgl2}function mo(e=Jt()){return e.secureContext&&e.webCodecs&&e.webgl2?"high":e.wasm&&e.webgl2?"standard":"unsupported"}const go="https://www.tapflow.dev/reference/configuration#https-secure-context";function xo({open:e,onOpenChange:t}){return n.jsx(_n,{open:e,onOpenChange:t,children:n.jsxs(Pn,{className:"sm:max-w-[440px]",children:[n.jsxs(Fr,{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(Hr,{children:[n.jsx(ie,{variant:"outline",onClick:()=>window.open(go,"_blank","noopener,noreferrer"),children:"How to enable"}),n.jsx(ie,{onClick:()=>t(!1),children:"Got it"})]})]})})}const gn="tapflow.perfModeNoticeDismissed";function bo(e,t){return e==="standard"&&!t}const yo={high:"Smooth",standard:"Standard",unsupported:null};function vo(e){const{connected:t,joined:r,bootError:o,deviceReady:i,installing:a,installError:c,agentAway:u,decoderUnsupported:d}=e;return t?r?u?"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…":c?`Install failed: ${c}`:d?"Streaming is not supported in this environment.":null:"Starting device…":"Joining session…":"Connecting…"}function Qt(e){const{joined:t,fps:r,keyboardActive:o}=e,i=vo(e),a=r>15,c=a?"#10b981":"#94a3b8",u=a?"Active":"Idle",d=s.useMemo(()=>mo(),[]),h=yo[d],[p,g]=s.useState(!1);s.useEffect(()=>{let f=!1;try{f=localStorage.getItem(gn)==="1"}catch{}bo(d,f)&&g(!0)},[d]);const x=f=>{if(g(f),!f)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:te("flex items-center",o?"text-emerald-500":"text-muted-foreground"),style:{gap:6},children:[n.jsx(ks,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"text-[12px] font-medium",children:"Focus"})]}),t&&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:c}}),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:te("text-[11px]",a?"text-emerald-500":"text-muted-foreground/60"),children:u})]}),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-words",children:i})}),n.jsx(xo,{open:p,onOpenChange:x})]})}function zn({open:e,onOpenChange:t,openUrl:r}){const[o,i]=s.useState(""),a=s.useRef(null);s.useEffect(()=>{e?setTimeout(()=>{var u;return(u=a.current)==null?void 0:u.focus()},0):i("")},[e]);const c=()=>{o.trim()&&(r(o.trim()),t(!1))};return n.jsx(_n,{open:e,onOpenChange:t,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(Cr,{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:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&c()}})]}),n.jsx(ie,{size:"sm",disabled:!o.trim(),onClick:c,className:"shrink-0 rounded-xl h-8 px-4",children:"Open"})]})]})})}function wo(e,t,r,o,i,a){const{x:c,y:u,width:d,height:h}=i;let p,g;if(a){const x=(e.x-t.left)/t.width;p=(1-(e.y-t.top)/t.height)*r,g=x*o}else p=(e.x-t.left)*(r/t.width),g=(e.y-t.top)*(o/t.height);return p<c||p>c+d||g<u||g>u+h?null:{x:(p-c)/d,y:(g-u)/h}}function So(e,t,r){const o=(e.x-t.left)/t.width,i=(e.y-t.top)/t.height;return o<0||o>1||i<0||i>1?null:r?{x:i,y:1-o}:{x:o,y:i}}function Wn(e){return{f0:{x:1-e.x,y:1-e.y},f1:e}}function Ro(e,t){return e>0?Math.min(1,t/e):1}const Kt=22,xn=[84,70,70,69],ko=1,jo=0,It=1,Vn=2,Co=1,To=2,Eo=4;function No(e){if(e.byteLength<Kt)return null;const t=new DataView(e);for(let i=0;i<xn.length;i++)if(t.getUint8(i)!==xn[i])return null;if(t.getUint8(4)!==ko)return null;const r=t.getUint8(5),o=r&Eo?Vn:r&Co?It:jo;return{capturedAt:Number(t.getBigUint64(6)),relayedAt:Number(t.getBigUint64(14)),codec:o,keyframe:o===It&&(r&To)!==0}}function qn(e){const{binaryFrameHandlerRef:t,perfHookRef:r,frameCount:o}=e,i=s.useRef(e);s.useLayoutEffect(()=>{i.current=e},[e]),s.useEffect(()=>{let a=null,c=!1,u=!1,d;const h=()=>{if(a)return a;if(c)return null;const p=ho();return p?(a=p,p.onResize(g=>i.current.onResize(g)),d=i.current.onDecoderReady(p),p):(c=!0,i.current.onUnsupported(),console.warn("[decoder] none available — set up HTTPS or use a supported browser"),null)};return t.current=(p,g)=>{const x=i.current.onJpegFrame;if(x&&(g==null?void 0:g.codec)!==It){x(p,g);return}const f=h();if(f){if(!u){if(!(g!=null&&g.keyframe))return;u=!0}f.decode(p),o.current+=1}},()=>{t.current=void 0,typeof d=="function"&&d(),a==null||a.close(),a==null||a.surface.remove(),a=null}},[t,r,o])}const Ao=3e3+5*300,_o=Ao+500,_t=8;function Po(){var e;return window.isSecureContext&&typeof ClipboardItem<"u"&&!!((e=navigator.clipboard)!=null&&e.write)}class Rt extends Error{}function Do(e){const t=e.then(r=>new Blob([r],{type:"text/plain"}));return navigator.clipboard.write([new ClipboardItem({"text/plain":t})])}function Zt(e){return!(e.metaKey||e.ctrlKey)||e.altKey?!1:e.code==="KeyV"?!0:!e.shiftKey&&(e.code==="KeyC"||e.code==="KeyX")}const Lo=1024*1024,Io=e=>new TextEncoder().encode(e).length,Mo=e=>{var t;return!!((t=e.payload)!=null&&t.unsupported)},Uo=e=>{var t,r;return((t=e.payload)==null?void 0:t.sentinelParked)===!1||((r=e.payload)==null?void 0:r.unsupported)===!0};function $o(){const e=window.getSelection();return!!e&&!e.isCollapsed&&e.toString().length>0}function bn(){const e=document.activeElement;return!!e&&(e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable)}function Xn({sessionId:e,send:t,active:r,supported:o,handlerRef:i,sendChord:a,onError:c}){const u=s.useRef(new Map),d=s.useRef(null),h=s.useRef(c);s.useLayoutEffect(()=>{h.current=c});const p=s.useCallback(x=>{var f;d.current!==x&&(d.current=x,(f=h.current)==null||f.call(h,x))},[]);s.useEffect(()=>(i.current=x=>{if(!x.requestId)return;const f=u.current.get(x.requestId);f&&(u.current.delete(x.requestId),f(x))},()=>{i.current=void 0}),[i]);const g=s.useCallback((...[x,f])=>{const b=X();return new Promise(v=>{const T=setTimeout(()=>{u.current.delete(b),v(null)},_o);u.current.set(b,j=>{clearTimeout(T),v(j)}),t({type:x,sessionId:e,requestId:b,payload:f})})},[t,e]);s.useEffect(()=>{if(!r||!o)return;const x=async b=>{if(b.code==="KeyV"||!Zt(b))return;const v=b.code==="KeyX";if(bn()||$o()||(b.preventDefault(),b.repeat))return;if(!Po()){a(v?"KeyX":"KeyC",_t),p("Copied on the device. Serving the dashboard over HTTPS also brings it to your clipboard.");return}let T,j;const L=new Promise((M,k)=>{T=M,j=k});L.catch(()=>{});const C=Do(L).catch(M=>{M instanceof Rt||p(M instanceof Error&&M.name==="NotAllowedError"?"Your browser blocked the clipboard write":"Could not write to your clipboard")}),N=await g("clipboard:read",{press:v?"cut":"copy"});if(!N){j(new Rt("timeout")),p("The device is taking too long — try again");return}if(N.type==="clipboard:error"){j(new Rt(N.message||"read failed")),p(N.message||"Clipboard read failed"),Uo(N)&&a(v?"KeyX":"KeyC",_t);return}if(N.type!=="clipboard:data"){j(new Rt("unexpected reply")),p("Clipboard read failed");return}const{text:E}=N.payload;if(d.current=null,!E){j(new Rt("empty"));return}T(E),await C},f=b=>{var T;if(bn())return;const v=((T=b.clipboardData)==null?void 0:T.getData("text"))??"";if(b.preventDefault(),!v){a("KeyV",_t);return}if(Io(v)>Lo){p("That text is too large to send to the device");return}g("clipboard:write",{text:v,pasteAfter:!0}).then(j=>{if(!j){p("The device is taking too long — try again");return}if(j.type==="clipboard:write-done"){d.current=null;return}if(j.type!=="clipboard:error"){p("Clipboard write failed");return}p(j.message||"Clipboard write failed"),Mo(j)&&a("KeyV",_t)})};return document.addEventListener("keydown",x),document.addEventListener("paste",f),()=>{document.removeEventListener("keydown",x),document.removeEventListener("paste",f)}},[r,o,g,a,p])}const ze=13,ut=8,yn=16,Bo=.02,Fo=100;function Oo({sessionId:e,buildId:t,send:r,openUrl:o,launchApp:i,connected:a,joined:c,deviceReady:u,installing:d,installed:h,installError:p,bootError:g,launching:x,chrome:f,binaryFrameHandlerRef:b,clipboardHandlerRef:v,clipboardSupported:T,networkHandlerRef:j,networkSupported:L,onRecordingUploaded:C,swKeyboardVisible:N,swKeyboardPending:E,onKbdToggle:M,rebootPending:k,onReboot:B,restartButtonRef:G,perfHookRef:z}){const F=s.useRef(null),Q=s.useRef(null),ue=s.useRef(null),{fps:Ie,frameCount:Fe}=$n(),be=s.useRef(0),{recordState:ye,recordCanvasRef:Z,startClientRecording:Ae,stopClientRecording:Oe}=Un({sessionId:e,buildId:t,onRecordingUploaded:C}),He=s.useRef(0),[Me,Ue]=s.useState(!1),[U,q]=s.useState(!1),[K,Se]=s.useState(!1),[J,Re]=s.useState(!1),[de,ee]=s.useState(!1),[We,rt]=s.useState(null),[Ve,fe]=s.useState(null),[ve,ke]=s.useState(!1),[Y,he]=s.useState(null),$e=s.useRef(Y);s.useEffect(()=>{$e.current=Y},[Y]);const ge=s.useRef(null),oe=s.useRef(null),re=s.useRef(!1),ae=s.useRef(!1),_e=s.useRef(0),Pe=s.useRef(null),je=s.useRef(null),we=s.useRef("idle"),w=s.useRef(null),H=s.useRef(null),ce=s.useRef(null);s.useEffect(()=>{ce.current=f},[f]),s.useEffect(()=>{const l=new Image;l.onload=()=>{H.current=l},l.src=`data:image/png;base64,${f.framePng}`},[f.framePng]),qn({binaryFrameHandlerRef:b,perfHookRef:z,frameCount:Fe,onUnsupported:()=>Se(!0),onResize:l=>{const y=F.current;if(y&&(y.width!==l.width||y.height!==l.height)&&(y.width=l.width,y.height=l.height,!ce.current)){const m=Z.current;m&&(m.width=l.width,m.height=l.height)}q(!0)},onDecoderReady:l=>{var S;const y=l.surface,m=F.current;y.style.position="absolute",m&&(y.style.left=m.style.left,y.style.top=m.style.top,y.style.width=m.style.width,y.style.height=m.style.height,y.style.borderRadius=m.style.borderRadius),y.style.objectFit="fill",y.style.zIndex="3",y.style.pointerEvents="none",(S=Q.current)==null||S.appendChild(y);let A=null;const P=()=>{const I=F.current,$=I==null?void 0:I.getContext("2d");if(I&&$&&l.size)try{$.drawImage(l.surface,0,0,I.width,I.height)}catch{}A=requestAnimationFrame(P)};return A=requestAnimationFrame(P),()=>{A!==null&&cancelAnimationFrame(A)}},onJpegFrame:l=>{const y=performance.now();be.current&&y-be.current,be.current=y;const m=He.current;createImageBitmap(new Blob([l],{type:"image/jpeg"})).then(A=>{if(performance.now()-y,He.current!==m){A.close();return}const P=F.current,S=P==null?void 0:P.getContext("2d");if(!P||!S){A.close();return}if((P.width!==A.width||P.height!==A.height)&&(P.width=A.width,P.height=A.height,!ce.current)){const $=Z.current;$&&($.width=A.width,$.height=A.height)}const I=performance.now();S.drawImage(A,0,0),performance.now()-I,A.close(),q(!0),Fe.current+=1}).catch(()=>{})}}),s.useEffect(()=>{const l=Z.current,y=Q.current;l&&y&&(l.width=y.clientWidth,l.height=y.clientHeight)},[f,Z]);const pe=s.useCallback(()=>{const l=Z.current,y=F.current;if(!l||!y)return;const m=l.getContext("2d");if(!m)return;const A=ce.current;if(m.clearRect(0,0,l.width,l.height),A){H.current&&m.drawImage(H.current,0,0,l.width,l.height);const I=Math.round(A.screenCornerRadius/2*(l.height/(A.compositeHeight/2)));m.save(),m.beginPath(),I>0?m.roundRect(y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight,I):m.rect(y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight),m.clip(),m.drawImage(y,y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight),m.restore()}else m.drawImage(y,0,0,l.width,l.height);const P=$e.current;if(P)for(const I of[P.f0,P.f1]){const $=A?y.offsetLeft+I.x*y.clientWidth:I.x*l.width,le=A?y.offsetTop+I.y*y.clientHeight:I.y*l.height;re.current?(m.beginPath(),m.arc($,le,ut,0,Math.PI*2),m.fillStyle="rgba(255,255,255,0.92)",m.fill(),m.strokeStyle="rgba(0,0,0,0.2)",m.lineWidth=1,m.stroke()):(m.beginPath(),m.arc($,le,ze,0,Math.PI*2),m.strokeStyle="rgba(0,0,0,0.3)",m.lineWidth=3,m.stroke(),m.beginPath(),m.arc($,le,ze,0,Math.PI*2),m.strokeStyle="rgba(255,255,255,0.65)",m.lineWidth=1.5,m.stroke())}const S=je.current;if(S){const I=we.current,$=w.current;if(m.save(),I==="down")m.beginPath(),m.arc(S.x,S.y,ut,0,Math.PI*2),m.fillStyle="rgba(255,255,255,0.92)",m.fill(),m.strokeStyle="rgba(0,0,0,0.2)",m.lineWidth=1,m.stroke();else if(I==="release"&&$){const le=Math.min((performance.now()-$.startTime)/350,1);m.beginPath(),m.arc(S.x,S.y,ut+26*le,0,Math.PI*2),m.strokeStyle=`rgba(255,255,255,${(1-le)*.55})`,m.lineWidth=1.5,m.stroke(),le>=1&&(we.current="idle",w.current=null)}else m.beginPath(),m.arc(S.x,S.y,ze,0,Math.PI*2),m.strokeStyle="rgba(0,0,0,0.3)",m.lineWidth=3,m.stroke(),m.beginPath(),m.arc(S.x,S.y,ze,0,Math.PI*2),m.strokeStyle="rgba(255,255,255,0.65)",m.lineWidth=1.5,m.stroke();m.restore()}},[Z]),V=s.useCallback(()=>{const l=F.current;if(!l)return;const y=document.createElement("canvas"),m=y.getContext("2d");m&&(y.width=l.width,y.height=l.height,m.drawImage(l,0,0),y.toBlob(A=>{if(!A)return;const P=URL.createObjectURL(A),S=document.createElement("a");S.href=P,S.download=`tapflow-${Date.now()}.png`,S.click(),URL.revokeObjectURL(P)},"image/png"))},[]),me=s.useCallback(()=>{if(ye==="idle"){const l=Z.current;if(!l)return;const y=Q.current;if(y&&y.clientWidth>0)l.width=y.clientWidth,l.height=y.clientHeight;else{const m=F.current;if(m&&m.width>0)l.width=m.width,l.height=m.height;else return}Ae(pe)}else ye==="recording"&&Oe()},[ye,Ae,Oe,pe,Z]),qe=s.useCallback(()=>{r({type:"input:rotate",sessionId:e}),Re(l=>!l)},[r,e]),Nt=s.useRef(J);s.useEffect(()=>{Nt.current=J},[J]),s.useEffect(()=>()=>{Nt.current&&r({type:"input:rotate",sessionId:e})},[]);const Ut=s.useCallback((l,y)=>{r({type:"input:key",sessionId:e,requestId:X(),payload:{code:l,modifiers:y}})},[r,e]);Xn({sessionId:e,send:r,active:de,supported:T,handlerRef:v,sendChord:Ut,onError:l=>Ne.error(l)});const st=Fn({sessionId:e,send:r,supported:L,deviceReady:u,handlerRef:j,onError:l=>Ne.error(l)});s.useEffect(()=>{const l=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),y=S=>{if(S.code==="AltLeft"||S.code==="AltRight"){ae.current=!0;return}if(S.metaKey){const $=document.activeElement;if(!$||$.tagName!=="INPUT"&&$.tagName!=="TEXTAREA"){if(!S.shiftKey&&S.code==="KeyK"){S.preventDefault(),Ue(!0);return}if(!S.shiftKey&&S.code==="KeyS"){S.preventDefault(),V();return}if(S.shiftKey&&S.code==="KeyY"){S.preventDefault(),me();return}if(S.shiftKey&&S.code==="KeyO"){S.preventDefault(),qe();return}if(S.shiftKey&&S.code==="KeyU"){S.preventDefault(),r({type:"input:button",sessionId:e,requestId:X(),payload:{name:"home"}});return}if(S.shiftKey&&S.code==="KeyK"){S.preventDefault(),E||M();return}}}if(!de||l.has(S.code)||T&&Zt(S))return;S.preventDefault();const I=(S.shiftKey?2:0)|(S.ctrlKey?1:0)|(S.metaKey?8:0);r({type:"input:key",sessionId:e,requestId:X(),payload:{code:S.code,modifiers:I}})},m=()=>{re.current&&(re.current=!1,ke(!1),r({type:"input:pinch:end",sessionId:e,requestId:X()})),ae.current=!1,he(null)},A=S=>{(S.code==="AltLeft"||S.code==="AltRight")&&m()},P=()=>{ae.current&&m()};return window.addEventListener("keydown",y),window.addEventListener("keyup",A),window.addEventListener("blur",P),()=>{window.removeEventListener("keydown",y),window.removeEventListener("keyup",A),window.removeEventListener("blur",P)}},[de,T,r,e,V,me,qe,M,E]),s.useEffect(()=>{if(!de)return;const l=y=>{const m=Q.current??F.current;m&&!m.contains(y.target)&&ee(!1)};return document.addEventListener("pointerdown",l),()=>document.removeEventListener("pointerdown",l)},[de]);const Xe=s.useCallback(l=>{const y=(J?ue.current:null)??Q.current;if(!y)return null;const m=y.getBoundingClientRect(),A=f.compositeWidth/2,P=f.compositeHeight/2,S=f.screenRect.x/2,I=f.screenRect.y/2,$=f.screenRect.width/2,le=f.screenRect.height/2;return wo({x:l.clientX,y:l.clientY},m,A,P,{x:S,y:I,width:$,height:le},J)},[f,J]),ot=s.useCallback(l=>{const y=Xe(l);return y?Wn(y):null},[Xe]),xe=s.useCallback(l=>{const y=J?ue.current:Q.current;if(!y)return null;const m=y.getBoundingClientRect();let A,P;if(J){const I=m.height-(l.clientY-m.top),$=l.clientX-m.left;A=I*(f.compositeWidth/m.height),P=$*(f.compositeHeight/m.width)}else A=(l.clientX-m.left)*(f.compositeWidth/m.width),P=(l.clientY-m.top)*(f.compositeHeight/m.height);const S=f.screenRect;return A>=S.x&&A<=S.x+S.width&&P>=S.y&&P<=S.y+S.height?null:$s(A,P,f.buttons,Fo)},[f,J]),Ge=s.useCallback(l=>{const y=F.current,m=Z.current;return y&&y.clientWidth>0?{x:y.offsetLeft+l.x*y.clientWidth,y:y.offsetTop+l.y*y.clientHeight}:{x:l.x*((m==null?void 0:m.width)??1),y:l.y*((m==null?void 0:m.height)??1)}},[Z]),Je=s.useCallback(l=>{if(ee(!0),ae.current){const S=ot(l);if(!S)return;re.current=!0,ke(!0),l.target.setPointerCapture(l.pointerId),he(S),r({type:"input:pinch:start",sessionId:e,payload:S});return}const y=xe(l);if(y){ge.current=y,rt(y),l.target.setPointerCapture(l.pointerId),r({type:"input:button",sessionId:e,requestId:X(),payload:{name:y,phase:"down"}});return}const m=Xe(l);if(!m)return;oe.current=m,l.target.setPointerCapture(l.pointerId),je.current=Ge(m),we.current="down",w.current=null;const A=l.currentTarget.getBoundingClientRect(),P=Pe.current;P&&(P.style.display="block",P.style.left=`${l.clientX-A.left}px`,P.style.top=`${l.clientY-A.top}px`,P.style.width=`${ut*2}px`,P.style.height=`${ut*2}px`,P.style.background="rgba(255,255,255,0.92)",P.style.border="1.5px solid rgba(0,0,0,0.2)",P.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:e,payload:m})},[xe,Xe,ot,Ge,r,e]),at=s.useCallback(l=>{if(l.buttons===0){if(fe(xe(l)),ae.current){he(ot(l)),je.current=null;const I=Pe.current;I&&(I.style.display="none")}else{he(null);const I=Xe(l);je.current=I?Ge(I):null,we.current!=="down"&&(we.current="idle");const $=Pe.current;if($)if(I){const le=l.currentTarget.getBoundingClientRect();$.style.display="block",$.style.left=`${l.clientX-le.left}px`,$.style.top=`${l.clientY-le.top}px`,$.style.width=`${ze*2}px`,$.style.height=`${ze*2}px`,$.style.background="transparent",$.style.border="1.5px solid rgba(255,255,255,0.6)",$.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"}else $.style.display="none"}return}if(re.current){const I=ot(l);if(!I)return;const $=performance.now();if($-_e.current<yn)return;_e.current=$,he(I),r({type:"input:pinch:move",sessionId:e,payload:I});return}if(ge.current||!oe.current)return;const y=Xe(l);if(!y)return;const m=y.x-oe.current.x,A=y.y-oe.current.y;if(Math.sqrt(m*m+A*A)<Bo)return;const P=performance.now();if(P-_e.current<yn)return;_e.current=P,je.current=Ge(y);const S=Pe.current;if(S&&S.style.display!=="none"){const I=l.currentTarget.getBoundingClientRect();S.style.left=`${l.clientX-I.left}px`,S.style.top=`${l.clientY-I.top}px`}r({type:"input:touch:move",sessionId:e,payload:y})},[xe,Xe,ot,Ge,r,e]),$t=s.useCallback(()=>{if(re.current){re.current=!1,ke(!1),he(null),r({type:"input:pinch:end",sessionId:e,requestId:X()});return}if(oe.current=null,ge.current){r({type:"input:button",sessionId:e,requestId:X(),payload:{name:ge.current,phase:"up"}}),ge.current=null,setTimeout(()=>rt(null),100);return}we.current="release",w.current={startTime:performance.now()};const l=Pe.current;l&&(l.style.width=`${ze*2}px`,l.style.height=`${ze*2}px`,l.style.background="transparent",l.style.border="1.5px solid rgba(255,255,255,0.6)",l.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:e,requestId:X()})},[r,e]),Qe=s.useCallback(()=>{if(re.current){re.current=!1,ke(!1),he(null),r({type:"input:pinch:end",sessionId:e,requestId:X()});return}if(oe.current=null,ge.current){r({type:"input:button",sessionId:e,requestId:X(),payload:{name:ge.current,phase:"up"}}),ge.current=null,rt(null);return}we.current="release",w.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:e,requestId:X()})},[r,e]),Bt=s.useCallback(()=>{fe(null),he(null),je.current=null;const l=Pe.current;l&&(l.style.display="none")},[]),Ft=f.compositeWidth/2,vt=f.compositeHeight/2,wt=Ro(vt,750),it=Math.round(Ft*wt),ct=Math.round(vt*wt),lt=f.screenRect.x/f.compositeWidth*100,mt=f.screenRect.y/f.compositeHeight*100,gt=f.screenRect.width/f.compositeWidth*100,xt=f.screenRect.height/f.compositeHeight*100,R=Math.round(f.screenCornerRadius/2*wt),D=n.jsx(n.Fragment,{children:n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":"Home",onClick:()=>r({type:"input:button",sessionId:e,requestId:X(),payload:{name:"home"}}),children:n.jsx(Ln,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsxs("span",{className:"flex items-center gap-3",children:["Home ",n.jsxs(qt,{children:[n.jsx(ft,{children:"⌘"}),n.jsx(ft,{children:"⇧"}),n.jsx(ft,{children:"U"})]})]})})]})}),W=s.useId(),_=n.jsxs(n.Fragment,{children:[n.jsx("span",{id:W,role:"status",className:"sr-only",children:E?"Changing the software keyboard.":N?"The software keyboard is up.":"The software keyboard is down."}),n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":E?"Software keyboard — changing it":"Software keyboard","aria-pressed":N,"aria-busy":E,"aria-disabled":E,"aria-describedby":W,onClick:()=>{E||M()},"data-active":N,children:E?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(ls,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:E?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(ft,{children:"⌘"}),n.jsx(ft,{children:"⇧"}),n.jsx(ft,{children:"K"})]})]})})]})]}),se=h&&t?n.jsxs(Ce,{children:[n.jsx(Te,{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(Ee,{side:"left",children:x?"Launching…":"Launch app"})]}):null;return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:Z,style:{display:"none"}}),n.jsx(zn,{open:Me,onOpenChange:Ue,openUrl:o}),n.jsx(Bn,{joined:c,onDeepLink:()=>Ue(!0),onScreenshot:V,onRecordToggle:me,recordState:ye,onRotate:qe,navigationSlot:D,deviceSlot:_,launchSlot:se,network:L?{position:st.position,steerable:st.steerable,reason:st.reason,pending:st.pending,onToggle:st.toggle}:void 0,reboot:{pending:k,onReboot:B,buttonRef:G}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsxs("div",{ref:ue,style:{width:J?ct:it,height:J?it:ct,position:"relative",flexShrink:0},children:[n.jsxs("div",{ref:Q,className:`relative ${Ve?"cursor-pointer":"cursor-default"}`,style:{width:it,height:ct,...J?{position:"absolute",top:(it-ct)/2,left:(ct-it)/2,transform:"rotate(-90deg)",transformOrigin:"center center"}:{}},onPointerDown:Je,onPointerMove:at,onPointerUp:$t,onPointerCancel:Qe,onPointerLeave:Bt,children:[n.jsx("img",{src:`data:image/png;base64,${f.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:F,style:{position:"absolute",zIndex:3,left:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,borderRadius:R>0?`${R}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:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,borderRadius:R>0?`${R}px`:void 0}}),Y&&(()=>{const l=lt/100,y=mt/100,m=gt/100,A=xt/100,P=(S,I)=>({left:`${(l+S*m)*100}%`,top:`${(y+I*A)*100}%`});return n.jsx(n.Fragment,{children:[Y.f0,Y.f1].map((S,I)=>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",...ve?{width:ut*2,height:ut*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:ze*2,height:ze*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(S.x,S.y)}},I))})})(),c&&Ie===0&&n.jsx("div",{style:{position:"absolute",zIndex:8,left:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n.jsx("span",{style:{color:"white",fontSize:"0.875rem"},children:"Waiting for first frame..."})}),f.buttons.map(l=>{const y=We===l.name,m=Ve===l.name,A=l.anchor==="top",P=Mn(l),S=P.top/f.compositeHeight*100,I=l.buttonH/f.compositeHeight*100,$=l.buttonW/f.compositeWidth*100,le=l.buttonW/2,De=P.left/f.compositeWidth*100,Be=(2*l.rolloverOffset.x-l.normalOffset.x-le)/f.compositeWidth*100,Ze=l.rolloverOffset.x/f.compositeWidth*100,At=S,bt=A?(2*l.rolloverOffset.y-l.normalOffset.y)/f.compositeHeight*100:0,pr=l.onTop?4:1;return n.jsxs(s.Fragment,{children:[l.buttonPng&&n.jsx("img",{src:`data:image/png;base64,${l.buttonPng}`,style:{position:"absolute",zIndex:pr,top:`${A&&m?bt:S}%`,left:`${A?De:m?Be:De}%`,width:`${$}%`,height:`${I}%`,transition:A?"top 0.15s ease":"left 0.15s ease",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),y&&l.pressedPng&&l.pressedRect&&n.jsx("img",{src:`data:image/png;base64,${l.pressedPng}`,style:{position:"absolute",zIndex:l.onTop?3:1,left:`${A?De:m?Be:De}%`,top:`${A&&m?bt:S}%`,width:`${l.pressedRect.width/f.compositeWidth*100}%`,height:`${l.pressedRect.height/f.compositeHeight*100}%`,pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),m&&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:`${Ze}%`,top:`${At}%`,transform:"translate(-50%, calc(-100% - 8px))"},children:l.accessibilityTitle})]},l.name)})]}),n.jsx("div",{ref:Pe,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:c,fps:Ie,connected:a,deviceReady:u,bootError:g,installing:d,installError:p,decoderUnsupported:K,keyboardActive:de})]})]})}const dt=13,kt=8,vn=16,Ho=.02,zt=720;function zo({sessionId:e,buildId:t,send:r,openUrl:o,launchApp:i,connected:a,joined:c,deviceReady:u,installing:d,installed:h,installError:p,bootError:g,launching:x,androidButtons:f,binaryFrameHandlerRef:b,clipboardHandlerRef:v,clipboardSupported:T,networkHandlerRef:j,networkSupported:L,onRecordingUploaded:C,rebootPending:N,onReboot:E,restartButtonRef:M,screenWidth:k,screenHeight:B,cornerRadius:G,perfHookRef:z}){const F=s.useRef(null),Q=s.useRef(null),ue=s.useRef(null),{fps:Ie,frameCount:Fe}=$n(),{recordState:be,recordCanvasRef:ye,startClientRecording:Z,stopClientRecording:Ae}=Un({sessionId:e,buildId:t,onRecordingUploaded:C}),[Oe,He]=s.useState(!1),[Me,Ue]=s.useState(!1),[U,q]=s.useState(!1),K=s.useRef(null),[Se,J]=s.useState(null),[Re,de]=s.useState(!1),[ee,We]=s.useState(!1),[rt,Ve]=s.useState(!1),[fe,ve]=s.useState(null),ke=s.useRef(fe);s.useEffect(()=>{ke.current=fe},[fe]);const Y=s.useRef(!1),he=s.useRef(!1),$e=s.useRef(null),ge=s.useRef(0),oe=s.useRef(null),re=s.useRef(null),ae=s.useRef("idle"),_e=s.useRef(null);qn({binaryFrameHandlerRef:b,perfHookRef:z,frameCount:Fe,onUnsupported:()=>q(!0),onResize:R=>{Ue(!0);const D=K.current;(!D||D.width!==R.width||D.height!==R.height)&&(K.current=R,J(R))},onDecoderReady:R=>{var W;ue.current=R;const D=R.surface;D.style.display="block",D.style.width="100%",D.style.height="100%",D.style.objectFit="fill",(W=F.current)==null||W.appendChild(D)}});const Pe=s.useCallback(()=>{var le;const R=ye.current,D=(le=ue.current)==null?void 0:le.surface,W=K.current;if(!R||!D||!W)return;const _=R.getContext("2d");if(!_)return;const se=W.width,l=W.height,y=R.width>R.height!=se>l;_.save(),y&&(_.translate(R.width,0),_.rotate(Math.PI/2)),_.drawImage(D,0,0,se,l);const m=Math.max(se,l),A=m>zt?m/zt:1,P=dt*A,S=kt*A,I=ke.current;if(I)for(const De of[I.f0,I.f1]){const Be=De.x*se,Ze=De.y*l;Y.current?(_.beginPath(),_.arc(Be,Ze,S,0,Math.PI*2),_.fillStyle="rgba(255,255,255,0.92)",_.fill(),_.strokeStyle="rgba(0,0,0,0.2)",_.lineWidth=A,_.stroke()):(_.beginPath(),_.arc(Be,Ze,P,0,Math.PI*2),_.strokeStyle="rgba(0,0,0,0.3)",_.lineWidth=3*A,_.stroke(),_.beginPath(),_.arc(Be,Ze,P,0,Math.PI*2),_.strokeStyle="rgba(255,255,255,0.65)",_.lineWidth=1.5*A,_.stroke())}const $=re.current;if($){const De=$.x*se,Be=$.y*l,Ze=ae.current,At=_e.current;if(Ze==="down")_.beginPath(),_.arc(De,Be,S,0,Math.PI*2),_.fillStyle="rgba(255,255,255,0.92)",_.fill(),_.strokeStyle="rgba(0,0,0,0.2)",_.lineWidth=A,_.stroke();else if(Ze==="release"&&At){const bt=Math.min((performance.now()-At.startTime)/350,1);_.beginPath(),_.arc(De,Be,S+26*A*bt,0,Math.PI*2),_.strokeStyle=`rgba(255,255,255,${(1-bt)*.55})`,_.lineWidth=1.5*A,_.stroke(),bt>=1&&(ae.current="idle",_e.current=null)}else _.beginPath(),_.arc(De,Be,P,0,Math.PI*2),_.strokeStyle="rgba(0,0,0,0.3)",_.lineWidth=3*A,_.stroke(),_.beginPath(),_.arc(De,Be,P,0,Math.PI*2),_.strokeStyle="rgba(255,255,255,0.65)",_.lineWidth=1.5*A,_.stroke()}_.restore()},[ye]),je=s.useCallback(()=>{var se;const R=(se=ue.current)==null?void 0:se.surface,D=K.current;if(!R||!D)return;const W=document.createElement("canvas"),_=W.getContext("2d");_&&(W.width=D.width,W.height=D.height,_.drawImage(R,0,0,D.width,D.height),W.toBlob(l=>{if(!l)return;const y=URL.createObjectURL(l),m=document.createElement("a");m.href=y,m.download=`tapflow-${Date.now()}.png`,m.click(),URL.revokeObjectURL(y)},"image/png"))},[]),we=s.useCallback(()=>{if(be==="idle"){const R=ye.current;if(!R)return;const D=K.current;if(!D)return;const W=V.current;R.width=W?D.height:D.width,R.height=W?D.width:D.height,Z(Pe)}else be==="recording"&&Ae()},[be,Z,Ae,Pe,ye]),w=s.useCallback(()=>{r({type:"input:rotate",sessionId:e}),de(R=>!R)},[r,e]),H=s.useRef(Re);s.useEffect(()=>{H.current=Re},[Re]),s.useEffect(()=>()=>{H.current&&r({type:"input:rotate",sessionId:e})},[]);const ce=s.useCallback((R,D)=>{r({type:"input:key",sessionId:e,requestId:X(),payload:{code:R,modifiers:D}})},[r,e]);Xn({sessionId:e,send:r,active:ee,supported:T,handlerRef:v,sendChord:ce,onError:R=>Ne.error(R)});const pe=Fn({sessionId:e,send:r,supported:L,deviceReady:u,handlerRef:j,onError:R=>Ne.error(R)});s.useEffect(()=>{const R=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),D=l=>{if(l.code==="AltLeft"||l.code==="AltRight"){he.current=!0;return}if(l.metaKey){const m=document.activeElement;if(!m||m.tagName!=="INPUT"&&m.tagName!=="TEXTAREA"){if(!l.shiftKey&&l.code==="KeyK"){l.preventDefault(),He(!0);return}if(!l.shiftKey&&l.code==="KeyS"){l.preventDefault(),je();return}if(l.shiftKey&&l.code==="KeyY"){l.preventDefault(),we();return}if(l.shiftKey&&l.code==="KeyO"){l.preventDefault(),w();return}}}if(!ee||R.has(l.code)||T&&Zt(l))return;l.preventDefault();const y=(l.shiftKey?2:0)|(l.ctrlKey?1:0)|(l.metaKey?8:0);r({type:"input:key",sessionId:e,requestId:X(),payload:{code:l.code,modifiers:y}})},W=()=>{Y.current&&(Y.current=!1,Ve(!1),r({type:"input:pinch:end",sessionId:e,requestId:X()})),he.current=!1,ve(null)},_=l=>{(l.code==="AltLeft"||l.code==="AltRight")&&W()},se=()=>{he.current&&W()};return window.addEventListener("keydown",D),window.addEventListener("keyup",_),window.addEventListener("blur",se),()=>{window.removeEventListener("keydown",D),window.removeEventListener("keyup",_),window.removeEventListener("blur",se)}},[ee,T,r,e,je,we,w]),s.useEffect(()=>{if(!ee)return;const R=D=>{const W=Q.current??F.current;W&&!W.contains(D.target)&&We(!1)};return document.addEventListener("pointerdown",R),()=>document.removeEventListener("pointerdown",R)},[ee]);const V=s.useRef(!1),me=s.useCallback(R=>{const D=F.current;if(!D)return null;const W=D.getBoundingClientRect();return So({x:R.clientX,y:R.clientY},W,V.current)},[]),qe=s.useCallback(R=>{const D=me(R);return D?Wn(D):null},[me]),Nt=s.useCallback(R=>{if(he.current){const se=qe(R);if(!se)return;Y.current=!0,Ve(!0),R.target.setPointerCapture(R.pointerId);const l=oe.current;l&&(l.style.display="none"),ve(se),r({type:"input:pinch:start",sessionId:e,payload:se});return}const D=me(R);if(!D)return;We(!0),$e.current=D,R.target.setPointerCapture(R.pointerId);const W=R.currentTarget.getBoundingClientRect();re.current=D,ae.current="down",_e.current=null;const _=oe.current;_&&(_.style.display="block",_.style.left=`${R.clientX-W.left}px`,_.style.top=`${R.clientY-W.top}px`,_.style.width=`${kt*2}px`,_.style.height=`${kt*2}px`,_.style.background="rgba(255,255,255,0.92)",_.style.border="1.5px solid rgba(0,0,0,0.2)",_.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:e,payload:D})},[me,qe,r,e]),Ut=s.useCallback(R=>{if(R.buttons===0){if(he.current){ve(qe(R)),re.current=null;const S=oe.current;S&&(S.style.display="none");return}const m=me(R),A=R.currentTarget.getBoundingClientRect(),P=oe.current;m?(re.current=m,ae.current!=="down"&&(ae.current="idle"),P&&(P.style.display="block",P.style.left=`${R.clientX-A.left}px`,P.style.top=`${R.clientY-A.top}px`,P.style.width=`${dt*2}px`,P.style.height=`${dt*2}px`,P.style.background="transparent",P.style.border="1.5px solid rgba(255,255,255,0.6)",P.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)")):(re.current=null,P&&(P.style.display="none"));return}if(Y.current){const m=qe(R);if(!m)return;const A=performance.now();if(A-ge.current<vn)return;ge.current=A,ve(m),r({type:"input:pinch:move",sessionId:e,payload:m});return}if(!$e.current)return;const D=me(R);if(!D)return;const W=D.x-$e.current.x,_=D.y-$e.current.y;if(Math.sqrt(W*W+_*_)<Ho)return;const se=performance.now();if(se-ge.current<vn)return;ge.current=se;const l=R.currentTarget.getBoundingClientRect();re.current=D;const y=oe.current;y&&y.style.display!=="none"&&(y.style.left=`${R.clientX-l.left}px`,y.style.top=`${R.clientY-l.top}px`),r({type:"input:touch:move",sessionId:e,payload:D})},[me,qe,r,e]),st=s.useCallback(()=>{if(Y.current){Y.current=!1,Ve(!1),ve(null),r({type:"input:pinch:end",sessionId:e,requestId:X()});return}$e.current=null,ae.current="release",_e.current={startTime:performance.now()};const R=oe.current;R&&(R.style.width=`${dt*2}px`,R.style.height=`${dt*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:e,requestId:X()})},[r,e]),Xe=s.useCallback(()=>{if(Y.current){Y.current=!1,Ve(!1),ve(null),r({type:"input:pinch:end",sessionId:e,requestId:X()});return}$e.current=null,ae.current="release",_e.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:e,requestId:X()})},[r,e]),ot=s.useCallback(()=>{ve(null),re.current=null;const R=oe.current;R&&(R.style.display="none")},[]),xe=Se??(k&&B?{width:k,height:B}:null),Ge=xe?Math.min(1,zt/Math.max(xe.width,xe.height)):.3,Je=xe?Math.round(xe.width*Ge):324,at=xe?Math.round(xe.height*Ge):720,$t=xe?xe.width>xe.height:!1,Qe=Re&&!$t;s.useLayoutEffect(()=>{V.current=Qe},[Qe]);const Bt=Qe?at:Je,Ft=Qe?Je:at,vt=G!=null?Math.round(G*Je):22,cn=Qe?{position:"absolute",width:Je,height:at,top:(Je-at)/2,left:(at-Je)/2,transform:"rotate(90deg)",transformOrigin:"center center",visibility:Me?"visible":"hidden",cursor:"none"}:{visibility:Me?"visible":"hidden",cursor:"none"},wt=["home","back","recent_apps"],it=["volume_up","volume_down","power"],ct=R=>R==="back"?n.jsx(Gr,{className:"h-4 w-4"}):R==="recent_apps"?n.jsx(mr,{className:"h-4 w-4"}):R==="volume_up"?n.jsx(Ps,{className:"h-4 w-4"}):R==="volume_down"?n.jsx(As,{className:"h-4 w-4"}):R==="power"?n.jsx(ms,{className:"h-4 w-4"}):n.jsx(Ln,{className:"h-4 w-4"}),lt=R=>n.jsx(n.Fragment,{children:R.map(D=>f==null?void 0:f.find(W=>W.name===D)).filter(D=>D!==void 0).map(D=>n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":D.accessibilityTitle,onClick:()=>r({type:"input:button",sessionId:e,requestId:X(),payload:{name:D.name}}),children:ct(D.name)})}),n.jsx(Ee,{side:"left",children:D.accessibilityTitle})]},D.name))}),mt=lt(wt),gt=lt(it),xt=h&&t?n.jsxs(Ce,{children:[n.jsx(Te,{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(Ee,{side:"left",children:x?"Launching…":d?"Installing…":"Launch app"})]}):null;return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:ye,style:{display:"none"}}),n.jsx(zn,{open:Oe,onOpenChange:He,openUrl:o}),n.jsx(Bn,{joined:c,onDeepLink:()=>He(!0),onScreenshot:je,onRecordToggle:we,recordState:be,onRotate:w,navigationSlot:mt,deviceSlot:gt,launchSlot:xt,network:L?{position:pe.position,steerable:pe.steerable,reason:pe.reason,pending:pe.pending,onToggle:pe.toggle}:void 0,reboot:{pending:N,onReboot:E,buttonRef:M}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{style:{background:"#1c1c1e",borderRadius:`${vt+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:Q,className:"relative",style:{width:Bt,height:Ft,backgroundColor:"#010101",borderRadius:`${vt}px`,overflow:"hidden"},children:!U&&n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:F,className:Qe?void 0:"block w-full h-full",style:cn,onPointerDown:Nt,onPointerMove:Ut,onPointerUp:st,onPointerCancel:Xe,onPointerLeave:ot}),!Me&&n.jsx("div",{className:"absolute inset-0 animate-pulse bg-zinc-700"}),!Me&&u&&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: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"}}),fe&&n.jsx(n.Fragment,{children:[fe.f0,fe.f1].map((R,D)=>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}%`,...rt?{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:dt*2,height:dt*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"}}},D))})]})})}),n.jsx(Qt,{joined:c,fps:Ie,connected:a,deviceReady:u,bootError:g,installing:d,installError:p,decoderUnsupported:U,keyboardActive:ee})]})]})}function Wo(e,t){const r=new DataView(e),o=Math.floor(e.byteLength/2),i=Math.floor(o/t),a=[];for(let c=0;c<t;c++)a.push(new Float32Array(i));for(let c=0;c<i;c++)for(let u=0;u<t;u++){const d=r.getInt16((c*t+u)*2,!0);a[u][c]=d/32768}return a}const Vo=44100,Wt=2,wn=.06,qo=.3;function Xo(){const e=s.useRef(null),t=s.useRef(0),r=s.useCallback(()=>{if(e.current)return e.current;const i=window.AudioContext??window.webkitAudioContext;return i?(e.current=new i,e.current):null},[]),o=s.useCallback(i=>{var x;const a=r();if(!a)return;a.state==="suspended"&&a.resume();const c=Wo(i,Wt),u=((x=c[0])==null?void 0:x.length)??0;if(u===0)return;const d=a.createBuffer(Wt,u,Vo);for(let f=0;f<Wt;f++)d.getChannelData(f).set(c[f]);const h=a.createBufferSource();h.buffer=d,h.connect(a.destination);const p=a.currentTime;let g=t.current;(g<p+.005||g>p+qo+wn)&&(g=p+wn),h.start(g),t.current=g+d.duration},[r]);return s.useEffect(()=>()=>{var i;(i=e.current)==null||i.close(),e.current=null},[]),{pushFrame:o}}const Ko=2e4;function Yo({sessionId:e,deviceId:t,deviceReady:r,send:o,handlerRef:i,onShutdownComplete:a,onError:c}){const[u,d]=s.useState(!1),h=s.useRef(null),p=s.useRef(a),g=s.useRef(c);s.useEffect(()=>{p.current=a},[a]),s.useEffect(()=>{g.current=c},[c]),s.useEffect(()=>{d(!1),h.current=null},[e]),s.useEffect(()=>{r||(d(!1),h.current=null)},[r]),s.useEffect(()=>(i.current=v=>{if(v.requestId===h.current){if(h.current=null,d(!1),v.type==="device:shutdown-error"){g.current(`The device was not restarted. ${v.message}`);return}p.current()}},()=>{i.current=void 0}),[i]);const[x,f]=s.useState(null);s.useEffect(()=>{f(u?h.current:null)},[u]),s.useEffect(()=>{if(x===null)return;const v=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."))},Ko);return()=>clearTimeout(v)},[x]);const b=s.useCallback(()=>{if(u)return;const v=X();h.current=v,d(!0),o({type:"device:shutdown",sessionId:e,requestId:v,payload:{deviceId:t}})},[u,o,e,t]);return{pending:u,reboot:b}}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 Go(e){const t=e!==void 0&&Object.hasOwn(Sn,e)?e:"channel-unavailable";return{key:t,notice:Sn[t]}}function Jo({sessionId:e,deviceId:t,buildId:r,resetMode:o,onRecordingUploaded:i,onSessionEnded:a}){const c=s.useRef(()=>{}),u=s.useRef(!1),d=s.useRef({pending:0,appInstalled:!1});Ms();const h=s.useRef(null),p=s.useRef(null),g=s.useRef([]);s.useRef({onFrameBegin:()=>{var w;return(w=h.current)==null?void 0:w.onFrameBegin()},onFrameEnd:w=>{var pe,V;const H=g.current.shift()??null,ce=H?{...w,capturedAt:H.capturedAt,relayedAt:H.relayedAt}:w;(pe=h.current)==null||pe.onFrameEnd(ce),(V=p.current)==null||V.call(p,ce)}});const[x,f]=s.useState(!1),[b,v]=s.useState(!1),[T,j]=s.useState(!1),[L,C]=s.useState(null),[N,E]=s.useState(!1),[M,k]=s.useState(!1),[B,G]=s.useState(null),[z,F]=s.useState(null),[Q,ue]=s.useState(!1),[Ie,Fe]=s.useState([]),be=s.useRef(new Set),ye=s.useRef(null),Z=s.useRef(new Set),Ae=s.useRef(new Set),Oe=s.useRef(new Set),[He,Me]=s.useState(!1),Ue=8e3,[U,q]=s.useState(!1),K=s.useRef(null);s.useEffect(()=>()=>{K.current&&clearTimeout(K.current)},[]);const Se=s.useRef(void 0),J=s.useRef(void 0),Re=s.useRef(void 0),de=s.useRef(void 0),ee=s.useCallback(w=>{const H=X();be.current.add(H),ye.current=H,c.current({type:"device:boot",sessionId:e,requestId:H,payload:{deviceId:t,resetMode:w,acceptH264:po(),secureContext:window.isSecureContext}})},[e,t]),{pushFrame:We}=Xo(),rt=s.useCallback(w=>{var H,ce,pe;if(!("sessionId"in w&&w.sessionId!==e)){if(w.type==="session:joined"){d.current={pending:0,appInstalled:!1},f(!0),v(!1),Fe(w.capabilities??[]);const V=u.current?"app-only":o;u.current=!0,be.current.clear(),ee(V)}if(w.type==="session:agent-away"){v(!0),C(null),j(!1);return}if(w.type==="session:terminated"){a==null||a(w.reason);return}if(w.type==="session:rebound"){j(!1),C(null),E(!1),G(null),F(null),ue(!1),q(!1),K.current&&clearTimeout(K.current),Me(!1),g.current=[],Fe(w.capabilities);const V=b;v(!1),d.current={pending:d.current.pending+1,appInstalled:d.current.pending>0?d.current.appInstalled:M},u.current=!0,ee("app-only"),V||Ne.info("The agent restarted — reconnecting to the device.");return}if(w.type==="device:boot-error"){if(w.requestId!==void 0&&w.requestId!==ye.current||b)return;d.current={pending:0,appInstalled:!1},F(w.message)}if(w.type==="input:error"){if(b)return;const{key:V,notice:me}=Go(w.reason);w.reason!==void 0&&w.reason!==V&&console.debug(`[tapflow] unrecognised input:error reason "${w.reason}", treated as ${V}`),me?Ne.error(me.title,{id:`input:${e}:${V}`,description:w.message?`${me.action} (${w.message})`:me.action,duration:6e3}):console.debug(`[tapflow] input refused, shown nowhere: ${V}${w.message?` — ${w.message}`:""}`)}if(w.type==="device:booting"&&(j(!1),E(!1),k(!1),G(null),F(null),Ae.current.clear(),Oe.current.clear(),C(null)),w.type==="device:ready"){if(j(!0),w.requestId!==void 0&&!be.current.delete(w.requestId))return;if(d.current.pending>0){const{appInstalled:V}=d.current;if(d.current={pending:d.current.pending-1,appInstalled:V},V){k(!0);return}}if(r){E(!0);const V=X();Ae.current.add(V),c.current({type:"app:install",sessionId:e,requestId:V,buildId:r})}}if(w.type==="app:install-done"||w.type==="app:install-error"){if(!Ae.current.delete(w.requestId))return;E(!1),w.type==="app:install-done"?k(!0):G(w.message)}if(w.type==="app:launch-done"||w.type==="app:launch-error"){if(!Oe.current.delete(w.requestId))return;ue(!1)}if(w.type==="session:chrome"&&C(w.payload),w.type==="keyboard:toggled"){const{visible:V}=w.payload;Me(V),q(!1),K.current&&clearTimeout(K.current)}if(w.type==="network:state"||w.type==="network:error"){(H=Re.current)==null||H.call(Re,w);return}if(w.type==="device:shutdown-done"||w.type==="device:shutdown-error"){(ce=de.current)==null||ce.call(de,w);return}if((w.type==="clipboard:data"||w.type==="clipboard:write-done"||w.type==="clipboard:error")&&((pe=J.current)==null||pe.call(J,w)),w.type==="open-url:done"||w.type==="open-url:error"){if(!Z.current.delete(w.requestId))return;w.type==="open-url:done"?Ne.success("Deeplink opened"):Ne.error(w.message)}if(w.type==="error")switch(w.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}}},[e,r,a,o,M,b,ee]),Ve=s.useCallback(w=>{var V;const H=No(w);if(H&&H.codec===Vn){We(w.slice(Kt));return}H&&H.codec===It||g.current.push(H);const ce=H?w.slice(Kt):w,pe=H?{codec:H.codec,keyframe:H.keyframe,capturedAt:H.capturedAt,relayedAt:H.relayedAt}:void 0;(V=Se.current)==null||V.call(Se,ce,pe)},[We]),{send:fe,connected:ve}=Nn(rt,Ve);s.useLayoutEffect(()=>{c.current=fe}),s.useEffect(()=>{ve&&fe({type:"session:start",sessionId:e})},[ve,fe,e]);const ke=L!==null&&"framePng"in L?L:null,Y=L!==null&&!("framePng"in L)?L:null,he=()=>{q(!0),K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{q(!1),Ne.error("The device did not answer. The software keyboard is where it was, as far as tapflow can tell.")},Ue),fe({type:"input:keyboard:toggle",sessionId:e})},$e=s.useCallback(w=>{const H=X();Z.current.add(H),c.current({type:"open-url",sessionId:e,requestId:H,payload:{url:w}})},[e]),ge=s.useCallback(()=>{if(r===void 0)return;const w=X();Oe.current.add(w),ue(!0),c.current({type:"app:launch",sessionId:e,requestId:w,buildId:r})},[e,r]),oe=s.useRef(null),re=s.useRef(!1),ae=s.useRef(!1),{pending:_e,reboot:Pe}=Yo({sessionId:e,deviceId:t,deviceReady:T,send:fe,handlerRef:de,onShutdownComplete:s.useCallback(()=>{ae.current=!0,ee("app-only")},[ee]),onError:s.useCallback(w=>{Ne.error(w)},[])});s.useEffect(()=>{var ce;const w=!!(ke??Y),H=!re.current&&w;re.current=w,!(!H||!ae.current)&&(ae.current=!1,document.activeElement===document.body&&((ce=oe.current)==null||ce.focus()))},[ke,Y]),s.useEffect(()=>{(z||b)&&(ae.current=!1)},[z,b]);const je={sessionId:e,buildId:r,send:fe,openUrl:$e,launchApp:ge,connected:ve,joined:x,deviceReady:T,installing:N,installed:M,installError:B,bootError:z,launching:Q,binaryFrameHandlerRef:Se,clipboardHandlerRef:J,clipboardSupported:Ie.includes("clipboard"),networkHandlerRef:Re,networkSupported:Ie.includes("network-control"),onRecordingUploaded:i,swKeyboardVisible:He,swKeyboardPending:U,onKbdToggle:he,rebootPending:_e,onReboot:Pe,restartButtonRef:oe};if(!ke&&!Y)return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",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((w,H)=>n.jsx("div",{className:"h-8 w-8 rounded-md bg-muted animate-pulse"},H))}),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:ve,deviceReady:T,bootError:z,installing:N,installError:B,decoderUnsupported:!1,keyboardActive:!1,agentAway:b})]})]});const we=void 0;return n.jsxs(n.Fragment,{children:[ke&&n.jsx(Oo,{...je,chrome:ke,perfHookRef:we}),Y&&n.jsx(zo,{...je,androidButtons:Y.buttons,screenWidth:Y.screenWidth,screenHeight:Y.screenHeight,cornerRadius:Y.cornerRadius,perfHookRef:we}),!1]})}const Kn=s.forwardRef(({className:e,...t},r)=>n.jsx("textarea",{className:te("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",e),ref:r,...t}));Kn.displayName="Textarea";var Qo=Object.defineProperty,O=(e,t)=>Qo(e,"name",{value:t,configurable:!0});function Yn(e,t){return s.useReducer((r,o)=>t[r][o]??r,e)}O(Yn,"useStateMachine");var Gn="ScrollArea",[Jn,qa]=Tn(Gn),[Zo,Le]=Jn(Gn),ea=s.forwardRef(O(function(t,r){const{__scopeScrollArea:o,type:i="hover",dir:a,scrollHideDelay:c=600,...u}=t,[d,h]=s.useState(null),[p,g]=s.useState(null),[x,f]=s.useState(null),[b,v]=s.useState(null),[T,j]=s.useState(null),[L,C]=s.useState(0),[N,E]=s.useState(0),[M,k]=s.useState(!1),[B,G]=s.useState(!1),z=tt(r,h),F=xr(a);return n.jsx(Zo,{scope:o,type:i,dir:F,scrollHideDelay:c,scrollArea:d,viewport:p,onViewportChange:g,content:x,onContentChange:f,scrollbarX:b,onScrollbarXChange:v,scrollbarXEnabled:M,onScrollbarXEnabledChange:k,scrollbarY:T,onScrollbarYChange:j,scrollbarYEnabled:B,onScrollbarYEnabledChange:G,onCornerWidthChange:C,onCornerHeightChange:E,children:n.jsx(nt.div,{dir:F,...u,ref:z,style:{position:"relative","--radix-scroll-area-corner-width":L+"px","--radix-scroll-area-corner-height":N+"px",...t.style}})})},"ScrollArea")),ta="ScrollAreaViewport",na=s.forwardRef(O(function(t,r){const{__scopeScrollArea:o,children:i,nonce:a,...c}=t,u=Le(ta,o),d=s.useRef(null),h=tt(r,d,u.onViewportChange);return n.jsxs(n.Fragment,{children:[n.jsx(ra,{nonce:a}),n.jsx(nt.div,{"data-radix-scroll-area-viewport":"",...c,ref:h,style:{overflowX:u.scrollbarXEnabled?"scroll":"hidden",overflowY:u.scrollbarYEnabled?"scroll":"hidden",...t.style},children:n.jsx("div",{ref:u.onContentChange,style:{minWidth:"100%",display:"table"},children:i})})]})},"ScrollAreaViewport")),ra=s.memo(O(function({nonce:t}){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:t})},"ScrollAreaViewportStyle"),(e,t)=>e.nonce===t.nonce),Ye="ScrollAreaScrollbar",Qn=s.forwardRef(O(function(t,r){const{forceMount:o,...i}=t,a=Le(Ye,t.__scopeScrollArea),{onScrollbarXEnabledChange:c,onScrollbarYEnabledChange:u}=a,d=t.orientation==="horizontal";return s.useEffect(()=>(d?c(!0):u(!0),()=>{d?c(!1):u(!1)}),[d,c,u]),a.type==="hover"?n.jsx(sa,{...i,ref:r,forceMount:o}):a.type==="scroll"?n.jsx(oa,{...i,ref:r,forceMount:o}):a.type==="auto"?n.jsx(Zn,{...i,ref:r,forceMount:o}):a.type==="always"?n.jsx(en,{...i,ref:r,"data-state":"visible"}):null},"ScrollAreaScrollbar")),sa=s.forwardRef(O(function(t,r){const{forceMount:o,...i}=t,a=Le(Ye,t.__scopeScrollArea),[c,u]=s.useState(!1);return s.useEffect(()=>{const d=a.scrollArea;let h=0;if(d){const p=O(()=>{window.clearTimeout(h),u(!0)},"handlePointerEnter"),g=O(()=>{h=window.setTimeout(()=>u(!1),a.scrollHideDelay)},"handlePointerLeave");return d.addEventListener("pointerenter",p),d.addEventListener("pointerleave",g),()=>{window.clearTimeout(h),d.removeEventListener("pointerenter",p),d.removeEventListener("pointerleave",g)}}},[a.scrollArea,a.scrollHideDelay]),n.jsx(Mt,{present:o||c,children:n.jsx(Zn,{"data-state":c?"visible":"hidden",...i,ref:r})})},"ScrollAreaScrollbarHover")),oa=s.forwardRef(O(function(t,r){const{forceMount:o,...i}=t,a=Le(Ye,t.__scopeScrollArea),c=t.orientation==="horizontal",u=Et(()=>h("SCROLL_END"),100),[d,h]=Yn("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 p=window.setTimeout(()=>h("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(p)}},[d,a.scrollHideDelay,h]),s.useEffect(()=>{const p=a.viewport,g=c?"scrollLeft":"scrollTop";if(p){let x=p[g];const f=O(()=>{const b=p[g];x!==b&&(h("SCROLL"),u()),x=b},"handleScroll");return p.addEventListener("scroll",f),()=>p.removeEventListener("scroll",f)}},[a.viewport,c,h,u]),n.jsx(Mt,{present:o||d!=="hidden",children:n.jsx(en,{"data-state":d==="hidden"?"hidden":"visible",...i,ref:r,onPointerEnter:Ke(t.onPointerEnter,()=>h("POINTER_ENTER")),onPointerLeave:Ke(t.onPointerLeave,()=>h("POINTER_LEAVE"))})})},"ScrollAreaScrollbarScroll")),Zn=s.forwardRef(O(function(t,r){const o=Le(Ye,t.__scopeScrollArea),{forceMount:i,...a}=t,[c,u]=s.useState(!1),d=t.orientation==="horizontal",h=Et(()=>{if(o.viewport){const p=o.viewport.offsetWidth<o.viewport.scrollWidth,g=o.viewport.offsetHeight<o.viewport.scrollHeight;u(d?p:g)}},10);return pt(o.viewport,h),pt(o.content,h),n.jsx(Mt,{present:i||c,children:n.jsx(en,{"data-state":c?"visible":"hidden",...a,ref:r})})},"ScrollAreaScrollbarAuto")),en=s.forwardRef(O(function(t,r){const{orientation:o="vertical",...i}=t,a=Le(Ye,t.__scopeScrollArea),c=s.useRef(null),u=s.useRef(0),[d,h]=s.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),p=tn(d.viewport,d.content),g={...i,sizes:d,onSizesChange:h,hasThumb:p>0&&p<1,onThumbChange:O(f=>c.current=f,"onThumbChange"),onThumbPointerUp:O(()=>u.current=0,"onThumbPointerUp"),onThumbPointerDown:O(f=>u.current=f,"onThumbPointerDown")};function x(f,b){return rr(f,u.current,d,b)}return O(x,"getScrollPosition"),o==="horizontal"?n.jsx(aa,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&c.current){const f=a.viewport.scrollLeft,b=Gt(f,d,a.dir);c.current.style.transform=`translate3d(${b}px, 0, 0)`}},onWheelScroll:f=>{a.viewport&&(a.viewport.scrollLeft=f)},onDragScroll:f=>{a.viewport&&(a.viewport.scrollLeft=x(f,a.dir))}}):o==="vertical"?n.jsx(ia,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&c.current){const f=a.viewport.scrollTop,b=Gt(f,d);c.current.style.transform=`translate3d(0, ${b}px, 0)`}},onWheelScroll:f=>{a.viewport&&(a.viewport.scrollTop=f)},onDragScroll:f=>{a.viewport&&(a.viewport.scrollTop=x(f))}}):null},"ScrollAreaScrollbarVisible")),aa=s.forwardRef(O(function(t,r){const{sizes:o,onSizesChange:i,...a}=t,c=Le(Ye,t.__scopeScrollArea),[u,d]=s.useState(),h=s.useRef(null),p=tt(r,h,c.onScrollbarXChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(tr,{"data-orientation":"horizontal",...a,ref:p,sizes:o,style:{bottom:0,left:c.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:c.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Tt(o)+"px",...t.style},onThumbPointerDown:g=>t.onThumbPointerDown(g.x),onDragScroll:g=>t.onDragScroll(g.x),onWheelScroll:(g,x)=>{if(c.viewport){const f=c.viewport.scrollLeft+g.deltaX;t.onWheelScroll(f),rn(f,x)&&g.preventDefault()}},onResize:()=>{h.current&&c.viewport&&u&&i({content:c.viewport.scrollWidth,viewport:c.viewport.offsetWidth,scrollbar:{size:h.current.clientWidth,paddingStart:Ct(u.paddingLeft),paddingEnd:Ct(u.paddingRight)}})}})},"ScrollAreaScrollbarX")),ia=s.forwardRef(O(function(t,r){const{sizes:o,onSizesChange:i,...a}=t,c=Le(Ye,t.__scopeScrollArea),[u,d]=s.useState(),h=s.useRef(null),p=tt(r,h,c.onScrollbarYChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(tr,{"data-orientation":"vertical",...a,ref:p,sizes:o,style:{top:0,right:c.dir==="ltr"?0:void 0,left:c.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Tt(o)+"px",...t.style},onThumbPointerDown:g=>t.onThumbPointerDown(g.y),onDragScroll:g=>t.onDragScroll(g.y),onWheelScroll:(g,x)=>{if(c.viewport){const f=c.viewport.scrollTop+g.deltaY;t.onWheelScroll(f),rn(f,x)&&g.preventDefault()}},onResize:()=>{h.current&&c.viewport&&u&&i({content:c.viewport.scrollHeight,viewport:c.viewport.offsetHeight,scrollbar:{size:h.current.clientHeight,paddingStart:Ct(u.paddingTop),paddingEnd:Ct(u.paddingBottom)}})}})},"ScrollAreaScrollbarY")),[ca,er]=Jn(Ye),tr=s.forwardRef(O(function(t,r){const{__scopeScrollArea:o,sizes:i,hasThumb:a,onThumbChange:c,onThumbPointerUp:u,onThumbPointerDown:d,onThumbPositionChange:h,onDragScroll:p,onWheelScroll:g,onResize:x,...f}=t,b=Le(Ye,o),[v,T]=s.useState(null),j=tt(r,T),L=s.useRef(null),C=s.useRef(""),N=b.viewport,E=i.content-i.viewport,M=ht(g),k=ht(h),B=Et(x,10);function G(z){if(L.current){const F=z.clientX-L.current.left,Q=z.clientY-L.current.top;p({x:F,y:Q})}}return O(G,"handleDragScroll"),s.useEffect(()=>{const z=O(F=>{const Q=F.target;(v==null?void 0:v.contains(Q))&&M(F,E)},"handleWheel");return document.addEventListener("wheel",z,{passive:!1}),()=>document.removeEventListener("wheel",z,{passive:!1})},[N,v,E,M]),s.useEffect(k,[i,k]),pt(v,B),pt(b.content,B),n.jsx(ca,{scope:o,scrollbar:v,hasThumb:a,onThumbChange:ht(c),onThumbPointerUp:ht(u),onThumbPositionChange:k,onThumbPointerDown:ht(d),children:n.jsx(nt.div,{...f,ref:j,style:{position:"absolute",...f.style},onPointerDown:Ke(t.onPointerDown,z=>{z.button===0&&(z.target.setPointerCapture(z.pointerId),L.current=v.getBoundingClientRect(),C.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",b.viewport&&(b.viewport.style.scrollBehavior="auto"),G(z))}),onPointerMove:Ke(t.onPointerMove,G),onPointerUp:Ke(t.onPointerUp,z=>{const F=z.target;F.hasPointerCapture(z.pointerId)&&F.releasePointerCapture(z.pointerId),document.body.style.webkitUserSelect=C.current,b.viewport&&(b.viewport.style.scrollBehavior=""),L.current=null})})})},"ScrollAreaScrollbarImpl")),Yt="ScrollAreaThumb",la=s.forwardRef(O(function(t,r){const{forceMount:o,...i}=t,a=er(Yt,t.__scopeScrollArea);return n.jsx(Mt,{present:o||a.hasThumb,children:n.jsx(ua,{ref:r,...i})})},"ScrollAreaThumb")),ua=s.forwardRef(O(function(t,r){const{__scopeScrollArea:o,style:i,...a}=t,c=Le(Yt,o),u=er(Yt,o),{onThumbPositionChange:d}=u,h=tt(r,u.onThumbChange),p=s.useRef(void 0),g=Et(()=>{p.current&&(p.current(),p.current=void 0)},100);return s.useEffect(()=>{const x=c.viewport;if(x){const f=O(()=>{if(g(),!p.current){const b=ha(x,d);p.current=b,d()}},"handleScroll");return d(),x.addEventListener("scroll",f),()=>x.removeEventListener("scroll",f)}},[c.viewport,g,d]),n.jsx(nt.div,{"data-state":u.hasThumb?"visible":"hidden",...a,ref:h,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...i},onPointerDownCapture:Ke(t.onPointerDownCapture,x=>{const b=x.target.getBoundingClientRect(),v=x.clientX-b.left,T=x.clientY-b.top;u.onThumbPointerDown({x:v,y:T})}),onPointerUp:Ke(t.onPointerUp,u.onThumbPointerUp)})},"ScrollAreaThumbImpl")),nr="ScrollAreaCorner",da=s.forwardRef(O(function(t,r){const o=Le(nr,t.__scopeScrollArea),i=!!(o.scrollbarX&&o.scrollbarY);return o.type!=="scroll"&&i?n.jsx(fa,{...t,ref:r}):null},"ScrollAreaCorner")),fa=s.forwardRef(O(function(t,r){const{__scopeScrollArea:o,...i}=t,a=Le(nr,o),[c,u]=s.useState(0),[d,h]=s.useState(0),p=!!(c&&d),{onCornerWidthChange:g,onCornerHeightChange:x}=a;return pt(a.scrollbarX,()=>{var b;const f=((b=a.scrollbarX)==null?void 0:b.offsetHeight)||0;a.onCornerHeightChange(f),h(f)}),pt(a.scrollbarY,()=>{var b;const f=((b=a.scrollbarY)==null?void 0:b.offsetWidth)||0;a.onCornerWidthChange(f),u(f)}),s.useEffect(()=>()=>{g(0),x(0)},[g,x]),p?n.jsx(nt.div,{...i,ref:r,style:{width:c,height:d,position:"absolute",right:a.dir==="ltr"?0:void 0,left:a.dir==="rtl"?0:void 0,bottom:0,...t.style}}):null},"ScrollAreaCornerImpl"));function Ct(e){return e?parseInt(e,10):0}O(Ct,"toInt");function tn(e,t){const r=e/t;return isNaN(r)?0:r}O(tn,"getThumbRatio");function Tt(e){const t=tn(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,o=(e.scrollbar.size-r)*t;return Math.max(o,18)}O(Tt,"getThumbSize");function rr(e,t,r,o="ltr"){const i=Tt(r),a=i/2,c=t||a,u=i-c,d=r.scrollbar.paddingStart+c,h=r.scrollbar.size-r.scrollbar.paddingEnd-u,p=r.content-r.viewport,g=o==="ltr"?[0,p]:[p*-1,0];return nn([d,h],g)(e)}O(rr,"getScrollPositionFromPointer");function Gt(e,t,r="ltr"){const o=Tt(t),i=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,a=t.scrollbar.size-i,c=t.content-t.viewport,u=a-o,d=r==="ltr"?[0,c]:[c*-1,0],h=zr(e,d);return nn([0,c],[0,u])(h)}O(Gt,"getThumbOffsetFromScroll");function nn(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const o=(t[1]-t[0])/(e[1]-e[0]);return t[0]+o*(r-e[0])}}O(nn,"linearScale");function rn(e,t){return e>0&&e<t}O(rn,"isScrollingWithinScrollbarBounds");var ha=O((e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},o=0;return O((function i(){const a={left:e.scrollLeft,top:e.scrollTop},c=r.left!==a.left,u=r.top!==a.top;(c||u)&&t(),r=a,o=window.requestAnimationFrame(i)}),"loop")(),()=>window.cancelAnimationFrame(o)},"addUnlinkedScrollListener");function Et(e,t){const r=ht(e),o=s.useRef(0);return s.useEffect(()=>()=>window.clearTimeout(o.current),[]),s.useCallback(()=>{window.clearTimeout(o.current),o.current=window.setTimeout(r,t)},[r,t])}O(Et,"useDebounceCallback");function pt(e,t){const r=ht(t);gr(()=>{let o=0;if(e){const i=new ResizeObserver(()=>{cancelAnimationFrame(o),o=window.requestAnimationFrame(r)});return i.observe(e),()=>{window.cancelAnimationFrame(o),i.unobserve(e)}}},[e,r])}O(pt,"useResizeObserver");var sr=ea,pa=na,ma=da;const or=s.forwardRef(({className:e,children:t,...r},o)=>n.jsxs(sr,{ref:o,className:te("relative overflow-hidden",e),...r,children:[n.jsx(pa,{className:"h-full w-full rounded-[inherit]",children:t}),n.jsx(ar,{}),n.jsx(ma,{})]}));or.displayName=sr.displayName;const ar=s.forwardRef(({className:e,orientation:t="vertical",...r},o)=>n.jsx(Qn,{ref:o,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...r,children:n.jsx(la,{className:"relative flex-1 rounded-full bg-border"})}));ar.displayName=Qn.displayName;function ir(e){return/[Zz]|[+-]\d{2}/.test(e)?new Date(e):new Date(e.replace(" ","T")+"Z")}function ga(e){const t=new Map;for(const i of e){const a=ir(i.created_at).toDateString();t.has(a)||t.set(a,[]),t.get(a).push(i)}const r=new Date().toDateString(),o=new Date(Date.now()-864e5).toDateString();return Array.from(t.entries()).map(([i,a])=>{let c;if(i===r)c="Today";else if(i===o)c="Yesterday";else{const u=new Date(i);c=u.toLocaleDateString(void 0,{month:"short",day:"numeric",...u.getFullYear()!==new Date().getFullYear()?{year:"numeric"}:{}})}return{label:c,items:a}})}function xa(e){return ir(e).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}const ba=5*1024*1024,ya=["image/png","image/jpeg","image/webp"];function va({buildId:e}){const t=s.useId(),[r,o]=s.useState([]),[i,a]=s.useState(""),[c,u]=s.useState(null),[d,h]=s.useState(!1),[p,g]=s.useState(""),x=s.useRef(null),f=s.useRef({}),b=s.useCallback(()=>{fetch(`/api/v1/comments?build_id=${e}`,{credentials:"include"}).then(C=>C.ok?C.json():[]).then(o)},[e]);s.useEffect(()=>{b()},[b]),s.useEffect(()=>{const C=window.location.hash;if(!C.startsWith("#comment-"))return;const N=Number(C.replace("#comment-","")),E=f.current[N];if(!E)return;E.scrollIntoView({behavior:"smooth"});const M=document.documentElement.classList.contains("dark");E.style.backgroundColor=M?"rgb(0 112 243 / 0.18)":"#d3e5ff",setTimeout(()=>{E.style.backgroundColor=""},2e3)},[r]);function v(C){const N=`${location.origin}${location.pathname}${location.search}#comment-${C}`;navigator.clipboard.writeText(N).then(()=>Ne.success("Link copied")).catch(()=>Ne.error("Could not copy link"))}function T(C){if(g(""),!ya.includes(C.type)){g("Only png, jpg, webp allowed");return}if(C.size>ba){g("Max 5MB");return}u(C)}async function j(C){if(C.preventDefault(),!i.trim()&&!c)return;h(!0);const N=new FormData;N.append("build_id",String(e)),N.append("body",i),c&&N.append("attachment",c),(await fetch("/api/v1/comments",{method:"POST",credentials:"include",body:N})).ok&&(a(""),u(null),b()),h(!1)}const L=ga(r);return n.jsxs("div",{className:"flex h-full flex-col gap-3 px-1",children:[n.jsx(or,{className:"flex-1 rounded-md border",children:n.jsx("div",{className:"p-3",children:r.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:L.map(({label:C,items:N})=>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:C}),n.jsx("div",{className:"h-px flex-1 bg-border"})]}),n.jsx("div",{className:"flex flex-col gap-4",children:N.map(E=>n.jsxs("div",{id:`comment-${E.id}`,ref:M=>{f.current[E.id]=M},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(br,{name:E.author,avatarUrl:E.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:E.author}),n.jsx("span",{className:"text-[11px] text-muted-foreground leading-none",children:xa(E.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(E.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:E.body}),E.attachments.map(M=>{const k=decodeURIComponent(M.file_path.split("/").pop()??"image");return n.jsx("a",{href:M.file_path,target:"_blank",rel:"noreferrer",className:"mt-1.5 block","aria-label":`Open ${k} in a new tab`,children:n.jsx("img",{src:M.file_path,alt:k,className:"max-h-48 rounded border object-contain"})},M.id)})]})]},E.id))})]},C))})})}),n.jsx("div",{className:"pb-1",children:n.jsx("form",{onSubmit:j,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(Kn,{"aria-label":"Comment",placeholder:"Leave a comment…",value:i,onChange:C=>a(C.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"}),(c||p)&&n.jsxs("div",{className:"px-3 -mt-1 pb-1",children:[c&&n.jsx("p",{className:"text-xs text-muted-foreground",children:c.name}),p&&n.jsx("p",{id:t,role:"alert",className:"text-xs text-destructive",children:p})]}),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","aria-describedby":p?t:void 0,onClick:()=>{var C;return(C=x.current)==null?void 0:C.click()},children:n.jsx(is,{className:"h-4 w-4","aria-hidden":"true"})}),n.jsx("input",{ref:x,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:C=>{var E;const N=(E=C.target.files)==null?void 0:E[0];N&&T(N)}}),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:d||!i.trim()&&!c,children:n.jsx(Qr,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})})})]})}function wa(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Sa(e){return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function Ra(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return{label:"Expired",urgent:!0};const r=Math.floor(t/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 ka({buildId:e,refreshKey:t}){const[r,o]=s.useState([]),[i,a]=s.useState(!0),[c,u]=s.useState(!1);return s.useEffect(()=>{a(!0),u(!1);const d=setTimeout(()=>u(!0),250);return fetch(`/api/v1/recordings?buildId=${e}`,{credentials:"include"}).then(h=>h.ok?h.json():[]).then(h=>o(h)).catch(()=>o([])).finally(()=>{clearTimeout(d),a(!1)}),()=>clearTimeout(d)},[e,t]),i?c?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=Ra(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:Sa(d.createdAt)}),n.jsxs("span",{className:`text-xs ${h.urgent?"text-destructive":"text-muted-foreground"}`,children:[h.label," · ",wa(d.fileSize)]})]}),n.jsx(ie,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 ml-2",title:"Download",onClick:()=>{const p=document.createElement("a");p.href=d.url,p.download="",p.click()},children:n.jsx(ns,{className:"h-3.5 w-3.5"})})]},d.id)})})}function ja({buildId:e,recordingsRefreshKey:t=0}){return n.jsxs(Nr,{defaultValue:"comments",className:"flex h-full flex-col",children:[n.jsx("div",{className:"shrink-0 px-1",children:n.jsxs(Ar,{className:"w-full",children:[n.jsxs(un,{value:"comments",className:"flex-1 gap-1.5",children:[n.jsx(hs,{className:"h-3.5 w-3.5"}),"Comments"]}),n.jsxs(un,{value:"recordings",className:"flex-1 gap-1.5",children:[n.jsx(ss,{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(va,{buildId:e})}),n.jsx(dn,{value:"recordings",className:"mt-3 min-h-0 flex-1 overflow-y-auto",children:n.jsx(ka,{buildId:e,refreshKey:t})})]})}const cr=s.forwardRef(({...e},t)=>n.jsx("nav",{ref:t,"aria-label":"breadcrumb",...e}));cr.displayName="Breadcrumb";const lr=s.forwardRef(({className:e,...t},r)=>n.jsx("ol",{ref:r,className:te("flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",e),...t}));lr.displayName="BreadcrumbList";const jt=s.forwardRef(({className:e,...t},r)=>n.jsx("li",{ref:r,className:te("inline-flex items-center gap-1.5",e),...t}));jt.displayName="BreadcrumbItem";const Pt=s.forwardRef(({asChild:e,className:t,...r},o)=>{const i=e?yr:"a";return n.jsx(i,{ref:o,className:te("transition-colors hover:text-foreground cursor-pointer",t),...r})});Pt.displayName="BreadcrumbLink";const Dt=s.forwardRef(({className:e,...t},r)=>n.jsx("span",{ref:r,role:"link","aria-disabled":"true","aria-current":"page",className:te("font-medium text-foreground",e),...t}));Dt.displayName="BreadcrumbPage";const Lt=({children:e,className:t,...r})=>n.jsx("li",{role:"presentation","aria-hidden":"true",className:te("[&>svg]:h-3.5 [&>svg]:w-3.5",t),...r,children:e??n.jsx(vr,{})});Lt.displayName="BreadcrumbSeparator";var Ca=Object.defineProperty,et=(e,t)=>Ca(e,"name",{value:t,configurable:!0}),sn="Switch",[Ta,Xa]=Tn(sn),[Ea,on]=Ta(sn);function ur(e){const{__scopeSwitch:t,checked:r,children:o,defaultChecked:i,disabled:a,form:c,name:u,onCheckedChange:d,required:h,value:p="on",internal_do_not_use_render:g}=e,[x,f]=Sr({prop:r,defaultProp:i??!1,onChange:d,caller:sn}),[b,v]=s.useState(null),[T,j]=s.useState(null),L=s.useRef(!1),[C,N]=s.useReducer(k=>k+1,0),E=b?!!c||!!b.closest("form"):!0,M={checked:x,setChecked:f,disabled:a,control:b,setControl:v,name:u,form:c,value:p,hasConsumerStoppedPropagationRef:L,userInteractionCount:C,onUserInteraction:N,required:h,defaultChecked:i,isFormControl:E,bubbleInput:T,setBubbleInput:j};return n.jsx(Ea,{scope:t,...M,children:fr(g)?g(M):o})}et(ur,"SwitchProvider");var Na="SwitchTrigger",Aa=s.forwardRef(et(function({__scopeSwitch:t,onClick:r,...o},i){const{control:a,form:c,value:u,disabled:d,checked:h,required:p,setControl:g,setChecked:x,hasConsumerStoppedPropagationRef:f,onUserInteraction:b,isFormControl:v,bubbleInput:T}=on(Na,t),j=tt(i,g),L=s.useRef(h);return s.useEffect(()=>{const C=c?a==null?void 0:a.ownerDocument.getElementById(c):a==null?void 0:a.form;if(C instanceof HTMLFormElement){const N=et(()=>x(L.current),"reset");return C.addEventListener("reset",N),()=>C.removeEventListener("reset",N)}},[a,c,x]),n.jsx(nt.button,{type:"button",role:"switch","aria-checked":h,"aria-required":p,"data-state":an(h),"data-disabled":d?"":void 0,disabled:d,value:u,...o,ref:j,onClick:Ke(r,C=>{b(),x(N=>!N),T&&v&&(f.current=C.isPropagationStopped(),f.current||C.stopPropagation())})})},"SwitchTrigger")),dr=s.forwardRef(et(function(t,r){const{__scopeSwitch:o,name:i,checked:a,defaultChecked:c,required:u,disabled:d,value:h,onCheckedChange:p,form:g,...x}=t;return n.jsx(ur,{__scopeSwitch:o,checked:a,defaultChecked:c,disabled:d,required:u,onCheckedChange:p,name:i,form:g,value:h,internal_do_not_use_render:({isFormControl:f})=>n.jsxs(n.Fragment,{children:[n.jsx(Aa,{...x,ref:r,__scopeSwitch:o}),f&&n.jsx(La,{__scopeSwitch:o})]})})},"Switch")),_a="SwitchThumb",Pa=s.forwardRef(et(function(t,r){const{__scopeSwitch:o,...i}=t,a=on(_a,o);return n.jsx(nt.span,{"data-state":an(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:r})},"SwitchThumb")),Da="SwitchBubbleInput",La=s.forwardRef(et(function({__scopeSwitch:t,onClick:r,...o},i){const{control:a,hasConsumerStoppedPropagationRef:c,userInteractionCount:u,checked:d,defaultChecked:h,required:p,disabled:g,name:x,value:f,form:b,bubbleInput:v,setBubbleInput:T}=on(Da,t),j=tt(i,T),L=wr(a),C=s.useRef(!1),N=s.useRef(d),E=s.useRef(u);s.useEffect(()=>{const k=v;if(!k)return;const B=window.HTMLInputElement.prototype,z=Object.getOwnPropertyDescriptor(B,"checked").set,F=u!==E.current;E.current=u;const Q=N.current!==d;N.current=d;const ue=!(F&&c.current);if(Q&&z){C.current=!F;const Ie=new Event("click",{bubbles:ue});z.call(k,d),k.dispatchEvent(Ie),C.current=!1}},[v,d,c,u]);const M=s.useRef(d);return n.jsx(nt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:h??M.current,required:p,disabled:g,name:x,value:f,form:b,...o,tabIndex:-1,ref:j,onClick:Ke(r,k=>{C.current&&k.stopPropagation()}),style:{...o.style,...L,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"SwitchBubbleInput"));function fr(e){return typeof e=="function"}et(fr,"isFunction");function an(e){return e?"checked":"unchecked"}et(an,"getState");const hr=s.forwardRef(({className:e,...t},r)=>n.jsx(dr,{className:te("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",e),...t,ref:r,children:n.jsx(Pa,{className:te("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")})}));hr.displayName=dr.displayName;const Rn=70,kn=80;function Ia(e,t){if(!e||t)return"unknown";const r=e.memUsedMB/e.memTotalMB*100;return e.cpuPercent>kn||r>kn?"overloaded":e.cpuPercent>=Rn||r>=Rn?"warning":"healthy"}const Ma={"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 Ka(){const[e]=An(),t=_r(),r=e.get("id"),{build:o}=Ds(r),[i,a]=s.useState(0),c=(o==null?void 0:o.platform)??"ios",{sessions:u,selectedAgent:d,setSelectedAgent:h,activeSessionId:p,deviceId:g,booting:x,status:f,connected:b,agentGroups:v,startDevice:T,resetDevice:j,handleBack:L,handleBackToMacs:C,handleSessionEnded:N}=Ls(c),E=v.find(U=>U.agentName===d),{osVersions:M,osVersion:k,setOsVersion:B,deviceSearch:G,setDeviceSearch:z,versionedDevices:F,resetMode:Q,setResetMode:ue,appliedResetMode:Ie,consumeResetMode:Fe,fullResetSupported:be}=Is(E,c),Z=u.flatMap(U=>U.devices).find(U=>U.id===g),Ae=Z?`${Z.name}${Z.osVersion?` · ${Z.osVersion}`:""}`:"",Oe=s.useCallback(()=>a(U=>U+1),[]),He=s.useCallback(U=>{Fe(),T(U)},[Fe,T]),Me=s.useCallback(U=>{const q=Ma[U];Ne.error(q.title,{description:q.description}),N()},[N]),{setNode:Ue}=Rr();return s.useEffect(()=>{if(o)return Ue(n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(cr,{children:n.jsxs(lr,{children:[n.jsx(jt,{children:n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:()=>t(`/app-center?appId=${o.app_id}`),children:o.name})})}),n.jsx(Lt,{}),n.jsx(jt,{children:d?n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:C,children:ln(o)})}):n.jsx(Dt,{children:ln(o)})}),d&&n.jsxs(n.Fragment,{children:[n.jsx(Lt,{}),n.jsx(jt,{children:p?n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:L,children:d})}):n.jsx(Dt,{children:d})})]}),p&&n.jsxs(n.Fragment,{children:[n.jsx(Lt,{}),n.jsx(jt,{children:n.jsx(Dt,{children:Ae})})]})]})}),!d&&o.status_label&&n.jsx(Kr,{tone:Tr[o.status_label],children:o.status_label})]})),()=>Ue(null)},[o,d,p,Ae,t,L,C,Ue]),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:p?n.jsx("div",{className:"min-h-full flex items-center justify-center py-6 px-8 min-w-max",children:n.jsx(Jo,{sessionId:p,deviceId:g,buildId:o==null?void 0:o.id,resetMode:Ie,onRecordingUploaded:Oe,onSessionEnded:Me})}):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:C,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(Er,{placeholder:"Search device…",value:G,onChange:z}),M.length>0&&n.jsxs(Wr,{value:k||"__all__",onValueChange:U=>{B(U==="__all__"?"":U),j()},children:[n.jsx(Vr,{className:"h-8 w-36 shrink-0",children:n.jsx(qr,{})}),n.jsxs(Xr,{children:[n.jsx(fn,{value:"__all__",children:"Any version"}),M.map(U=>n.jsx(fn,{value:U,children:U},U))]})]}),be&&n.jsx(Vt,{children:n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx(kr,{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(hr,{id:"reset-mode","aria-describedby":"reset-mode-desc",checked:Q==="full-erase",onCheckedChange:U=>ue(U?"full-erase":"app-only")})]})}),n.jsx(Ee,{children:Q==="full-erase"?"Erase all data on the next device you pick":"Keep existing data"})]})})]}),F.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:b?"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:F.map(U=>{const q=U.status==="booted",K=U.busy,Se=K?"In use":q?"Booted":"Available",J=K?"bg-amber-400":q?"bg-emerald-400":"bg-muted-foreground/40";return n.jsxs("button",{disabled:K||x||!b,onClick:()=>He(U),className:te("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:te("inline-block h-1.5 w-1.5 rounded-full",J)}),Se]})]},U.id)})}),f&&n.jsx("p",{className:"text-sm text-muted-foreground",children:f})]}):n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select Mac"}),v.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:b?`No agents available for ${c}.`:"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:v.map(U=>{const q=U.resources,K=q?Date.now()-q.reportedAt>3e4:!1,Se=U.devices.filter(We=>We.platform===c).length,J=(q==null?void 0:q.cpuPercent)??0,Re=q?q.memUsedMB/q.memTotalMB*100:0,de=Ia(q,K),ee=de==="overloaded";return n.jsx(Vt,{children:n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx("span",{tabIndex:ee?0:void 0,className:ee?"cursor-not-allowed":void 0,children:n.jsxs("button",{disabled:ee,"aria-disabled":ee,onClick:()=>h(U.agentName??null),className:te("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px] w-full",ee?"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(Ua,{health:de}),n.jsx("span",{className:"text-sm font-medium leading-tight truncate",children:U.agentName??"Unknown"})]}),K&&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:[Se," device",Se!==1?"s":""]}),q&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:[q.slotsAvailable,"/",q.slotsTotal," slots"]})]})]}),q&&!K&&n.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[n.jsx(jn,{label:"CPU",percent:J,colorClass:"bg-blue-400"}),n.jsx(jn,{label:"RAM",percent:Re,colorClass:"bg-violet-400"})]})]})})}),ee&&n.jsx(Ee,{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(ja,{buildId:Number(r),recordingsRefreshKey:i})})]})]})}function Ua({health:e}){const t={unknown:"bg-muted-foreground/40",healthy:"bg-emerald-400",warning:"bg-amber-400",overloaded:"bg-red-500"}[e];return n.jsx("span",{"data-testid":"resource-health-dot",className:te("inline-block h-2 w-2 shrink-0 rounded-full",t)})}function jn({label:e,percent:t,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:e}),n.jsxs("span",{children:[t.toFixed(0),"%"]})]}),n.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:n.jsx("div",{className:te("h-full rounded-full transition-all",r),style:{width:`${Math.min(100,t)}%`}})})]})}export{Ka as QASession};
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 co(t){const e=t.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!e)return null;const r=(x,f)=>{const b=e.createShader(x);return e.shaderSource(b,f),e.compileShader(b),b},o=e.createProgram(),i=r(e.VERTEX_SHADER,ao),a=r(e.FRAGMENT_SHADER,io);e.attachShader(o,i),e.attachShader(o,a),e.linkProgram(o),e.deleteShader(i),e.deleteShader(a),e.useProgram(o);const c=e.createVertexArray();e.bindVertexArray(c);const u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u),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),p=Ht(e,1,"u_texU",o),g=Ht(e,2,"u_texV",o);return{gl:e,program:o,texY:h,texU:p,texV:g,vao:c}}class lo{constructor(e){this.canvas=e,this.state=null}init(){return this.state=co(this.canvas),this.state!==null}drawI420(e,r,o){const i=this.state;if(!i)return null;const{gl:a}=i,c=r+1>>1,u=o+1>>1,d=r*o,h=c*u,p=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 f=(b,v,T,j,L)=>{a.activeTexture(a.TEXTURE0+b),a.bindTexture(a.TEXTURE_2D,v),a.texImage2D(a.TEXTURE_2D,0,a.R8,T,j,0,a.RED,a.UNSIGNED_BYTE,L)};return f(0,i.texY,r,o,p),f(1,i.texU,c,u,g),f(2,i.texV,c,u,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 uo=0;function fo(t){const e=new lo(t);return e.init(),e}function ho(){return new Worker(new URL("/assets/tinyh264.worker-DiJ50Hai.js",import.meta.url),{type:"module"})}class po{constructor(e=fo,r=ho){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:uo},[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 mo(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2?new oo:t.wasm&&t.webgl2?new po:null}function go(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2||t.wasm&&t.webgl2}function xo(t=Jt()){return t.secureContext&&t.webCodecs&&t.webgl2?"high":t.wasm&&t.webgl2?"standard":"unsupported"}const bo="https://www.tapflow.dev/reference/configuration#https-secure-context";function yo({open:t,onOpenChange:e}){return n.jsx(An,{open:t,onOpenChange:e,children:n.jsxs(_n,{className:"sm:max-w-[440px]",children:[n.jsxs(Or,{children:[n.jsx(Pn,{children:"Streaming in Standard mode"}),n.jsxs(Hr,{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(zr,{children:[n.jsx(ie,{variant:"outline",onClick:()=>window.open(bo,"_blank","noopener,noreferrer"),children:"How to enable"}),n.jsx(ie,{onClick:()=>e(!1),children:"Got it"})]})]})})}const xn="tapflow.perfModeNoticeDismissed";function vo(t,e){return t==="standard"&&!e}const wo={high:"Smooth",standard:"Standard",unsupported:null};function So(t){const{connected:e,joined:r,bootError:o,deviceReady:i,installing:a,installError:c,agentAway:u,decoderUnsupported:d}=t;return e?r?u?"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…":c?`Install failed: ${c}`:d?"Streaming is not supported in this environment.":null:"Starting device…":"Joining session…":"Connecting…"}function Qt(t){const{joined:e,fps:r,keyboardActive:o}=t,i=So(t),a=r>15,c=a?"#10b981":"#94a3b8",u=a?"Active":"Idle",d=s.useMemo(()=>xo(),[]),h=wo[d],[p,g]=s.useState(!1);s.useEffect(()=>{let f=!1;try{f=localStorage.getItem(xn)==="1"}catch{}vo(d,f)&&g(!0)},[d]);const x=f=>{if(g(f),!f)try{localStorage.setItem(xn,"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:te("flex items-center",o?"text-emerald-500":"text-muted-foreground"),style:{gap:6},children:[n.jsx(Cs,{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:c}}),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:te("text-[11px]",a?"text-emerald-500":"text-muted-foreground/60"),children:u})]}),h&&n.jsxs(n.Fragment,{children:[n.jsx(jn,{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-words",children:i})}),n.jsx(yo,{open:p,onOpenChange:x})]})}function Hn({open:t,onOpenChange:e,openUrl:r}){const[o,i]=s.useState(""),a=s.useRef(null);s.useEffect(()=>{t?setTimeout(()=>{var u;return(u=a.current)==null?void 0:u.focus()},0):i("")},[t]);const c=()=>{o.trim()&&(r(o.trim()),e(!1))};return n.jsx(An,{open:t,onOpenChange:e,children:n.jsxs(_n,{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(Pn,{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(jr,{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:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&c()}})]}),n.jsx(ie,{size:"sm",disabled:!o.trim(),onClick:c,className:"shrink-0 rounded-xl h-8 px-4",children:"Open"})]})]})})}function Ro(t,e,r,o,i,a){const{x:c,y:u,width:d,height:h}=i;let p,g;if(a){const x=(t.x-e.left)/e.width;p=(1-(t.y-e.top)/e.height)*r,g=x*o}else p=(t.x-e.left)*(r/e.width),g=(t.y-e.top)*(o/e.height);return p<c||p>c+d||g<u||g>u+h?null:{x:(p-c)/d,y:(g-u)/h}}function ko(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 jo(t,e){return t>0?Math.min(1,e/t):1}const Kt=22,bn=[84,70,70,69],Co=1,To=0,It=1,Wn=2,Eo=1,No=2,Ao=4;function _o(t){if(t.byteLength<Kt)return null;const e=new DataView(t);for(let i=0;i<bn.length;i++)if(e.getUint8(i)!==bn[i])return null;if(e.getUint8(4)!==Co)return null;const r=e.getUint8(5),o=r&Ao?Wn:r&Eo?It:To;return{capturedAt:Number(e.getBigUint64(6)),relayedAt:Number(e.getBigUint64(14)),codec:o,keyframe:o===It&&(r&No)!==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,c=!1,u=!1,d;const h=()=>{if(a)return a;if(c)return null;const p=mo();return p?(a=p,p.onResize(g=>i.current.onResize(g)),d=i.current.onDecoderReady(p),p):(c=!0,i.current.onUnsupported(),console.warn("[decoder] none available — set up HTTPS or use a supported browser"),null)};return e.current=(p,g)=>{const x=i.current.onJpegFrame;if(x&&(g==null?void 0:g.codec)!==It){x(p,g);return}const f=h();if(f){if(!u){if(!(g!=null&&g.keyframe))return;u=!0}f.decode(p),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 Po=3e3+5*300,Do=Po+500,_t=8;function Lo(){var t;return window.isSecureContext&&typeof ClipboardItem<"u"&&!!((t=navigator.clipboard)!=null&&t.write)}class Rt extends Error{}function Io(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 Mo=1024*1024,Uo=t=>new TextEncoder().encode(t).length,$o=t=>{var e;return!!((e=t.payload)!=null&&e.unsupported)},Fo=t=>{var e,r;return((e=t.payload)==null?void 0:e.sentinelParked)===!1||((r=t.payload)==null?void 0:r.unsupported)===!0};function Bo(){const t=window.getSelection();return!!t&&!t.isCollapsed&&t.toString().length>0}function yn(){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:c}){const u=s.useRef(new Map),d=s.useRef(null),h=s.useRef(c);s.useLayoutEffect(()=>{h.current=c});const p=s.useCallback(x=>{var f;d.current!==x&&(d.current=x,(f=h.current)==null||f.call(h,x))},[]);s.useEffect(()=>(i.current=x=>{if(!x.requestId)return;const f=u.current.get(x.requestId);f&&(u.current.delete(x.requestId),f(x))},()=>{i.current=void 0}),[i]);const g=s.useCallback((...[x,f])=>{const b=X();return new Promise(v=>{const T=setTimeout(()=>{u.current.delete(b),v(null)},Do);u.current.set(b,j=>{clearTimeout(T),v(j)}),e({type:x,sessionId:t,requestId:b,payload:f})})},[e,t]);s.useEffect(()=>{if(!r||!o)return;const x=async b=>{if(b.code==="KeyV"||!Zt(b))return;const v=b.code==="KeyX";if(yn()||Bo()||(b.preventDefault(),b.repeat))return;if(!Lo()){a(v?"KeyX":"KeyC",_t),p("Copied on the device. Serving the dashboard over HTTPS also brings it to your clipboard.");return}let T,j;const L=new Promise((M,k)=>{T=M,j=k});L.catch(()=>{});const C=Io(L).catch(M=>{M instanceof Rt||p(M instanceof Error&&M.name==="NotAllowedError"?"Your browser blocked the clipboard write":"Could not write to your clipboard")}),N=await g("clipboard:read",{press:v?"cut":"copy"});if(!N){j(new Rt("timeout")),p("The device is taking too long — try again");return}if(N.type==="clipboard:error"){j(new Rt(N.message||"read failed")),p(N.message||"Clipboard read failed"),Fo(N)&&a(v?"KeyX":"KeyC",_t);return}if(N.type!=="clipboard:data"){j(new Rt("unexpected reply")),p("Clipboard read failed");return}const{text:E}=N.payload;if(d.current=null,!E){j(new Rt("empty"));return}T(E),await C},f=b=>{var T;if(yn())return;const v=((T=b.clipboardData)==null?void 0:T.getData("text"))??"";if(b.preventDefault(),!v){a("KeyV",_t);return}if(Uo(v)>Mo){p("That text is too large to send to the device");return}g("clipboard:write",{text:v,pasteAfter:!0}).then(j=>{if(!j){p("The device is taking too long — try again");return}if(j.type==="clipboard:write-done"){d.current=null;return}if(j.type!=="clipboard:error"){p("Clipboard write failed");return}p(j.message||"Clipboard write failed"),$o(j)&&a("KeyV",_t)})};return document.addEventListener("keydown",x),document.addEventListener("paste",f),()=>{document.removeEventListener("keydown",x),document.removeEventListener("paste",f)}},[r,o,g,a,p])}const ze=13,ut=8,vn=16,Oo=.02,Ho=100;function zo({sessionId:t,buildId:e,send:r,openUrl:o,launchApp:i,connected:a,joined:c,deviceReady:u,installing:d,installed:h,installError:p,bootError:g,launching:x,chrome:f,binaryFrameHandlerRef:b,clipboardHandlerRef:v,clipboardSupported:T,networkHandlerRef:j,networkSupported:L,onRecordingUploaded:C,swKeyboardVisible:N,swKeyboardPending:E,onKbdToggle:M,rebootPending:k,onReboot:F,restartButtonRef:G,perfHookRef:z}){const B=s.useRef(null),Q=s.useRef(null),ue=s.useRef(null),{fps:Ie,frameCount:Be}=Un(),be=s.useRef(0),{recordState:ye,recordCanvasRef:Z,startClientRecording:Ae,stopClientRecording:Oe}=Mn({sessionId:t,buildId:e,onRecordingUploaded:C}),He=s.useRef(0),[Me,Ue]=s.useState(!1),[U,q]=s.useState(!1),[K,Se]=s.useState(!1),[J,Re]=s.useState(!1),[de,ee]=s.useState(!1),[We,rt]=s.useState(null),[Ve,fe]=s.useState(null),[ve,ke]=s.useState(!1),[Y,he]=s.useState(null),$e=s.useRef(Y);s.useEffect(()=>{$e.current=Y},[Y]);const ge=s.useRef(null),oe=s.useRef(null),re=s.useRef(!1),ae=s.useRef(!1),_e=s.useRef(0),Pe=s.useRef(null),je=s.useRef(null),we=s.useRef("idle"),w=s.useRef(null),H=s.useRef(null),ce=s.useRef(null);s.useEffect(()=>{ce.current=f},[f]),s.useEffect(()=>{const l=new Image;l.onload=()=>{H.current=l},l.src=`data:image/png;base64,${f.framePng}`},[f.framePng]),Vn({binaryFrameHandlerRef:b,perfHookRef:z,frameCount:Be,onUnsupported:()=>Se(!0),onResize:l=>{const y=B.current;if(y&&(y.width!==l.width||y.height!==l.height)&&(y.width=l.width,y.height=l.height,!ce.current)){const m=Z.current;m&&(m.width=l.width,m.height=l.height)}q(!0)},onDecoderReady:l=>{var S;const y=l.surface,m=B.current;y.style.position="absolute",m&&(y.style.left=m.style.left,y.style.top=m.style.top,y.style.width=m.style.width,y.style.height=m.style.height,y.style.borderRadius=m.style.borderRadius),y.style.objectFit="fill",y.style.zIndex="3",y.style.pointerEvents="none",(S=Q.current)==null||S.appendChild(y);let A=null;const P=()=>{const I=B.current,$=I==null?void 0:I.getContext("2d");if(I&&$&&l.size)try{$.drawImage(l.surface,0,0,I.width,I.height)}catch{}A=requestAnimationFrame(P)};return A=requestAnimationFrame(P),()=>{A!==null&&cancelAnimationFrame(A)}},onJpegFrame:l=>{const y=performance.now();be.current&&y-be.current,be.current=y;const m=He.current;createImageBitmap(new Blob([l],{type:"image/jpeg"})).then(A=>{if(performance.now()-y,He.current!==m){A.close();return}const P=B.current,S=P==null?void 0:P.getContext("2d");if(!P||!S){A.close();return}if((P.width!==A.width||P.height!==A.height)&&(P.width=A.width,P.height=A.height,!ce.current)){const $=Z.current;$&&($.width=A.width,$.height=A.height)}const I=performance.now();S.drawImage(A,0,0),performance.now()-I,A.close(),q(!0),Be.current+=1}).catch(()=>{})}}),s.useEffect(()=>{const l=Z.current,y=Q.current;l&&y&&(l.width=y.clientWidth,l.height=y.clientHeight)},[f,Z]);const pe=s.useCallback(()=>{const l=Z.current,y=B.current;if(!l||!y)return;const m=l.getContext("2d");if(!m)return;const A=ce.current;if(m.clearRect(0,0,l.width,l.height),A){H.current&&m.drawImage(H.current,0,0,l.width,l.height);const I=Math.round(A.screenCornerRadius/2*(l.height/(A.compositeHeight/2)));m.save(),m.beginPath(),I>0?m.roundRect(y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight,I):m.rect(y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight),m.clip(),m.drawImage(y,y.offsetLeft,y.offsetTop,y.clientWidth,y.clientHeight),m.restore()}else m.drawImage(y,0,0,l.width,l.height);const P=$e.current;if(P)for(const I of[P.f0,P.f1]){const $=A?y.offsetLeft+I.x*y.clientWidth:I.x*l.width,le=A?y.offsetTop+I.y*y.clientHeight:I.y*l.height;re.current?(m.beginPath(),m.arc($,le,ut,0,Math.PI*2),m.fillStyle="rgba(255,255,255,0.92)",m.fill(),m.strokeStyle="rgba(0,0,0,0.2)",m.lineWidth=1,m.stroke()):(m.beginPath(),m.arc($,le,ze,0,Math.PI*2),m.strokeStyle="rgba(0,0,0,0.3)",m.lineWidth=3,m.stroke(),m.beginPath(),m.arc($,le,ze,0,Math.PI*2),m.strokeStyle="rgba(255,255,255,0.65)",m.lineWidth=1.5,m.stroke())}const S=je.current;if(S){const I=we.current,$=w.current;if(m.save(),I==="down")m.beginPath(),m.arc(S.x,S.y,ut,0,Math.PI*2),m.fillStyle="rgba(255,255,255,0.92)",m.fill(),m.strokeStyle="rgba(0,0,0,0.2)",m.lineWidth=1,m.stroke();else if(I==="release"&&$){const le=Math.min((performance.now()-$.startTime)/350,1);m.beginPath(),m.arc(S.x,S.y,ut+26*le,0,Math.PI*2),m.strokeStyle=`rgba(255,255,255,${(1-le)*.55})`,m.lineWidth=1.5,m.stroke(),le>=1&&(we.current="idle",w.current=null)}else m.beginPath(),m.arc(S.x,S.y,ze,0,Math.PI*2),m.strokeStyle="rgba(0,0,0,0.3)",m.lineWidth=3,m.stroke(),m.beginPath(),m.arc(S.x,S.y,ze,0,Math.PI*2),m.strokeStyle="rgba(255,255,255,0.65)",m.lineWidth=1.5,m.stroke();m.restore()}},[Z]),V=s.useCallback(()=>{const l=B.current;if(!l)return;const y=document.createElement("canvas"),m=y.getContext("2d");m&&(y.width=l.width,y.height=l.height,m.drawImage(l,0,0),y.toBlob(A=>{if(!A)return;const P=URL.createObjectURL(A),S=document.createElement("a");S.href=P,S.download=`tapflow-${Date.now()}.png`,S.click(),URL.revokeObjectURL(P)},"image/png"))},[]),me=s.useCallback(()=>{if(ye==="idle"){const l=Z.current;if(!l)return;const y=Q.current;if(y&&y.clientWidth>0)l.width=y.clientWidth,l.height=y.clientHeight;else{const m=B.current;if(m&&m.width>0)l.width=m.width,l.height=m.height;else return}Ae(pe)}else ye==="recording"&&Oe()},[ye,Ae,Oe,pe,Z]),qe=s.useCallback(()=>{r({type:"input:rotate",sessionId:t}),Re(l=>!l)},[r,t]),Nt=s.useRef(J);s.useEffect(()=>{Nt.current=J},[J]),s.useEffect(()=>()=>{Nt.current&&r({type:"input:rotate",sessionId:t})},[]);const Ut=s.useCallback((l,y)=>{r({type:"input:key",sessionId:t,requestId:X(),payload:{code:l,modifiers:y}})},[r,t]);qn({sessionId:t,send:r,active:de,supported:T,handlerRef:v,sendChord:Ut,onError:l=>Ne.error(l)});const st=Fn({sessionId:t,send:r,supported:L,deviceReady:u,handlerRef:j,onError:l=>Ne.error(l)});s.useEffect(()=>{const l=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),y=S=>{if(S.code==="AltLeft"||S.code==="AltRight"){ae.current=!0;return}if(S.metaKey){const $=document.activeElement;if(!$||$.tagName!=="INPUT"&&$.tagName!=="TEXTAREA"){if(!S.shiftKey&&S.code==="KeyK"){S.preventDefault(),Ue(!0);return}if(!S.shiftKey&&S.code==="KeyS"){S.preventDefault(),V();return}if(S.shiftKey&&S.code==="KeyY"){S.preventDefault(),me();return}if(S.shiftKey&&S.code==="KeyO"){S.preventDefault(),qe();return}if(S.shiftKey&&S.code==="KeyU"){S.preventDefault(),r({type:"input:button",sessionId:t,requestId:X(),payload:{name:"home"}});return}if(S.shiftKey&&S.code==="KeyK"){S.preventDefault(),E||M();return}}}if(!de||l.has(S.code)||T&&Zt(S))return;S.preventDefault();const I=(S.shiftKey?2:0)|(S.ctrlKey?1:0)|(S.metaKey?8:0);r({type:"input:key",sessionId:t,requestId:X(),payload:{code:S.code,modifiers:I}})},m=()=>{re.current&&(re.current=!1,ke(!1),r({type:"input:pinch:end",sessionId:t,requestId:X()})),ae.current=!1,he(null)},A=S=>{(S.code==="AltLeft"||S.code==="AltRight")&&m()},P=()=>{ae.current&&m()};return window.addEventListener("keydown",y),window.addEventListener("keyup",A),window.addEventListener("blur",P),()=>{window.removeEventListener("keydown",y),window.removeEventListener("keyup",A),window.removeEventListener("blur",P)}},[de,T,r,t,V,me,qe,M,E]),s.useEffect(()=>{if(!de)return;const l=y=>{const m=Q.current??B.current;m&&!m.contains(y.target)&&ee(!1)};return document.addEventListener("pointerdown",l),()=>document.removeEventListener("pointerdown",l)},[de]);const Xe=s.useCallback(l=>{const y=(J?ue.current:null)??Q.current;if(!y)return null;const m=y.getBoundingClientRect(),A=f.compositeWidth/2,P=f.compositeHeight/2,S=f.screenRect.x/2,I=f.screenRect.y/2,$=f.screenRect.width/2,le=f.screenRect.height/2;return Ro({x:l.clientX,y:l.clientY},m,A,P,{x:S,y:I,width:$,height:le},J)},[f,J]),ot=s.useCallback(l=>{const y=Xe(l);return y?zn(y):null},[Xe]),xe=s.useCallback(l=>{const y=J?ue.current:Q.current;if(!y)return null;const m=y.getBoundingClientRect();let A,P;if(J){const I=m.height-(l.clientY-m.top),$=l.clientX-m.left;A=I*(f.compositeWidth/m.height),P=$*(f.compositeHeight/m.width)}else A=(l.clientX-m.left)*(f.compositeWidth/m.width),P=(l.clientY-m.top)*(f.compositeHeight/m.height);const S=f.screenRect;return A>=S.x&&A<=S.x+S.width&&P>=S.y&&P<=S.y+S.height?null:Bs(A,P,f.buttons,Ho)},[f,J]),Ge=s.useCallback(l=>{const y=B.current,m=Z.current;return y&&y.clientWidth>0?{x:y.offsetLeft+l.x*y.clientWidth,y:y.offsetTop+l.y*y.clientHeight}:{x:l.x*((m==null?void 0:m.width)??1),y:l.y*((m==null?void 0:m.height)??1)}},[Z]),Je=s.useCallback(l=>{if(ee(!0),ae.current){const S=ot(l);if(!S)return;re.current=!0,ke(!0),l.target.setPointerCapture(l.pointerId),he(S),r({type:"input:pinch:start",sessionId:t,payload:S});return}const y=xe(l);if(y){ge.current=y,rt(y),l.target.setPointerCapture(l.pointerId),r({type:"input:button",sessionId:t,requestId:X(),payload:{name:y,phase:"down"}});return}const m=Xe(l);if(!m)return;oe.current=m,l.target.setPointerCapture(l.pointerId),je.current=Ge(m),we.current="down",w.current=null;const A=l.currentTarget.getBoundingClientRect(),P=Pe.current;P&&(P.style.display="block",P.style.left=`${l.clientX-A.left}px`,P.style.top=`${l.clientY-A.top}px`,P.style.width=`${ut*2}px`,P.style.height=`${ut*2}px`,P.style.background="rgba(255,255,255,0.92)",P.style.border="1.5px solid rgba(0,0,0,0.2)",P.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:m})},[xe,Xe,ot,Ge,r,t]),at=s.useCallback(l=>{if(l.buttons===0){if(fe(xe(l)),ae.current){he(ot(l)),je.current=null;const I=Pe.current;I&&(I.style.display="none")}else{he(null);const I=Xe(l);je.current=I?Ge(I):null,we.current!=="down"&&(we.current="idle");const $=Pe.current;if($)if(I){const le=l.currentTarget.getBoundingClientRect();$.style.display="block",$.style.left=`${l.clientX-le.left}px`,$.style.top=`${l.clientY-le.top}px`,$.style.width=`${ze*2}px`,$.style.height=`${ze*2}px`,$.style.background="transparent",$.style.border="1.5px solid rgba(255,255,255,0.6)",$.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"}else $.style.display="none"}return}if(re.current){const I=ot(l);if(!I)return;const $=performance.now();if($-_e.current<vn)return;_e.current=$,he(I),r({type:"input:pinch:move",sessionId:t,payload:I});return}if(ge.current||!oe.current)return;const y=Xe(l);if(!y)return;const m=y.x-oe.current.x,A=y.y-oe.current.y;if(Math.sqrt(m*m+A*A)<Oo)return;const P=performance.now();if(P-_e.current<vn)return;_e.current=P,je.current=Ge(y);const S=Pe.current;if(S&&S.style.display!=="none"){const I=l.currentTarget.getBoundingClientRect();S.style.left=`${l.clientX-I.left}px`,S.style.top=`${l.clientY-I.top}px`}r({type:"input:touch:move",sessionId:t,payload:y})},[xe,Xe,ot,Ge,r,t]),$t=s.useCallback(()=>{if(re.current){re.current=!1,ke(!1),he(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}if(oe.current=null,ge.current){r({type:"input:button",sessionId:t,requestId:X(),payload:{name:ge.current,phase:"up"}}),ge.current=null,setTimeout(()=>rt(null),100);return}we.current="release",w.current={startTime:performance.now()};const l=Pe.current;l&&(l.style.width=`${ze*2}px`,l.style.height=`${ze*2}px`,l.style.background="transparent",l.style.border="1.5px solid rgba(255,255,255,0.6)",l.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),Qe=s.useCallback(()=>{if(re.current){re.current=!1,ke(!1),he(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}if(oe.current=null,ge.current){r({type:"input:button",sessionId:t,requestId:X(),payload:{name:ge.current,phase:"up"}}),ge.current=null,rt(null);return}we.current="release",w.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),Ft=s.useCallback(()=>{fe(null),he(null),je.current=null;const l=Pe.current;l&&(l.style.display="none")},[]),Bt=f.compositeWidth/2,vt=f.compositeHeight/2,wt=jo(vt,750),it=Math.round(Bt*wt),ct=Math.round(vt*wt),lt=f.screenRect.x/f.compositeWidth*100,mt=f.screenRect.y/f.compositeHeight*100,gt=f.screenRect.width/f.compositeWidth*100,xt=f.screenRect.height/f.compositeHeight*100,R=Math.round(f.screenCornerRadius/2*wt),D=n.jsx(n.Fragment,{children:n.jsxs(Ce,{children:[n.jsx(Te,{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(Dn,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:n.jsxs("span",{className:"flex items-center gap-3",children:["Home ",n.jsxs(qt,{children:[n.jsx(ft,{children:"⌘"}),n.jsx(ft,{children:"⇧"}),n.jsx(ft,{children:"U"})]})]})})]})}),W=s.useId(),_=n.jsxs(n.Fragment,{children:[n.jsx("span",{id:W,role:"status",className:"sr-only",children:E?"Changing the software keyboard.":N?"The software keyboard is up.":"The software keyboard is down."}),n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":E?"Software keyboard — changing it":"Software keyboard","aria-pressed":N,"aria-busy":E,"aria-disabled":E,"aria-describedby":W,onClick:()=>{E||M()},"data-active":N,children:E?n.jsx(yt,{className:"h-4 w-4 animate-spin"}):n.jsx(ds,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:E?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(ft,{children:"⌘"}),n.jsx(ft,{children:"⇧"}),n.jsx(ft,{children:"K"})]})]})})]})]}),se=h&&e?n.jsxs(Ce,{children:[n.jsx(Te,{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(Tn,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:x?"Launching…":"Launch app"})]}):null;return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:Z,style:{display:"none"}}),n.jsx(Hn,{open:Me,onOpenChange:Ue,openUrl:o}),n.jsx($n,{joined:c,onDeepLink:()=>Ue(!0),onScreenshot:V,onRecordToggle:me,recordState:ye,onRotate:qe,navigationSlot:D,deviceSlot:_,launchSlot:se,network:L?{position:st.position,steerable:st.steerable,reason:st.reason,pending:st.pending,onToggle:st.toggle}:void 0,reboot:{pending:k,onReboot:F,buttonRef:G}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsxs("div",{ref:ue,style:{width:J?ct:it,height:J?it:ct,position:"relative",flexShrink:0},children:[n.jsxs("div",{ref:Q,className:`relative ${Ve?"cursor-pointer":"cursor-default"}`,style:{width:it,height:ct,...J?{position:"absolute",top:(it-ct)/2,left:(ct-it)/2,transform:"rotate(-90deg)",transformOrigin:"center center"}:{}},onPointerDown:Je,onPointerMove:at,onPointerUp:$t,onPointerCancel:Qe,onPointerLeave:Ft,children:[n.jsx("img",{src:`data:image/png;base64,${f.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:B,style:{position:"absolute",zIndex:3,left:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,borderRadius:R>0?`${R}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:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,borderRadius:R>0?`${R}px`:void 0}}),Y&&(()=>{const l=lt/100,y=mt/100,m=gt/100,A=xt/100,P=(S,I)=>({left:`${(l+S*m)*100}%`,top:`${(y+I*A)*100}%`});return n.jsx(n.Fragment,{children:[Y.f0,Y.f1].map((S,I)=>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",...ve?{width:ut*2,height:ut*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:ze*2,height:ze*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(S.x,S.y)}},I))})})(),c&&Ie===0&&n.jsx("div",{style:{position:"absolute",zIndex:8,left:`${lt}%`,top:`${mt}%`,width:`${gt}%`,height:`${xt}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n.jsx("span",{style:{color:"white",fontSize:"0.875rem"},children:"Waiting for first frame..."})}),f.buttons.map(l=>{const y=We===l.name,m=Ve===l.name,A=l.anchor==="top",P=In(l),S=P.top/f.compositeHeight*100,I=l.buttonH/f.compositeHeight*100,$=l.buttonW/f.compositeWidth*100,le=l.buttonW/2,De=P.left/f.compositeWidth*100,Fe=(2*l.rolloverOffset.x-l.normalOffset.x-le)/f.compositeWidth*100,Ze=l.rolloverOffset.x/f.compositeWidth*100,At=S,bt=A?(2*l.rolloverOffset.y-l.normalOffset.y)/f.compositeHeight*100:0,hr=l.onTop?4:1;return n.jsxs(s.Fragment,{children:[l.buttonPng&&n.jsx("img",{src:`data:image/png;base64,${l.buttonPng}`,style:{position:"absolute",zIndex:hr,top:`${A&&m?bt:S}%`,left:`${A?De:m?Fe:De}%`,width:`${$}%`,height:`${I}%`,transition:A?"top 0.15s ease":"left 0.15s ease",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),y&&l.pressedPng&&l.pressedRect&&n.jsx("img",{src:`data:image/png;base64,${l.pressedPng}`,style:{position:"absolute",zIndex:l.onTop?3:1,left:`${A?De:m?Fe:De}%`,top:`${A&&m?bt:S}%`,width:`${l.pressedRect.width/f.compositeWidth*100}%`,height:`${l.pressedRect.height/f.compositeHeight*100}%`,pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),m&&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:`${Ze}%`,top:`${At}%`,transform:"translate(-50%, calc(-100% - 8px))"},children:l.accessibilityTitle})]},l.name)})]}),n.jsx("div",{ref:Pe,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:c,fps:Ie,connected:a,deviceReady:u,bootError:g,installing:d,installError:p,decoderUnsupported:K,keyboardActive:de})]})]})}const dt=13,kt=8,wn=16,Wo=.02,zt=720;function Vo({sessionId:t,buildId:e,send:r,openUrl:o,launchApp:i,connected:a,joined:c,deviceReady:u,installing:d,installed:h,installError:p,bootError:g,launching:x,androidButtons:f,binaryFrameHandlerRef:b,clipboardHandlerRef:v,clipboardSupported:T,networkHandlerRef:j,networkSupported:L,onRecordingUploaded:C,rebootPending:N,onReboot:E,restartButtonRef:M,screenWidth:k,screenHeight:F,cornerRadius:G,perfHookRef:z}){const B=s.useRef(null),Q=s.useRef(null),ue=s.useRef(null),{fps:Ie,frameCount:Be}=Un(),{recordState:be,recordCanvasRef:ye,startClientRecording:Z,stopClientRecording:Ae}=Mn({sessionId:t,buildId:e,onRecordingUploaded:C}),[Oe,He]=s.useState(!1),[Me,Ue]=s.useState(!1),[U,q]=s.useState(!1),K=s.useRef(null),[Se,J]=s.useState(null),[Re,de]=s.useState(!1),[ee,We]=s.useState(!1),[rt,Ve]=s.useState(!1),[fe,ve]=s.useState(null),ke=s.useRef(fe);s.useEffect(()=>{ke.current=fe},[fe]);const Y=s.useRef(!1),he=s.useRef(!1),$e=s.useRef(null),ge=s.useRef(0),oe=s.useRef(null),re=s.useRef(null),ae=s.useRef("idle"),_e=s.useRef(null);Vn({binaryFrameHandlerRef:b,perfHookRef:z,frameCount:Be,onUnsupported:()=>q(!0),onResize:R=>{Ue(!0);const D=K.current;(!D||D.width!==R.width||D.height!==R.height)&&(K.current=R,J(R))},onDecoderReady:R=>{var W;ue.current=R;const D=R.surface;D.style.display="block",D.style.width="100%",D.style.height="100%",D.style.objectFit="fill",(W=B.current)==null||W.appendChild(D)}});const Pe=s.useCallback(()=>{var le;const R=ye.current,D=(le=ue.current)==null?void 0:le.surface,W=K.current;if(!R||!D||!W)return;const _=R.getContext("2d");if(!_)return;const se=W.width,l=W.height,y=R.width>R.height!=se>l;_.save(),y&&(_.translate(R.width,0),_.rotate(Math.PI/2)),_.drawImage(D,0,0,se,l);const m=Math.max(se,l),A=m>zt?m/zt:1,P=dt*A,S=kt*A,I=ke.current;if(I)for(const De of[I.f0,I.f1]){const Fe=De.x*se,Ze=De.y*l;Y.current?(_.beginPath(),_.arc(Fe,Ze,S,0,Math.PI*2),_.fillStyle="rgba(255,255,255,0.92)",_.fill(),_.strokeStyle="rgba(0,0,0,0.2)",_.lineWidth=A,_.stroke()):(_.beginPath(),_.arc(Fe,Ze,P,0,Math.PI*2),_.strokeStyle="rgba(0,0,0,0.3)",_.lineWidth=3*A,_.stroke(),_.beginPath(),_.arc(Fe,Ze,P,0,Math.PI*2),_.strokeStyle="rgba(255,255,255,0.65)",_.lineWidth=1.5*A,_.stroke())}const $=re.current;if($){const De=$.x*se,Fe=$.y*l,Ze=ae.current,At=_e.current;if(Ze==="down")_.beginPath(),_.arc(De,Fe,S,0,Math.PI*2),_.fillStyle="rgba(255,255,255,0.92)",_.fill(),_.strokeStyle="rgba(0,0,0,0.2)",_.lineWidth=A,_.stroke();else if(Ze==="release"&&At){const bt=Math.min((performance.now()-At.startTime)/350,1);_.beginPath(),_.arc(De,Fe,S+26*A*bt,0,Math.PI*2),_.strokeStyle=`rgba(255,255,255,${(1-bt)*.55})`,_.lineWidth=1.5*A,_.stroke(),bt>=1&&(ae.current="idle",_e.current=null)}else _.beginPath(),_.arc(De,Fe,P,0,Math.PI*2),_.strokeStyle="rgba(0,0,0,0.3)",_.lineWidth=3*A,_.stroke(),_.beginPath(),_.arc(De,Fe,P,0,Math.PI*2),_.strokeStyle="rgba(255,255,255,0.65)",_.lineWidth=1.5*A,_.stroke()}_.restore()},[ye]),je=s.useCallback(()=>{var se;const R=(se=ue.current)==null?void 0:se.surface,D=K.current;if(!R||!D)return;const W=document.createElement("canvas"),_=W.getContext("2d");_&&(W.width=D.width,W.height=D.height,_.drawImage(R,0,0,D.width,D.height),W.toBlob(l=>{if(!l)return;const y=URL.createObjectURL(l),m=document.createElement("a");m.href=y,m.download=`tapflow-${Date.now()}.png`,m.click(),URL.revokeObjectURL(y)},"image/png"))},[]),we=s.useCallback(()=>{if(be==="idle"){const R=ye.current;if(!R)return;const D=K.current;if(!D)return;const W=V.current;R.width=W?D.height:D.width,R.height=W?D.width:D.height,Z(Pe)}else be==="recording"&&Ae()},[be,Z,Ae,Pe,ye]),w=s.useCallback(()=>{r({type:"input:rotate",sessionId:t}),de(R=>!R)},[r,t]),H=s.useRef(Re);s.useEffect(()=>{H.current=Re},[Re]),s.useEffect(()=>()=>{H.current&&r({type:"input:rotate",sessionId:t})},[]);const ce=s.useCallback((R,D)=>{r({type:"input:key",sessionId:t,requestId:X(),payload:{code:R,modifiers:D}})},[r,t]);qn({sessionId:t,send:r,active:ee,supported:T,handlerRef:v,sendChord:ce,onError:R=>Ne.error(R)});const pe=Fn({sessionId:t,send:r,supported:L,deviceReady:u,handlerRef:j,onError:R=>Ne.error(R)});s.useEffect(()=>{const R=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),D=l=>{if(l.code==="AltLeft"||l.code==="AltRight"){he.current=!0;return}if(l.metaKey){const m=document.activeElement;if(!m||m.tagName!=="INPUT"&&m.tagName!=="TEXTAREA"){if(!l.shiftKey&&l.code==="KeyK"){l.preventDefault(),He(!0);return}if(!l.shiftKey&&l.code==="KeyS"){l.preventDefault(),je();return}if(l.shiftKey&&l.code==="KeyY"){l.preventDefault(),we();return}if(l.shiftKey&&l.code==="KeyO"){l.preventDefault(),w();return}}}if(!ee||R.has(l.code)||T&&Zt(l))return;l.preventDefault();const y=(l.shiftKey?2:0)|(l.ctrlKey?1:0)|(l.metaKey?8:0);r({type:"input:key",sessionId:t,requestId:X(),payload:{code:l.code,modifiers:y}})},W=()=>{Y.current&&(Y.current=!1,Ve(!1),r({type:"input:pinch:end",sessionId:t,requestId:X()})),he.current=!1,ve(null)},_=l=>{(l.code==="AltLeft"||l.code==="AltRight")&&W()},se=()=>{he.current&&W()};return window.addEventListener("keydown",D),window.addEventListener("keyup",_),window.addEventListener("blur",se),()=>{window.removeEventListener("keydown",D),window.removeEventListener("keyup",_),window.removeEventListener("blur",se)}},[ee,T,r,t,je,we,w]),s.useEffect(()=>{if(!ee)return;const R=D=>{const W=Q.current??B.current;W&&!W.contains(D.target)&&We(!1)};return document.addEventListener("pointerdown",R),()=>document.removeEventListener("pointerdown",R)},[ee]);const V=s.useRef(!1),me=s.useCallback(R=>{const D=B.current;if(!D)return null;const W=D.getBoundingClientRect();return ko({x:R.clientX,y:R.clientY},W,V.current)},[]),qe=s.useCallback(R=>{const D=me(R);return D?zn(D):null},[me]),Nt=s.useCallback(R=>{if(he.current){const se=qe(R);if(!se)return;Y.current=!0,Ve(!0),R.target.setPointerCapture(R.pointerId);const l=oe.current;l&&(l.style.display="none"),ve(se),r({type:"input:pinch:start",sessionId:t,payload:se});return}const D=me(R);if(!D)return;We(!0),$e.current=D,R.target.setPointerCapture(R.pointerId);const W=R.currentTarget.getBoundingClientRect();re.current=D,ae.current="down",_e.current=null;const _=oe.current;_&&(_.style.display="block",_.style.left=`${R.clientX-W.left}px`,_.style.top=`${R.clientY-W.top}px`,_.style.width=`${kt*2}px`,_.style.height=`${kt*2}px`,_.style.background="rgba(255,255,255,0.92)",_.style.border="1.5px solid rgba(0,0,0,0.2)",_.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:D})},[me,qe,r,t]),Ut=s.useCallback(R=>{if(R.buttons===0){if(he.current){ve(qe(R)),re.current=null;const S=oe.current;S&&(S.style.display="none");return}const m=me(R),A=R.currentTarget.getBoundingClientRect(),P=oe.current;m?(re.current=m,ae.current!=="down"&&(ae.current="idle"),P&&(P.style.display="block",P.style.left=`${R.clientX-A.left}px`,P.style.top=`${R.clientY-A.top}px`,P.style.width=`${dt*2}px`,P.style.height=`${dt*2}px`,P.style.background="transparent",P.style.border="1.5px solid rgba(255,255,255,0.6)",P.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)")):(re.current=null,P&&(P.style.display="none"));return}if(Y.current){const m=qe(R);if(!m)return;const A=performance.now();if(A-ge.current<wn)return;ge.current=A,ve(m),r({type:"input:pinch:move",sessionId:t,payload:m});return}if(!$e.current)return;const D=me(R);if(!D)return;const W=D.x-$e.current.x,_=D.y-$e.current.y;if(Math.sqrt(W*W+_*_)<Wo)return;const se=performance.now();if(se-ge.current<wn)return;ge.current=se;const l=R.currentTarget.getBoundingClientRect();re.current=D;const y=oe.current;y&&y.style.display!=="none"&&(y.style.left=`${R.clientX-l.left}px`,y.style.top=`${R.clientY-l.top}px`),r({type:"input:touch:move",sessionId:t,payload:D})},[me,qe,r,t]),st=s.useCallback(()=>{if(Y.current){Y.current=!1,Ve(!1),ve(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}$e.current=null,ae.current="release",_e.current={startTime:performance.now()};const R=oe.current;R&&(R.style.width=`${dt*2}px`,R.style.height=`${dt*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]),Xe=s.useCallback(()=>{if(Y.current){Y.current=!1,Ve(!1),ve(null),r({type:"input:pinch:end",sessionId:t,requestId:X()});return}$e.current=null,ae.current="release",_e.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:t,requestId:X()})},[r,t]),ot=s.useCallback(()=>{ve(null),re.current=null;const R=oe.current;R&&(R.style.display="none")},[]),xe=Se??(k&&F?{width:k,height:F}:null),Ge=xe?Math.min(1,zt/Math.max(xe.width,xe.height)):.3,Je=xe?Math.round(xe.width*Ge):324,at=xe?Math.round(xe.height*Ge):720,$t=xe?xe.width>xe.height:!1,Qe=Re&&!$t;s.useLayoutEffect(()=>{V.current=Qe},[Qe]);const Ft=Qe?at:Je,Bt=Qe?Je:at,vt=G!=null?Math.round(G*Je):22,cn=Qe?{position:"absolute",width:Je,height:at,top:(Je-at)/2,left:(at-Je)/2,transform:"rotate(90deg)",transformOrigin:"center center",visibility:Me?"visible":"hidden",cursor:"none"}:{visibility:Me?"visible":"hidden",cursor:"none"},wt=["home","back","recent_apps"],it=["volume_up","volume_down","power"],ct=R=>R==="back"?n.jsx(Qr,{className:"h-4 w-4"}):R==="recent_apps"?n.jsx(pr,{className:"h-4 w-4"}):R==="volume_up"?n.jsx(Ls,{className:"h-4 w-4"}):R==="volume_down"?n.jsx(Ps,{className:"h-4 w-4"}):R==="power"?n.jsx(xs,{className:"h-4 w-4"}):n.jsx(Dn,{className:"h-4 w-4"}),lt=R=>n.jsx(n.Fragment,{children:R.map(D=>f==null?void 0:f.find(W=>W.name===D)).filter(D=>D!==void 0).map(D=>n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx(ie,{variant:"ghost",size:"icon",className:"h-8 w-8","aria-label":D.accessibilityTitle,onClick:()=>r({type:"input:button",sessionId:t,requestId:X(),payload:{name:D.name}}),children:ct(D.name)})}),n.jsx(Ee,{side:"left",children:D.accessibilityTitle})]},D.name))}),mt=lt(wt),gt=lt(it),xt=h&&e?n.jsxs(Ce,{children:[n.jsx(Te,{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(Tn,{className:"h-4 w-4"})})}),n.jsx(Ee,{side:"left",children:x?"Launching…":d?"Installing…":"Launch app"})]}):null;return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:ye,style:{display:"none"}}),n.jsx(Hn,{open:Oe,onOpenChange:He,openUrl:o}),n.jsx($n,{joined:c,onDeepLink:()=>He(!0),onScreenshot:je,onRecordToggle:we,recordState:be,onRotate:w,navigationSlot:mt,deviceSlot:gt,launchSlot:xt,network:L?{position:pe.position,steerable:pe.steerable,reason:pe.reason,pending:pe.pending,onToggle:pe.toggle}:void 0,reboot:{pending:N,onReboot:E,buttonRef:M}}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{style:{background:"#1c1c1e",borderRadius:`${vt+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:Q,className:"relative",style:{width:Ft,height:Bt,backgroundColor:"#010101",borderRadius:`${vt}px`,overflow:"hidden"},children:!U&&n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:B,className:Qe?void 0:"block w-full h-full",style:cn,onPointerDown:Nt,onPointerMove:Ut,onPointerUp:st,onPointerCancel:Xe,onPointerLeave:ot}),!Me&&n.jsx("div",{className:"absolute inset-0 animate-pulse bg-zinc-700"}),!Me&&u&&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: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"}}),fe&&n.jsx(n.Fragment,{children:[fe.f0,fe.f1].map((R,D)=>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}%`,...rt?{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:dt*2,height:dt*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"}}},D))})]})})}),n.jsx(Qt,{joined:c,fps:Ie,connected:a,deviceReady:u,bootError:g,installing:d,installError:p,decoderUnsupported:U,keyboardActive:ee})]})]})}function qo(t,e){const r=new DataView(t),o=Math.floor(t.byteLength/2),i=Math.floor(o/e),a=[];for(let c=0;c<e;c++)a.push(new Float32Array(i));for(let c=0;c<i;c++)for(let u=0;u<e;u++){const d=r.getInt16((c*e+u)*2,!0);a[u][c]=d/32768}return a}const Xo=44100,Wt=2,Sn=.06,Ko=.3;function Yo(){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 c=qo(i,Wt),u=((x=c[0])==null?void 0:x.length)??0;if(u===0)return;const d=a.createBuffer(Wt,u,Xo);for(let f=0;f<Wt;f++)d.getChannelData(f).set(c[f]);const h=a.createBufferSource();h.buffer=d,h.connect(a.destination);const p=a.currentTime;let g=e.current;(g<p+.005||g>p+Ko+Sn)&&(g=p+Sn),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 Go=2e4;function Jo({sessionId:t,deviceId:e,deviceReady:r,send:o,handlerRef:i,onShutdownComplete:a,onError:c}){const[u,d]=s.useState(!1),h=s.useRef(null),p=s.useRef(a),g=s.useRef(c);s.useEffect(()=>{p.current=a},[a]),s.useEffect(()=>{g.current=c},[c]),s.useEffect(()=>{d(!1),h.current=null},[t]),s.useEffect(()=>{r||(d(!1),h.current=null)},[r]),s.useEffect(()=>(i.current=v=>{if(v.requestId===h.current){if(h.current=null,d(!1),v.type==="device:shutdown-error"){g.current(`The device was not restarted. ${v.message}`);return}p.current()}},()=>{i.current=void 0}),[i]);const[x,f]=s.useState(null);s.useEffect(()=>{f(u?h.current:null)},[u]),s.useEffect(()=>{if(x===null)return;const v=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."))},Go);return()=>clearTimeout(v)},[x]);const b=s.useCallback(()=>{if(u)return;const v=X();h.current=v,d(!0),o({type:"device:shutdown",sessionId:t,requestId:v,payload:{deviceId:e}})},[u,o,t,e]);return{pending:u,reboot:b}}const Rn={"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(Rn,t)?t:"channel-unavailable";return{key:e,notice:Rn[e]}}function Zo({sessionId:t,deviceId:e,buildId:r,resetMode:o,onRecordingUploaded:i,onSessionEnded:a}){const c=s.useRef(()=>{}),u=s.useRef(!1),d=s.useRef({pending:0,appInstalled:!1});$s();const h=s.useRef(null),p=s.useRef(null),g=s.useRef([]);s.useRef({onFrameBegin:()=>{var w;return(w=h.current)==null?void 0:w.onFrameBegin()},onFrameEnd:w=>{var pe,V;const H=g.current.shift()??null,ce=H?{...w,capturedAt:H.capturedAt,relayedAt:H.relayedAt}:w;(pe=h.current)==null||pe.onFrameEnd(ce),(V=p.current)==null||V.call(p,ce)}});const[x,f]=s.useState(!1),[b,v]=s.useState(!1),[T,j]=s.useState(!1),[L,C]=s.useState(null),[N,E]=s.useState(!1),[M,k]=s.useState(!1),[F,G]=s.useState(null),[z,B]=s.useState(null),[Q,ue]=s.useState(!1),[Ie,Be]=s.useState([]),be=s.useRef(new Set),ye=s.useRef(null),Z=s.useRef(new Set),Ae=s.useRef(new Set),Oe=s.useRef(new Set),[He,Me]=s.useState(!1),Ue=8e3,[U,q]=s.useState(!1),K=s.useRef(null);s.useEffect(()=>()=>{K.current&&clearTimeout(K.current)},[]);const Se=s.useRef(void 0),J=s.useRef(void 0),Re=s.useRef(void 0),de=s.useRef(void 0),ee=s.useCallback(w=>{const H=X();be.current.add(H),ye.current=H,c.current({type:"device:boot",sessionId:t,requestId:H,payload:{deviceId:e,resetMode:w,acceptH264:go(),secureContext:window.isSecureContext}})},[t,e]),{pushFrame:We}=Yo(),rt=s.useCallback(w=>{var H,ce,pe;if(!("sessionId"in w&&w.sessionId!==t)){if(w.type==="session:joined"){d.current={pending:0,appInstalled:!1},f(!0),v(!1),Be(w.capabilities??[]);const V=u.current?"app-only":o;u.current=!0,be.current.clear(),ee(V)}if(w.type==="session:agent-away"){v(!0),C(null),j(!1);return}if(w.type==="session:terminated"){a==null||a(w.reason);return}if(w.type==="session:rebound"){j(!1),C(null),E(!1),G(null),B(null),ue(!1),q(!1),K.current&&clearTimeout(K.current),Me(!1),g.current=[],Be(w.capabilities);const V=b;v(!1),d.current={pending:d.current.pending+1,appInstalled:d.current.pending>0?d.current.appInstalled:M},u.current=!0,ee("app-only"),V||Ne.info("The agent restarted — reconnecting to the device.");return}if(w.type==="device:boot-error"){if(w.requestId!==void 0&&w.requestId!==ye.current||b)return;d.current={pending:0,appInstalled:!1},B(w.message)}if(w.type==="input:error"){if(b)return;const{key:V,notice:me}=Qo(w.reason);w.reason!==void 0&&w.reason!==V&&console.debug(`[tapflow] unrecognised input:error reason "${w.reason}", treated as ${V}`),me?Ne.error(me.title,{id:`input:${t}:${V}`,description:w.message?`${me.action} (${w.message})`:me.action,duration:6e3}):console.debug(`[tapflow] input refused, shown nowhere: ${V}${w.message?` — ${w.message}`:""}`)}if(w.type==="device:booting"&&(j(!1),E(!1),k(!1),G(null),B(null),Ae.current.clear(),Oe.current.clear(),C(null)),w.type==="device:ready"){if(j(!0),w.requestId!==void 0&&!be.current.delete(w.requestId))return;if(d.current.pending>0){const{appInstalled:V}=d.current;if(d.current={pending:d.current.pending-1,appInstalled:V},V){k(!0);return}}if(r){E(!0);const V=X();Ae.current.add(V),c.current({type:"app:install",sessionId:t,requestId:V,buildId:r})}}if(w.type==="app:install-done"||w.type==="app:install-error"){if(!Ae.current.delete(w.requestId))return;E(!1),w.type==="app:install-done"?k(!0):G(w.message)}if(w.type==="app:launch-done"||w.type==="app:launch-error"){if(!Oe.current.delete(w.requestId))return;ue(!1)}if(w.type==="session:chrome"&&C(w.payload),w.type==="keyboard:toggled"){const{visible:V}=w.payload;Me(V),q(!1),K.current&&clearTimeout(K.current)}if(w.type==="network:state"||w.type==="network:error"){(H=Re.current)==null||H.call(Re,w);return}if(w.type==="device:shutdown-done"||w.type==="device:shutdown-error"){(ce=de.current)==null||ce.call(de,w);return}if((w.type==="clipboard:data"||w.type==="clipboard:write-done"||w.type==="clipboard:error")&&((pe=J.current)==null||pe.call(J,w)),w.type==="open-url:done"||w.type==="open-url:error"){if(!Z.current.delete(w.requestId))return;w.type==="open-url:done"?Ne.success("Deeplink opened"):Ne.error(w.message)}if(w.type==="error")switch(w.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,b,ee]),Ve=s.useCallback(w=>{var V;const H=_o(w);if(H&&H.codec===Wn){We(w.slice(Kt));return}H&&H.codec===It||g.current.push(H);const ce=H?w.slice(Kt):w,pe=H?{codec:H.codec,keyframe:H.keyframe,capturedAt:H.capturedAt,relayedAt:H.relayedAt}:void 0;(V=Se.current)==null||V.call(Se,ce,pe)},[We]),{send:fe,connected:ve}=En(rt,Ve);s.useLayoutEffect(()=>{c.current=fe}),s.useEffect(()=>{ve&&fe({type:"session:start",sessionId:t})},[ve,fe,t]);const ke=L!==null&&"framePng"in L?L:null,Y=L!==null&&!("framePng"in L)?L:null,he=()=>{q(!0),K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{q(!1),Ne.error("The device did not answer. The software keyboard is where it was, as far as tapflow can tell.")},Ue),fe({type:"input:keyboard:toggle",sessionId:t})},$e=s.useCallback(w=>{const H=X();Z.current.add(H),c.current({type:"open-url",sessionId:t,requestId:H,payload:{url:w}})},[t]),ge=s.useCallback(()=>{if(r===void 0)return;const w=X();Oe.current.add(w),ue(!0),c.current({type:"app:launch",sessionId:t,requestId:w,buildId:r})},[t,r]),oe=s.useRef(null),re=s.useRef(!1),ae=s.useRef(!1),{pending:_e,reboot:Pe}=Jo({sessionId:t,deviceId:e,deviceReady:T,send:fe,handlerRef:de,onShutdownComplete:s.useCallback(()=>{ae.current=!0,ee("app-only")},[ee]),onError:s.useCallback(w=>{Ne.error(w)},[])});s.useEffect(()=>{var ce;const w=!!(ke??Y),H=!re.current&&w;re.current=w,!(!H||!ae.current)&&(ae.current=!1,document.activeElement===document.body&&((ce=oe.current)==null||ce.focus()))},[ke,Y]),s.useEffect(()=>{(z||b)&&(ae.current=!1)},[z,b]);const je={sessionId:t,buildId:r,send:fe,openUrl:$e,launchApp:ge,connected:ve,joined:x,deviceReady:T,installing:N,installed:M,installError:F,bootError:z,launching:Q,binaryFrameHandlerRef:Se,clipboardHandlerRef:J,clipboardSupported:Ie.includes("clipboard"),networkHandlerRef:Re,networkSupported:Ie.includes("network-control"),onRecordingUploaded:i,swKeyboardVisible:He,swKeyboardPending:U,onKbdToggle:he,rebootPending:_e,onReboot:Pe,restartButtonRef:oe};if(!ke&&!Y)return n.jsxs("div",{role:"region","aria-label":"Device screen",className:"flex items-start justify-center gap-16",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((w,H)=>n.jsx("div",{className:"h-8 w-8 rounded-md bg-muted animate-pulse"},H))}),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:ve,deviceReady:T,bootError:z,installing:N,installError:F,decoderUnsupported:!1,keyboardActive:!1,agentAway:b})]})]});const we=void 0;return n.jsxs(n.Fragment,{children:[ke&&n.jsx(zo,{...je,chrome:ke,perfHookRef:we}),Y&&n.jsx(Vo,{...je,androidButtons:Y.buttons,screenWidth:Y.screenWidth,screenHeight:Y.screenHeight,cornerRadius:Y.cornerRadius,perfHookRef:we}),!1]})}const Xn=s.forwardRef(({className:t,...e},r)=>n.jsx("textarea",{className:te("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 ea=Object.defineProperty,O=(t,e)=>ea(t,"name",{value:e,configurable:!0});function Kn(t,e){return s.useReducer((r,o)=>e[r][o]??r,t)}O(Kn,"useStateMachine");var Yn="ScrollArea",[Gn,Ka]=Cn(Yn),[ta,Le]=Gn(Yn),na=s.forwardRef(O(function(e,r){const{__scopeScrollArea:o,type:i="hover",dir:a,scrollHideDelay:c=600,...u}=e,[d,h]=s.useState(null),[p,g]=s.useState(null),[x,f]=s.useState(null),[b,v]=s.useState(null),[T,j]=s.useState(null),[L,C]=s.useState(0),[N,E]=s.useState(0),[M,k]=s.useState(!1),[F,G]=s.useState(!1),z=tt(r,h),B=gr(a);return n.jsx(ta,{scope:o,type:i,dir:B,scrollHideDelay:c,scrollArea:d,viewport:p,onViewportChange:g,content:x,onContentChange:f,scrollbarX:b,onScrollbarXChange:v,scrollbarXEnabled:M,onScrollbarXEnabledChange:k,scrollbarY:T,onScrollbarYChange:j,scrollbarYEnabled:F,onScrollbarYEnabledChange:G,onCornerWidthChange:C,onCornerHeightChange:E,children:n.jsx(nt.div,{dir:B,...u,ref:z,style:{position:"relative","--radix-scroll-area-corner-width":L+"px","--radix-scroll-area-corner-height":N+"px",...e.style}})})},"ScrollArea")),ra="ScrollAreaViewport",sa=s.forwardRef(O(function(e,r){const{__scopeScrollArea:o,children:i,nonce:a,...c}=e,u=Le(ra,o),d=s.useRef(null),h=tt(r,d,u.onViewportChange);return n.jsxs(n.Fragment,{children:[n.jsx(oa,{nonce:a}),n.jsx(nt.div,{"data-radix-scroll-area-viewport":"",...c,ref:h,style:{overflowX:u.scrollbarXEnabled?"scroll":"hidden",overflowY:u.scrollbarYEnabled?"scroll":"hidden",...e.style},children:n.jsx("div",{ref:u.onContentChange,style:{minWidth:"100%",display:"table"},children:i})})]})},"ScrollAreaViewport")),oa=s.memo(O(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),Ye="ScrollAreaScrollbar",Jn=s.forwardRef(O(function(e,r){const{forceMount:o,...i}=e,a=Le(Ye,e.__scopeScrollArea),{onScrollbarXEnabledChange:c,onScrollbarYEnabledChange:u}=a,d=e.orientation==="horizontal";return s.useEffect(()=>(d?c(!0):u(!0),()=>{d?c(!1):u(!1)}),[d,c,u]),a.type==="hover"?n.jsx(aa,{...i,ref:r,forceMount:o}):a.type==="scroll"?n.jsx(ia,{...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")),aa=s.forwardRef(O(function(e,r){const{forceMount:o,...i}=e,a=Le(Ye,e.__scopeScrollArea),[c,u]=s.useState(!1);return s.useEffect(()=>{const d=a.scrollArea;let h=0;if(d){const p=O(()=>{window.clearTimeout(h),u(!0)},"handlePointerEnter"),g=O(()=>{h=window.setTimeout(()=>u(!1),a.scrollHideDelay)},"handlePointerLeave");return d.addEventListener("pointerenter",p),d.addEventListener("pointerleave",g),()=>{window.clearTimeout(h),d.removeEventListener("pointerenter",p),d.removeEventListener("pointerleave",g)}}},[a.scrollArea,a.scrollHideDelay]),n.jsx(Mt,{present:o||c,children:n.jsx(Qn,{"data-state":c?"visible":"hidden",...i,ref:r})})},"ScrollAreaScrollbarHover")),ia=s.forwardRef(O(function(e,r){const{forceMount:o,...i}=e,a=Le(Ye,e.__scopeScrollArea),c=e.orientation==="horizontal",u=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 p=window.setTimeout(()=>h("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(p)}},[d,a.scrollHideDelay,h]),s.useEffect(()=>{const p=a.viewport,g=c?"scrollLeft":"scrollTop";if(p){let x=p[g];const f=O(()=>{const b=p[g];x!==b&&(h("SCROLL"),u()),x=b},"handleScroll");return p.addEventListener("scroll",f),()=>p.removeEventListener("scroll",f)}},[a.viewport,c,h,u]),n.jsx(Mt,{present:o||d!=="hidden",children:n.jsx(en,{"data-state":d==="hidden"?"hidden":"visible",...i,ref:r,onPointerEnter:Ke(e.onPointerEnter,()=>h("POINTER_ENTER")),onPointerLeave:Ke(e.onPointerLeave,()=>h("POINTER_LEAVE"))})})},"ScrollAreaScrollbarScroll")),Qn=s.forwardRef(O(function(e,r){const o=Le(Ye,e.__scopeScrollArea),{forceMount:i,...a}=e,[c,u]=s.useState(!1),d=e.orientation==="horizontal",h=Et(()=>{if(o.viewport){const p=o.viewport.offsetWidth<o.viewport.scrollWidth,g=o.viewport.offsetHeight<o.viewport.scrollHeight;u(d?p:g)}},10);return pt(o.viewport,h),pt(o.content,h),n.jsx(Mt,{present:i||c,children:n.jsx(en,{"data-state":c?"visible":"hidden",...a,ref:r})})},"ScrollAreaScrollbarAuto")),en=s.forwardRef(O(function(e,r){const{orientation:o="vertical",...i}=e,a=Le(Ye,e.__scopeScrollArea),c=s.useRef(null),u=s.useRef(0),[d,h]=s.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),p=tn(d.viewport,d.content),g={...i,sizes:d,onSizesChange:h,hasThumb:p>0&&p<1,onThumbChange:O(f=>c.current=f,"onThumbChange"),onThumbPointerUp:O(()=>u.current=0,"onThumbPointerUp"),onThumbPointerDown:O(f=>u.current=f,"onThumbPointerDown")};function x(f,b){return nr(f,u.current,d,b)}return O(x,"getScrollPosition"),o==="horizontal"?n.jsx(ca,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&c.current){const f=a.viewport.scrollLeft,b=Gt(f,d,a.dir);c.current.style.transform=`translate3d(${b}px, 0, 0)`}},onWheelScroll:f=>{a.viewport&&(a.viewport.scrollLeft=f)},onDragScroll:f=>{a.viewport&&(a.viewport.scrollLeft=x(f,a.dir))}}):o==="vertical"?n.jsx(la,{...g,ref:r,onThumbPositionChange:()=>{if(a.viewport&&c.current){const f=a.viewport.scrollTop,b=Gt(f,d);c.current.style.transform=`translate3d(0, ${b}px, 0)`}},onWheelScroll:f=>{a.viewport&&(a.viewport.scrollTop=f)},onDragScroll:f=>{a.viewport&&(a.viewport.scrollTop=x(f))}}):null},"ScrollAreaScrollbarVisible")),ca=s.forwardRef(O(function(e,r){const{sizes:o,onSizesChange:i,...a}=e,c=Le(Ye,e.__scopeScrollArea),[u,d]=s.useState(),h=s.useRef(null),p=tt(r,h,c.onScrollbarXChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(er,{"data-orientation":"horizontal",...a,ref:p,sizes:o,style:{bottom:0,left:c.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:c.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(c.viewport){const f=c.viewport.scrollLeft+g.deltaX;e.onWheelScroll(f),rn(f,x)&&g.preventDefault()}},onResize:()=>{h.current&&c.viewport&&u&&i({content:c.viewport.scrollWidth,viewport:c.viewport.offsetWidth,scrollbar:{size:h.current.clientWidth,paddingStart:Ct(u.paddingLeft),paddingEnd:Ct(u.paddingRight)}})}})},"ScrollAreaScrollbarX")),la=s.forwardRef(O(function(e,r){const{sizes:o,onSizesChange:i,...a}=e,c=Le(Ye,e.__scopeScrollArea),[u,d]=s.useState(),h=s.useRef(null),p=tt(r,h,c.onScrollbarYChange);return s.useEffect(()=>{h.current&&d(getComputedStyle(h.current))},[h]),n.jsx(er,{"data-orientation":"vertical",...a,ref:p,sizes:o,style:{top:0,right:c.dir==="ltr"?0:void 0,left:c.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(c.viewport){const f=c.viewport.scrollTop+g.deltaY;e.onWheelScroll(f),rn(f,x)&&g.preventDefault()}},onResize:()=>{h.current&&c.viewport&&u&&i({content:c.viewport.scrollHeight,viewport:c.viewport.offsetHeight,scrollbar:{size:h.current.clientHeight,paddingStart:Ct(u.paddingTop),paddingEnd:Ct(u.paddingBottom)}})}})},"ScrollAreaScrollbarY")),[ua,Zn]=Gn(Ye),er=s.forwardRef(O(function(e,r){const{__scopeScrollArea:o,sizes:i,hasThumb:a,onThumbChange:c,onThumbPointerUp:u,onThumbPointerDown:d,onThumbPositionChange:h,onDragScroll:p,onWheelScroll:g,onResize:x,...f}=e,b=Le(Ye,o),[v,T]=s.useState(null),j=tt(r,T),L=s.useRef(null),C=s.useRef(""),N=b.viewport,E=i.content-i.viewport,M=ht(g),k=ht(h),F=Et(x,10);function G(z){if(L.current){const B=z.clientX-L.current.left,Q=z.clientY-L.current.top;p({x:B,y:Q})}}return O(G,"handleDragScroll"),s.useEffect(()=>{const z=O(B=>{const Q=B.target;(v==null?void 0:v.contains(Q))&&M(B,E)},"handleWheel");return document.addEventListener("wheel",z,{passive:!1}),()=>document.removeEventListener("wheel",z,{passive:!1})},[N,v,E,M]),s.useEffect(k,[i,k]),pt(v,F),pt(b.content,F),n.jsx(ua,{scope:o,scrollbar:v,hasThumb:a,onThumbChange:ht(c),onThumbPointerUp:ht(u),onThumbPositionChange:k,onThumbPointerDown:ht(d),children:n.jsx(nt.div,{...f,ref:j,style:{position:"absolute",...f.style},onPointerDown:Ke(e.onPointerDown,z=>{z.button===0&&(z.target.setPointerCapture(z.pointerId),L.current=v.getBoundingClientRect(),C.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",b.viewport&&(b.viewport.style.scrollBehavior="auto"),G(z))}),onPointerMove:Ke(e.onPointerMove,G),onPointerUp:Ke(e.onPointerUp,z=>{const B=z.target;B.hasPointerCapture(z.pointerId)&&B.releasePointerCapture(z.pointerId),document.body.style.webkitUserSelect=C.current,b.viewport&&(b.viewport.style.scrollBehavior=""),L.current=null})})})},"ScrollAreaScrollbarImpl")),Yt="ScrollAreaThumb",da=s.forwardRef(O(function(e,r){const{forceMount:o,...i}=e,a=Zn(Yt,e.__scopeScrollArea);return n.jsx(Mt,{present:o||a.hasThumb,children:n.jsx(fa,{ref:r,...i})})},"ScrollAreaThumb")),fa=s.forwardRef(O(function(e,r){const{__scopeScrollArea:o,style:i,...a}=e,c=Le(Yt,o),u=Zn(Yt,o),{onThumbPositionChange:d}=u,h=tt(r,u.onThumbChange),p=s.useRef(void 0),g=Et(()=>{p.current&&(p.current(),p.current=void 0)},100);return s.useEffect(()=>{const x=c.viewport;if(x){const f=O(()=>{if(g(),!p.current){const b=ma(x,d);p.current=b,d()}},"handleScroll");return d(),x.addEventListener("scroll",f),()=>x.removeEventListener("scroll",f)}},[c.viewport,g,d]),n.jsx(nt.div,{"data-state":u.hasThumb?"visible":"hidden",...a,ref:h,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...i},onPointerDownCapture:Ke(e.onPointerDownCapture,x=>{const b=x.target.getBoundingClientRect(),v=x.clientX-b.left,T=x.clientY-b.top;u.onThumbPointerDown({x:v,y:T})}),onPointerUp:Ke(e.onPointerUp,u.onThumbPointerUp)})},"ScrollAreaThumbImpl")),tr="ScrollAreaCorner",ha=s.forwardRef(O(function(e,r){const o=Le(tr,e.__scopeScrollArea),i=!!(o.scrollbarX&&o.scrollbarY);return o.type!=="scroll"&&i?n.jsx(pa,{...e,ref:r}):null},"ScrollAreaCorner")),pa=s.forwardRef(O(function(e,r){const{__scopeScrollArea:o,...i}=e,a=Le(tr,o),[c,u]=s.useState(0),[d,h]=s.useState(0),p=!!(c&&d),{onCornerWidthChange:g,onCornerHeightChange:x}=a;return pt(a.scrollbarX,()=>{var b;const f=((b=a.scrollbarX)==null?void 0:b.offsetHeight)||0;a.onCornerHeightChange(f),h(f)}),pt(a.scrollbarY,()=>{var b;const f=((b=a.scrollbarY)==null?void 0:b.offsetWidth)||0;a.onCornerWidthChange(f),u(f)}),s.useEffect(()=>()=>{g(0),x(0)},[g,x]),p?n.jsx(nt.div,{...i,ref:r,style:{width:c,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}O(Ct,"toInt");function tn(t,e){const r=t/e;return isNaN(r)?0:r}O(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)}O(Tt,"getThumbSize");function nr(t,e,r,o="ltr"){const i=Tt(r),a=i/2,c=e||a,u=i-c,d=r.scrollbar.paddingStart+c,h=r.scrollbar.size-r.scrollbar.paddingEnd-u,p=r.content-r.viewport,g=o==="ltr"?[0,p]:[p*-1,0];return nn([d,h],g)(t)}O(nr,"getScrollPositionFromPointer");function Gt(t,e,r="ltr"){const o=Tt(e),i=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,a=e.scrollbar.size-i,c=e.content-e.viewport,u=a-o,d=r==="ltr"?[0,c]:[c*-1,0],h=Wr(t,d);return nn([0,c],[0,u])(h)}O(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])}}O(nn,"linearScale");function rn(t,e){return t>0&&t<e}O(rn,"isScrollingWithinScrollbarBounds");var ma=O((t,e=()=>{})=>{let r={left:t.scrollLeft,top:t.scrollTop},o=0;return O((function i(){const a={left:t.scrollLeft,top:t.scrollTop},c=r.left!==a.left,u=r.top!==a.top;(c||u)&&e(),r=a,o=window.requestAnimationFrame(i)}),"loop")(),()=>window.cancelAnimationFrame(o)},"addUnlinkedScrollListener");function Et(t,e){const r=ht(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])}O(Et,"useDebounceCallback");function pt(t,e){const r=ht(e);mr(()=>{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])}O(pt,"useResizeObserver");var rr=na,ga=sa,xa=ha;const sr=s.forwardRef(({className:t,children:e,...r},o)=>n.jsxs(rr,{ref:o,className:te("relative overflow-hidden",t),...r,children:[n.jsx(ga,{className:"h-full w-full rounded-[inherit]",children:e}),n.jsx(or,{}),n.jsx(xa,{})]}));sr.displayName=rr.displayName;const or=s.forwardRef(({className:t,orientation:e="vertical",...r},o)=>n.jsx(Jn,{ref:o,orientation:e,className:te("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(da,{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 ba(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 c;if(i===r)c="Today";else if(i===o)c="Yesterday";else{const u=new Date(i);c=u.toLocaleDateString(void 0,{month:"short",day:"numeric",...u.getFullYear()!==new Date().getFullYear()?{year:"numeric"}:{}})}return{label:c,items:a}})}function ya(t){return ar(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}const va=5*1024*1024,wa=["image/png","image/jpeg","image/webp"];function Sa({buildId:t}){const e=s.useId(),[r,o]=s.useState([]),[i,a]=s.useState(""),[c,u]=s.useState(null),[d,h]=s.useState(!1),[p,g]=s.useState(""),x=s.useRef(null),f=s.useRef({}),b=s.useCallback(()=>{fetch(`/api/v1/comments?build_id=${t}`,{credentials:"include"}).then(C=>C.ok?C.json():[]).then(o)},[t]);s.useEffect(()=>{b()},[b]),s.useEffect(()=>{const C=window.location.hash;if(!C.startsWith("#comment-"))return;const N=Number(C.replace("#comment-","")),E=f.current[N];if(!E)return;E.scrollIntoView({behavior:"smooth"});const M=document.documentElement.classList.contains("dark");E.style.backgroundColor=M?"rgb(0 112 243 / 0.18)":"#d3e5ff",setTimeout(()=>{E.style.backgroundColor=""},2e3)},[r]),s.useEffect(()=>{hn()},[]);async function v(C){const{linkBase:N}=await hn(),E=Yr(N,`${location.pathname}${location.search}#comment-${C}`);try{if(!navigator.clipboard)throw new Error("no clipboard");await navigator.clipboard.writeText(E),Ne.success("Link copied")}catch{Ne.error("Could not copy link")}}function T(C){if(g(""),!wa.includes(C.type)){g("Only png, jpg, webp allowed");return}if(C.size>va){g("Max 5MB");return}u(C)}async function j(C){if(C.preventDefault(),!i.trim()&&!c)return;h(!0);const N=new FormData;N.append("build_id",String(t)),N.append("body",i),c&&N.append("attachment",c),(await fetch("/api/v1/comments",{method:"POST",credentials:"include",body:N})).ok&&(a(""),u(null),b()),h(!1)}const L=ba(r);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:r.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:L.map(({label:C,items:N})=>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:C}),n.jsx("div",{className:"h-px flex-1 bg-border"})]}),n.jsx("div",{className:"flex flex-col gap-4",children:N.map(E=>n.jsxs("div",{id:`comment-${E.id}`,ref:M=>{f.current[E.id]=M},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(xr,{name:E.author,avatarUrl:E.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:E.author}),n.jsx("span",{className:"text-[11px] text-muted-foreground leading-none",children:ya(E.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:()=>void v(E.id),children:n.jsx(Ln,{className:"h-3 w-3","aria-hidden":"true"})})]}),n.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap mt-1",children:E.body}),E.attachments.map(M=>{const k=decodeURIComponent(M.file_path.split("/").pop()??"image");return n.jsx("a",{href:M.file_path,target:"_blank",rel:"noreferrer",className:"mt-1.5 block","aria-label":`Open ${k} in a new tab`,children:n.jsx("img",{src:M.file_path,alt:k,className:"max-h-48 rounded border object-contain"})},M.id)})]})]},E.id))})]},C))})})}),n.jsx("div",{className:"pb-1",children:n.jsx("form",{onSubmit:j,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:i,onChange:C=>a(C.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"}),(c||p)&&n.jsxs("div",{className:"px-3 -mt-1 pb-1",children:[c&&n.jsx("p",{className:"text-xs text-muted-foreground",children:c.name}),p&&n.jsx("p",{id:e,role:"alert",className:"text-xs text-destructive",children:p})]}),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","aria-describedby":p?e:void 0,onClick:()=>{var C;return(C=x.current)==null?void 0:C.click()},children:n.jsx(ls,{className:"h-4 w-4","aria-hidden":"true"})}),n.jsx("input",{ref:x,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:C=>{var E;const N=(E=C.target.files)==null?void 0:E[0];N&&T(N)}}),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:d||!i.trim()&&!c,children:n.jsx(es,{className:"h-3.5 w-3.5","aria-hidden":"true"})})]})]})})})]})}function Ra(t){return t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function ka(t){return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ja(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 Ca({buildId:t,refreshKey:e}){const[r,o]=s.useState([]),[i,a]=s.useState(!0),[c,u]=s.useState(!1);return s.useEffect(()=>{a(!0),u(!1);const d=setTimeout(()=>u(!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?c?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=ja(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:ka(d.createdAt)}),n.jsxs("span",{className:`text-xs ${h.urgent?"text-destructive":"text-muted-foreground"}`,children:[h.label," · ",Ra(d.fileSize)]})]}),n.jsx(ie,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 ml-2",title:"Download",onClick:()=>{const p=document.createElement("a");p.href=d.url,p.download="",p.click()},children:n.jsx(ss,{className:"h-3.5 w-3.5"})})]},d.id)})})}function Ta({buildId:t,recordingsRefreshKey:e=0}){return n.jsxs(Er,{defaultValue:"comments",className:"flex h-full flex-col",children:[n.jsx("div",{className:"shrink-0 px-1",children:n.jsxs(Nr,{className:"w-full",children:[n.jsxs(un,{value:"comments",className:"flex-1 gap-1.5",children:[n.jsx(ms,{className:"h-3.5 w-3.5"}),"Comments"]}),n.jsxs(un,{value:"recordings",className:"flex-1 gap-1.5",children:[n.jsx(as,{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(Sa,{buildId:t})}),n.jsx(dn,{value:"recordings",className:"mt-3 min-h-0 flex-1 overflow-y-auto",children:n.jsx(Ca,{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:te("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:te("inline-flex items-center gap-1.5",t),...e}));jt.displayName="BreadcrumbItem";const Pt=s.forwardRef(({asChild:t,className:e,...r},o)=>{const i=t?br:"a";return n.jsx(i,{ref:o,className:te("transition-colors hover:text-foreground cursor-pointer",e),...r})});Pt.displayName="BreadcrumbLink";const Dt=s.forwardRef(({className:t,...e},r)=>n.jsx("span",{ref:r,role:"link","aria-disabled":"true","aria-current":"page",className:te("font-medium text-foreground",t),...e}));Dt.displayName="BreadcrumbPage";const Lt=({children:t,className:e,...r})=>n.jsx("li",{role:"presentation","aria-hidden":"true",className:te("[&>svg]:h-3.5 [&>svg]:w-3.5",e),...r,children:t??n.jsx(yr,{})});Lt.displayName="BreadcrumbSeparator";var Ea=Object.defineProperty,et=(t,e)=>Ea(t,"name",{value:e,configurable:!0}),sn="Switch",[Na,Ya]=Cn(sn),[Aa,on]=Na(sn);function lr(t){const{__scopeSwitch:e,checked:r,children:o,defaultChecked:i,disabled:a,form:c,name:u,onCheckedChange:d,required:h,value:p="on",internal_do_not_use_render:g}=t,[x,f]=wr({prop:r,defaultProp:i??!1,onChange:d,caller:sn}),[b,v]=s.useState(null),[T,j]=s.useState(null),L=s.useRef(!1),[C,N]=s.useReducer(k=>k+1,0),E=b?!!c||!!b.closest("form"):!0,M={checked:x,setChecked:f,disabled:a,control:b,setControl:v,name:u,form:c,value:p,hasConsumerStoppedPropagationRef:L,userInteractionCount:C,onUserInteraction:N,required:h,defaultChecked:i,isFormControl:E,bubbleInput:T,setBubbleInput:j};return n.jsx(Aa,{scope:e,...M,children:dr(g)?g(M):o})}et(lr,"SwitchProvider");var _a="SwitchTrigger",Pa=s.forwardRef(et(function({__scopeSwitch:e,onClick:r,...o},i){const{control:a,form:c,value:u,disabled:d,checked:h,required:p,setControl:g,setChecked:x,hasConsumerStoppedPropagationRef:f,onUserInteraction:b,isFormControl:v,bubbleInput:T}=on(_a,e),j=tt(i,g),L=s.useRef(h);return s.useEffect(()=>{const C=c?a==null?void 0:a.ownerDocument.getElementById(c):a==null?void 0:a.form;if(C instanceof HTMLFormElement){const N=et(()=>x(L.current),"reset");return C.addEventListener("reset",N),()=>C.removeEventListener("reset",N)}},[a,c,x]),n.jsx(nt.button,{type:"button",role:"switch","aria-checked":h,"aria-required":p,"data-state":an(h),"data-disabled":d?"":void 0,disabled:d,value:u,...o,ref:j,onClick:Ke(r,C=>{b(),x(N=>!N),T&&v&&(f.current=C.isPropagationStopped(),f.current||C.stopPropagation())})})},"SwitchTrigger")),ur=s.forwardRef(et(function(e,r){const{__scopeSwitch:o,name:i,checked:a,defaultChecked:c,required:u,disabled:d,value:h,onCheckedChange:p,form:g,...x}=e;return n.jsx(lr,{__scopeSwitch:o,checked:a,defaultChecked:c,disabled:d,required:u,onCheckedChange:p,name:i,form:g,value:h,internal_do_not_use_render:({isFormControl:f})=>n.jsxs(n.Fragment,{children:[n.jsx(Pa,{...x,ref:r,__scopeSwitch:o}),f&&n.jsx(Ma,{__scopeSwitch:o})]})})},"Switch")),Da="SwitchThumb",La=s.forwardRef(et(function(e,r){const{__scopeSwitch:o,...i}=e,a=on(Da,o);return n.jsx(nt.span,{"data-state":an(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:r})},"SwitchThumb")),Ia="SwitchBubbleInput",Ma=s.forwardRef(et(function({__scopeSwitch:e,onClick:r,...o},i){const{control:a,hasConsumerStoppedPropagationRef:c,userInteractionCount:u,checked:d,defaultChecked:h,required:p,disabled:g,name:x,value:f,form:b,bubbleInput:v,setBubbleInput:T}=on(Ia,e),j=tt(i,T),L=vr(a),C=s.useRef(!1),N=s.useRef(d),E=s.useRef(u);s.useEffect(()=>{const k=v;if(!k)return;const F=window.HTMLInputElement.prototype,z=Object.getOwnPropertyDescriptor(F,"checked").set,B=u!==E.current;E.current=u;const Q=N.current!==d;N.current=d;const ue=!(B&&c.current);if(Q&&z){C.current=!B;const Ie=new Event("click",{bubbles:ue});z.call(k,d),k.dispatchEvent(Ie),C.current=!1}},[v,d,c,u]);const M=s.useRef(d);return n.jsx(nt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:h??M.current,required:p,disabled:g,name:x,value:f,form:b,...o,tabIndex:-1,ref:j,onClick:Ke(r,k=>{C.current&&k.stopPropagation()}),style:{...o.style,...L,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})},"SwitchBubbleInput"));function dr(t){return typeof t=="function"}et(dr,"isFunction");function an(t){return t?"checked":"unchecked"}et(an,"getState");const fr=s.forwardRef(({className:t,...e},r)=>n.jsx(ur,{className:te("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(La,{className:te("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 Ua={"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 Ga(){const[t]=Nn(),e=Pr(),r=t.get("id"),{build:o}=Is(r),[i,a]=s.useState(0),c=(o==null?void 0:o.platform)??"ios",{sessions:u,selectedAgent:d,setSelectedAgent:h,activeSessionId:p,deviceId:g,booting:x,status:f,connected:b,agentGroups:v,startDevice:T,resetDevice:j,handleBack:L,handleBackToMacs:C,handleSessionEnded:N}=Ms(c),E=v.find(U=>U.agentName===d),{osVersions:M,osVersion:k,setOsVersion:F,deviceSearch:G,setDeviceSearch:z,versionedDevices:B,resetMode:Q,setResetMode:ue,appliedResetMode:Ie,consumeResetMode:Be,fullResetSupported:be}=Us(E,c),Z=u.flatMap(U=>U.devices).find(U=>U.id===g),Ae=Z?`${Z.name}${Z.osVersion?` · ${Z.osVersion}`:""}`:"",Oe=s.useCallback(()=>a(U=>U+1),[]),He=s.useCallback(U=>{Be(),T(U)},[Be,T]),Me=s.useCallback(U=>{const q=Ua[U];Ne.error(q.title,{description:q.description}),N()},[N]),{setNode:Ue}=Sr();return s.useEffect(()=>{if(o)return Ue(n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(ir,{children:n.jsxs(cr,{children:[n.jsx(jt,{children:n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:()=>e(`/app-center?appId=${o.app_id}`),children:o.name})})}),n.jsx(Lt,{}),n.jsx(jt,{children:d?n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:C,children:ln(o)})}):n.jsx(Dt,{children:ln(o)})}),d&&n.jsxs(n.Fragment,{children:[n.jsx(Lt,{}),n.jsx(jt,{children:p?n.jsx(Pt,{asChild:!0,children:n.jsx("button",{onClick:L,children:d})}):n.jsx(Dt,{children:d})})]}),p&&n.jsxs(n.Fragment,{children:[n.jsx(Lt,{}),n.jsx(jt,{children:n.jsx(Dt,{children:Ae})})]})]})}),!d&&o.status_label&&n.jsx(Gr,{tone:Cr[o.status_label],children:o.status_label})]})),()=>Ue(null)},[o,d,p,Ae,e,L,C,Ue]),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:p?n.jsx("div",{className:"min-h-full flex items-center justify-center py-6 px-8 min-w-max",children:n.jsx(Zo,{sessionId:p,deviceId:g,buildId:o==null?void 0:o.id,resetMode:Ie,onRecordingUploaded:Oe,onSessionEnded:Me})}):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:C,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(Tr,{placeholder:"Search device…",value:G,onChange:z}),M.length>0&&n.jsxs(Vr,{value:k||"__all__",onValueChange:U=>{F(U==="__all__"?"":U),j()},children:[n.jsx(qr,{className:"h-8 w-36 shrink-0",children:n.jsx(Xr,{})}),n.jsxs(Kr,{children:[n.jsx(fn,{value:"__all__",children:"Any version"}),M.map(U=>n.jsx(fn,{value:U,children:U},U))]})]}),be&&n.jsx(Vt,{children:n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx(Rr,{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:Q==="full-erase",onCheckedChange:U=>ue(U?"full-erase":"app-only")})]})}),n.jsx(Ee,{children:Q==="full-erase"?"Erase all data on the next device you pick":"Keep existing data"})]})})]}),B.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:b?"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:B.map(U=>{const q=U.status==="booted",K=U.busy,Se=K?"In use":q?"Booted":"Available",J=K?"bg-amber-400":q?"bg-emerald-400":"bg-muted-foreground/40";return n.jsxs("button",{disabled:K||x||!b,onClick:()=>He(U),className:te("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:te("inline-block h-1.5 w-1.5 rounded-full",J)}),Se]})]},U.id)})}),f&&n.jsx("p",{className:"text-sm text-muted-foreground",children:f})]}):n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select Mac"}),v.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:b?`No agents available for ${c}.`:"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:v.map(U=>{const q=U.resources,K=q?Date.now()-q.reportedAt>Ar:!1,Se=U.devices.filter(We=>We.platform===c).length,J=(q==null?void 0:q.cpuPercent)??0,Re=q?q.memUsedMB/q.memTotalMB*100:0,de=_r(q,K),ee=de==="overloaded";return n.jsx(Vt,{children:n.jsxs(Ce,{children:[n.jsx(Te,{asChild:!0,children:n.jsx("span",{tabIndex:ee?0:void 0,className:ee?"cursor-not-allowed":void 0,children:n.jsxs("button",{disabled:ee,"aria-disabled":ee,onClick:()=>h(U.agentName??null),className:te("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px] w-full",ee?"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($a,{health:de}),n.jsx("span",{className:"text-sm font-medium leading-tight truncate",children:U.agentName??"Unknown"})]}),K&&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:[Se," device",Se!==1?"s":""]}),q&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:[q.slotsAvailable,"/",q.slotsTotal," slots"]})]})]}),q&&!K&&n.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[n.jsx(kn,{label:"CPU",percent:J,colorClass:"bg-blue-400"}),n.jsx(kn,{label:"RAM",percent:Re,colorClass:"bg-violet-400"})]})]})})}),ee&&n.jsx(Ee,{children:"This Mac is currently overloaded. Try again later."})]})},U.agentName)})})]})})}),r&&n.jsxs(n.Fragment,{children:[n.jsx(jn,{orientation:"vertical",className:"h-auto"}),n.jsx("div",{className:"w-80 shrink-0 h-full",children:n.jsx(Ta,{buildId:Number(r),recordingsRefreshKey:i})})]})]})}function $a({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:te("inline-block h-2 w-2 shrink-0 rounded-full",e)})}function kn({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:te("h-full rounded-full transition-all",r),style:{width:`${Math.min(100,e)}%`}})})]})}export{Ga as QASession};